Skip to content

Commit f6b8d89

Browse files
committed
Refactor GroovyInjectionQuery
1 parent bf5f82b commit f6b8d89

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

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

Lines changed: 23 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.GroovyInjection
77

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

1517
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
@@ -20,3 +22,23 @@ class GroovyInjectionConfig extends TaintTracking::Configuration {
2022
any(GroovyInjectionAdditionalTaintStep c).step(fromNode, toNode)
2123
}
2224
}
25+
26+
/**
27+
* A taint-tracking configuration for unsafe user input
28+
* that is used to evaluate a Groovy expression.
29+
*/
30+
module GroovyInjectionConfig implements DataFlow::ConfigSig {
31+
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
32+
33+
predicate isSink(DataFlow::Node sink) { sink instanceof GroovyInjectionSink }
34+
35+
predicate isAdditionalFlowStep(DataFlow::Node fromNode, DataFlow::Node toNode) {
36+
any(GroovyInjectionAdditionalTaintStep c).step(fromNode, toNode)
37+
}
38+
}
39+
40+
/**
41+
* Detect taint flow of unsafe user input
42+
* that is used to evaluate a Groovy expression.
43+
*/
44+
module GroovyInjectionFlow = TaintTracking::Make<GroovyInjectionConfig>;

java/ql/src/Security/CWE/CWE-094/GroovyInjection.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.GroovyInjectionQuery
16-
import DataFlow::PathGraph
16+
import GroovyInjectionFlow::PathGraph
1717

18-
from DataFlow::PathNode source, DataFlow::PathNode sink, GroovyInjectionConfig conf
19-
where conf.hasFlowPath(source, sink)
18+
from GroovyInjectionFlow::PathNode source, GroovyInjectionFlow::PathNode sink
19+
where GroovyInjectionFlow::hasFlowPath(source, sink)
2020
select sink.getNode(), source, sink, "Groovy script depends on a $@.", source.getNode(),
2121
"user-provided value"

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

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

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

0 commit comments

Comments
 (0)