Skip to content

Commit 7e1c424

Browse files
committed
Refactor OgnlInjection
1 parent 3116e30 commit 7e1c424

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

java/ql/lib/semmle/code/java/security/OgnlInjectionQuery.qll

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import semmle.code.java.dataflow.FlowSources
55
import semmle.code.java.security.OgnlInjection
66

77
/**
8+
* DEPRECATED: Use `OgnlInjectionFlow` instead.
9+
*
810
* A taint-tracking configuration for unvalidated user input that is used in OGNL EL evaluation.
911
*/
10-
class OgnlInjectionFlowConfig extends TaintTracking::Configuration {
12+
deprecated class OgnlInjectionFlowConfig extends TaintTracking::Configuration {
1113
OgnlInjectionFlowConfig() { this = "OgnlInjectionFlowConfig" }
1214

1315
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
@@ -22,3 +24,23 @@ class OgnlInjectionFlowConfig extends TaintTracking::Configuration {
2224
any(OgnlInjectionAdditionalTaintStep c).step(node1, node2)
2325
}
2426
}
27+
28+
/**
29+
* A taint-tracking configuration for unvalidated user input that is used in OGNL EL evaluation.
30+
*/
31+
private module OgnlInjectionFlowConfig implements DataFlow::ConfigSig {
32+
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
33+
34+
predicate isSink(DataFlow::Node sink) { sink instanceof OgnlInjectionSink }
35+
36+
predicate isBarrier(DataFlow::Node node) {
37+
node.getType() instanceof PrimitiveType or node.getType() instanceof BoxedType
38+
}
39+
40+
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
41+
any(OgnlInjectionAdditionalTaintStep c).step(node1, node2)
42+
}
43+
}
44+
45+
/** Tracks flow of unvalidated user input that is used in OGNL EL evaluation. */
46+
module OgnlInjectionFlow = TaintTracking::Make<OgnlInjectionFlowConfig>;

java/ql/src/Security/CWE/CWE-917/OgnlInjection.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
import java
1515
import semmle.code.java.security.OgnlInjectionQuery
16-
import DataFlow::PathGraph
16+
import OgnlInjectionFlow::PathGraph
1717

18-
from DataFlow::PathNode source, DataFlow::PathNode sink, OgnlInjectionFlowConfig conf
19-
where conf.hasFlowPath(source, sink)
18+
from OgnlInjectionFlow::PathNode source, OgnlInjectionFlow::PathNode sink
19+
where OgnlInjectionFlow::hasFlowPath(source, sink)
2020
select sink.getNode(), source, sink, "OGNL Expression Language statement depends on a $@.",
2121
source.getNode(), "user-provided value"

java/ql/test/query-tests/security/CWE-917/OgnlInjectionTest.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class OgnlInjectionTest extends InlineExpectationsTest {
99

1010
override predicate hasActualResult(Location location, string element, string tag, string value) {
1111
tag = "hasOgnlInjection" and
12-
exists(DataFlow::Node sink, OgnlInjectionFlowConfig conf | conf.hasFlowTo(sink) |
12+
exists(DataFlow::Node sink | OgnlInjectionFlow::hasFlowTo(sink) |
1313
sink.getLocation() = location and
1414
element = sink.toString() and
1515
value = ""

0 commit comments

Comments
 (0)