Skip to content

Commit 66f971e

Browse files
committed
Refactor query tests
1 parent 93bd2a9 commit 66f971e

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

java/ql/test/query-tests/security/CWE-079/semmle/tests/XSS.ql

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
import java
2+
import semmle.code.java.dataflow.TaintTracking
23
import semmle.code.java.dataflow.FlowSources
34
import semmle.code.java.security.XSS
45
import TestUtilities.InlineExpectationsTest
56

6-
class XssConfig extends TaintTracking::Configuration {
7-
XssConfig() { this = "XSSConfig" }
7+
module XssConfig implements DataFlow::ConfigSig {
8+
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
89

9-
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
10+
predicate isSink(DataFlow::Node sink) { sink instanceof XssSink }
1011

11-
override predicate isSink(DataFlow::Node sink) { sink instanceof XssSink }
12+
predicate isBarrier(DataFlow::Node node) { node instanceof XssSanitizer }
1213

13-
override predicate isSanitizer(DataFlow::Node node) { node instanceof XssSanitizer }
14-
15-
override predicate isAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
14+
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
1615
any(XssAdditionalTaintStep s).step(node1, node2)
1716
}
1817
}
1918

19+
module XssFlow = TaintTracking::Global<XssConfig>;
20+
2021
class XssTest extends InlineExpectationsTest {
2122
XssTest() { this = "XssTest" }
2223

2324
override string getARelevantTag() { result = "xss" }
2425

2526
override predicate hasActualResult(Location location, string element, string tag, string value) {
2627
tag = "xss" and
27-
exists(DataFlow::Node sink, XssConfig conf | conf.hasFlowTo(sink) |
28+
exists(DataFlow::Node sink | XssFlow::flowTo(sink) |
2829
sink.getLocation() = location and
2930
element = sink.toString() and
3031
value = ""

java/ql/test/query-tests/security/CWE-089/semmle/examples/springjdbc.ql

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,34 @@ import semmle.code.java.dataflow.TaintTracking
33
import semmle.code.java.security.QueryInjection
44
import TestUtilities.InlineExpectationsTest
55

6-
private class QueryInjectionFlowConfig extends TaintTracking::Configuration {
7-
QueryInjectionFlowConfig() { this = "SqlInjectionLib::QueryInjectionFlowConfig" }
8-
9-
override predicate isSource(DataFlow::Node src) {
6+
private module QueryInjectionFlowConfig implements DataFlow::ConfigSig {
7+
predicate isSource(DataFlow::Node src) {
108
src.asExpr() = any(MethodAccess ma | ma.getMethod().hasName("source"))
119
}
1210

13-
override predicate isSink(DataFlow::Node sink) { sink instanceof QueryInjectionSink }
11+
predicate isSink(DataFlow::Node sink) { sink instanceof QueryInjectionSink }
1412

15-
override predicate isSanitizer(DataFlow::Node node) {
13+
predicate isBarrier(DataFlow::Node node) {
1614
node.getType() instanceof PrimitiveType or
1715
node.getType() instanceof BoxedType or
1816
node.getType() instanceof NumberType
1917
}
2018

21-
override predicate isAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
19+
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
2220
any(AdditionalQueryInjectionTaintStep s).step(node1, node2)
2321
}
2422
}
2523

24+
private module QueryInjectionFlow = TaintTracking::Global<QueryInjectionFlowConfig>;
25+
2626
class HasFlowTest extends InlineExpectationsTest {
2727
HasFlowTest() { this = "HasFlowTest" }
2828

2929
override string getARelevantTag() { result = "sqlInjection" }
3030

3131
override predicate hasActualResult(Location location, string element, string tag, string value) {
3232
tag = "sqlInjection" and
33-
exists(DataFlow::Node sink, QueryInjectionFlowConfig conf | conf.hasFlowTo(sink) |
33+
exists(DataFlow::Node sink | QueryInjectionFlow::flowTo(sink) |
3434
sink.getLocation() = location and
3535
element = sink.toString() and
3636
value = ""

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ import semmle.code.java.dataflow.FlowSources
44
import semmle.code.java.security.XPath
55
import TestUtilities.InlineExpectationsTest
66

7-
class Conf extends TaintTracking::Configuration {
8-
Conf() { this = "test:xml:xpathinjection" }
7+
module Config implements DataFlow::ConfigSig {
8+
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
99

10-
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
11-
12-
override predicate isSink(DataFlow::Node sink) { sink instanceof XPathInjectionSink }
10+
predicate isSink(DataFlow::Node sink) { sink instanceof XPathInjectionSink }
1311
}
1412

13+
module Flow = TaintTracking::Global<Config>;
14+
1515
class HasXPathInjectionTest extends InlineExpectationsTest {
1616
HasXPathInjectionTest() { this = "HasXPathInjectionTest" }
1717

1818
override string getARelevantTag() { result = "hasXPathInjection" }
1919

2020
override predicate hasActualResult(Location location, string element, string tag, string value) {
2121
tag = "hasXPathInjection" and
22-
exists(DataFlow::Node sink, Conf conf | conf.hasFlowTo(sink) |
22+
exists(DataFlow::Node sink | Flow::flowTo(sink) |
2323
sink.getLocation() = location and
2424
element = sink.toString() and
2525
value = ""

0 commit comments

Comments
 (0)