Skip to content

Commit c2b6a3f

Browse files
committed
Add XPathInjectionQuery
1 parent c15ce27 commit c2b6a3f

File tree

4 files changed

+23
-24
lines changed

4 files changed

+23
-24
lines changed

java/ql/lib/change-notes/2023-03-30-add-libraries-for-query-configurations.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
category: minorAnalysis
33
---
44
* Added the `TaintedPermissionQuery.qll` library to provide the `TaintedPermissionFlow` taint-tracking module to reason about tainted permission vulnerabilities.
5+
* Added the `XPathInjectionQuery.qll` library to provide the `XPathInjectionFlow` taint-tracking module to reason about XPath injection vulnerabilities.
56
* Added the `SqlConcatenatedQuery.qll` library to provide the `UncontrolledStringBuilderSourceFlow` taint-tracking module to reason about SQL injection vulnerabilities caused by concatenating untrusted strings.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/** Provides taint-tracking flow to reason about XPath injection queries. */
2+
3+
import semmle.code.java.dataflow.FlowSources
4+
import semmle.code.java.dataflow.TaintTracking
5+
import semmle.code.java.security.XPath
6+
7+
/**
8+
* A taint-tracking configuration for reasoning about XPath injection vulnerabilities.
9+
*/
10+
module XPathInjectionConfig implements DataFlow::ConfigSig {
11+
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
12+
13+
predicate isSink(DataFlow::Node sink) { sink instanceof XPathInjectionSink }
14+
}
15+
16+
/**
17+
* Taint-tracking flow for XPath injection vulnerabilities.
18+
*/
19+
module XPathInjectionFlow = TaintTracking::Global<XPathInjectionConfig>;

java/ql/src/Security/CWE/CWE-643/XPathInjection.ql

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,7 @@
1212
*/
1313

1414
import java
15-
import semmle.code.java.dataflow.FlowSources
16-
import semmle.code.java.dataflow.TaintTracking
17-
import semmle.code.java.security.XPath
18-
19-
module XPathInjectionConfig implements DataFlow::ConfigSig {
20-
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
21-
22-
predicate isSink(DataFlow::Node sink) { sink instanceof XPathInjectionSink }
23-
}
24-
25-
module XPathInjectionFlow = TaintTracking::Global<XPathInjectionConfig>;
26-
15+
import semmle.code.java.security.XPathInjectionQuery
2716
import XPathInjectionFlow::PathGraph
2817

2918
from XPathInjectionFlow::PathNode source, XPathInjectionFlow::PathNode sink

java/ql/test/query-tests/security/CWE-643/XPathInjectionTest.ql

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11
import java
2-
import semmle.code.java.dataflow.TaintTracking
3-
import semmle.code.java.dataflow.FlowSources
4-
import semmle.code.java.security.XPath
2+
import semmle.code.java.security.XPathInjectionQuery
53
import TestUtilities.InlineExpectationsTest
64

7-
module Config implements DataFlow::ConfigSig {
8-
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
9-
10-
predicate isSink(DataFlow::Node sink) { sink instanceof XPathInjectionSink }
11-
}
12-
13-
module Flow = TaintTracking::Global<Config>;
14-
155
class HasXPathInjectionTest extends InlineExpectationsTest {
166
HasXPathInjectionTest() { this = "HasXPathInjectionTest" }
177

188
override string getARelevantTag() { result = "hasXPathInjection" }
199

2010
override predicate hasActualResult(Location location, string element, string tag, string value) {
2111
tag = "hasXPathInjection" and
22-
exists(DataFlow::Node sink | Flow::flowTo(sink) |
12+
exists(DataFlow::Node sink | XPathInjectionFlow::flowTo(sink) |
2313
sink.getLocation() = location and
2414
element = sink.toString() and
2515
value = ""

0 commit comments

Comments
 (0)