Skip to content

Commit 3116e30

Browse files
committed
Refactor MvelInjection
1 parent 423ab1d commit 3116e30

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import semmle.code.java.dataflow.TaintTracking
66
import semmle.code.java.security.MvelInjection
77

88
/**
9+
* DEPRECATED: Use `MvelInjectionFlow` instead.
10+
*
911
* A taint-tracking configuration for unsafe user input
1012
* that is used to construct and evaluate a MVEL expression.
1113
*/
12-
class MvelInjectionFlowConfig extends TaintTracking::Configuration {
14+
deprecated class MvelInjectionFlowConfig extends TaintTracking::Configuration {
1315
MvelInjectionFlowConfig() { this = "MvelInjectionFlowConfig" }
1416

1517
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
@@ -24,3 +26,22 @@ class MvelInjectionFlowConfig extends TaintTracking::Configuration {
2426
any(MvelInjectionAdditionalTaintStep c).step(node1, node2)
2527
}
2628
}
29+
30+
/**
31+
* A taint-tracking configuration for unsafe user input
32+
* that is used to construct and evaluate a MVEL expression.
33+
*/
34+
private module MvelInjectionFlowConfig implements DataFlow::ConfigSig {
35+
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
36+
37+
predicate isSink(DataFlow::Node sink) { sink instanceof MvelEvaluationSink }
38+
39+
predicate isBarrier(DataFlow::Node sanitizer) { sanitizer instanceof MvelInjectionSanitizer }
40+
41+
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
42+
any(MvelInjectionAdditionalTaintStep c).step(node1, node2)
43+
}
44+
}
45+
46+
/** Tracks flow of unsafe user input that is used to construct and evaluate a MVEL expression. */
47+
module MvelInjectionFlow = TaintTracking::Make<MvelInjectionFlowConfig>;

java/ql/src/Security/CWE/CWE-094/MvelInjection.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.MvelInjectionQuery
16-
import DataFlow::PathGraph
16+
import MvelInjectionFlow::PathGraph
1717

18-
from DataFlow::PathNode source, DataFlow::PathNode sink, MvelInjectionFlowConfig conf
19-
where conf.hasFlowPath(source, sink)
18+
from MvelInjectionFlow::PathNode source, MvelInjectionFlow::PathNode sink
19+
where MvelInjectionFlow::hasFlowPath(source, sink)
2020
select sink.getNode(), source, sink, "MVEL expression depends on a $@.", source.getNode(),
2121
"user-provided value"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class HasMvelInjectionTest extends InlineExpectationsTest {
1111

1212
override predicate hasActualResult(Location location, string element, string tag, string value) {
1313
tag = "hasMvelInjection" and
14-
exists(DataFlow::Node sink, MvelInjectionFlowConfig conf | conf.hasFlowTo(sink) |
14+
exists(DataFlow::Node sink | MvelInjectionFlow::hasFlowTo(sink) |
1515
sink.getLocation() = location and
1616
element = sink.toString() and
1717
value = ""

0 commit comments

Comments
 (0)