Skip to content

Commit a51154a

Browse files
committed
Deduplicate Jexl configuration
1 parent d022c57 commit a51154a

File tree

3 files changed

+21
-34
lines changed

3 files changed

+21
-34
lines changed

java/ql/src/Security/CWE/CWE-094/JexlInjection.ql

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,9 @@
1212
*/
1313

1414
import java
15-
import semmle.code.java.dataflow.FlowSources
1615
import semmle.code.java.security.JexlInjectionQuery
1716
import DataFlow::PathGraph
1817

19-
/**
20-
* A taint-tracking configuration for unsafe user input
21-
* that is used to construct and evaluate a JEXL expression.
22-
* It supports both JEXL 2 and 3.
23-
*/
24-
class JexlInjectionConfig extends TaintTracking::Configuration {
25-
JexlInjectionConfig() { this = "JexlInjectionConfig" }
26-
27-
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
28-
29-
override predicate isSink(DataFlow::Node sink) { sink instanceof JexlEvaluationSink }
30-
31-
override predicate isAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
32-
any(JexlInjectionAdditionalTaintStep c).step(node1, node2)
33-
}
34-
}
35-
3618
from DataFlow::PathNode source, DataFlow::PathNode sink, JexlInjectionConfig conf
3719
where conf.hasFlowPath(source, sink)
3820
select sink.getNode(), source, sink, "JEXL injection from $@.", source.getNode(), "this user input"

java/ql/src/semmle/code/java/security/JexlInjectionQuery.qll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java
44
import semmle.code.java.dataflow.TaintTracking
5+
import semmle.code.java.dataflow.FlowSources
56
private import semmle.code.java.dataflow.ExternalFlow
67

78
/**
@@ -37,6 +38,23 @@ private class DefaultJexlInjectionAdditionalTaintStep extends JexlInjectionAddit
3738
}
3839
}
3940

41+
/**
42+
* A taint-tracking configuration for unsafe user input
43+
* that is used to construct and evaluate a JEXL expression.
44+
* It supports both JEXL 2 and 3.
45+
*/
46+
class JexlInjectionConfig extends TaintTracking::Configuration {
47+
JexlInjectionConfig() { this = "JexlInjectionConfig" }
48+
49+
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
50+
51+
override predicate isSink(DataFlow::Node sink) { sink instanceof JexlEvaluationSink }
52+
53+
override predicate isAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
54+
any(JexlInjectionAdditionalTaintStep c).step(node1, node2)
55+
}
56+
}
57+
4058
/**
4159
* Holds if `n1` to `n2` is a dataflow step that creates a JEXL script using an unsafe engine
4260
* by calling `tainted.createScript(jexlExpr)`.

java/ql/test/query-tests/security/CWE-094/JexlInjectionTest.ql

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,17 @@
11
import java
2-
import semmle.code.java.dataflow.DataFlow
3-
import semmle.code.java.dataflow.FlowSteps
4-
import semmle.code.java.dataflow.FlowSources
52
import semmle.code.java.security.JexlInjectionQuery
63
import TestUtilities.InlineExpectationsTest
74

8-
class Conf extends TaintTracking::Configuration {
9-
Conf() { this = "qltest:cwe:jexl-injection" }
10-
11-
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
12-
13-
override predicate isSink(DataFlow::Node sink) { sink instanceof JexlEvaluationSink }
14-
15-
override predicate isAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
16-
any(JexlInjectionAdditionalTaintStep c).step(node1, node2)
17-
}
18-
}
19-
205
class JexlInjectionTest extends InlineExpectationsTest {
216
JexlInjectionTest() { this = "HasJexlInjectionTest" }
227

238
override string getARelevantTag() { result = "hasJexlInjection" }
249

2510
override predicate hasActualResult(Location location, string element, string tag, string value) {
2611
tag = "hasJexlInjection" and
27-
exists(DataFlow::Node src, DataFlow::Node sink, Conf conf | conf.hasFlow(src, sink) |
12+
exists(DataFlow::Node src, DataFlow::Node sink, JexlInjectionConfig conf |
13+
conf.hasFlow(src, sink)
14+
|
2815
sink.getLocation() = location and
2916
element = sink.toString() and
3017
value = ""

0 commit comments

Comments
 (0)