Skip to content

Commit 7ee6c06

Browse files
committed
Refactor RegexInjectionQuery
1 parent c44254e commit 7ee6c06

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

java/ql/lib/semmle/code/java/security/regexp/RegexInjectionQuery.qll

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ import semmle.code.java.dataflow.FlowSources
55
import semmle.code.java.dataflow.TaintTracking
66
import semmle.code.java.security.regexp.RegexInjection
77

8-
/** A taint-tracking configuration for untrusted user input used to construct regular expressions. */
9-
class RegexInjectionConfiguration extends TaintTracking::Configuration {
8+
/**
9+
* DEPRECATED: Use `RegexInjectionFlow` instead.
10+
*
11+
* A taint-tracking configuration for untrusted user input used to construct regular expressions.
12+
*/
13+
deprecated class RegexInjectionConfiguration extends TaintTracking::Configuration {
1014
RegexInjectionConfiguration() { this = "RegexInjection" }
1115

1216
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
@@ -15,3 +19,16 @@ class RegexInjectionConfiguration extends TaintTracking::Configuration {
1519

1620
override predicate isSanitizer(DataFlow::Node node) { node instanceof RegexInjectionSanitizer }
1721
}
22+
23+
/**
24+
* A taint-tracking configuration for untrusted user input used to construct regular expressions.
25+
*/
26+
private module RegexInjectionConfig implements DataFlow::ConfigSig {
27+
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
28+
29+
predicate isSink(DataFlow::Node sink) { sink instanceof RegexInjectionSink }
30+
31+
predicate isBarrier(DataFlow::Node node) { node instanceof RegexInjectionSanitizer }
32+
}
33+
34+
module RegexInjectionFlow = TaintTracking::Make<RegexInjectionConfig>;

java/ql/src/Security/CWE/CWE-730/RegexInjection.ql

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

1616
import java
1717
import semmle.code.java.security.regexp.RegexInjectionQuery
18-
import DataFlow::PathGraph
18+
import RegexInjectionFlow::PathGraph
1919

20-
from DataFlow::PathNode source, DataFlow::PathNode sink, RegexInjectionConfiguration c
21-
where c.hasFlowPath(source, sink)
20+
from RegexInjectionFlow::PathNode source, RegexInjectionFlow::PathNode sink
21+
where RegexInjectionFlow::hasFlowPath(source, sink)
2222
select sink.getNode(), source, sink, "This regular expression is constructed from a $@.",
2323
source.getNode(), "user-provided value"

java/ql/test/query-tests/security/CWE-730/RegexInjectionTest.ql

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

1010
override predicate hasActualResult(Location location, string element, string tag, string value) {
1111
tag = "hasRegexInjection" and
12-
exists(DataFlow::PathNode sink, RegexInjectionConfiguration c | c.hasFlowPath(_, sink) |
12+
exists(RegexInjectionFlow::PathNode sink | RegexInjectionFlow::hasFlowPath(_, sink) |
1313
location = sink.getNode().getLocation() and
1414
element = sink.getNode().toString() and
1515
value = ""

0 commit comments

Comments
 (0)