Skip to content

Commit 0d13864

Browse files
smowtonjoefarebrother
authored andcommitted
Restrict polynomial ReDoS' strings-parsed-as-regexes search to those that could possibly be interesting
In practice for polynomial ReDoS this means those regexes containing at least one potentially-infinite quantifier (* or +).
1 parent 0f606d9 commit 0d13864

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

java/ql/lib/semmle/code/java/regex/RegexFlowConfigs.qll

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ private import semmle.code.java.dataflow.DataFlow3
99
private import RegexFlowModels
1010
private import semmle.code.java.security.SecurityTests
1111

12+
private class ExploitableStringLiteral extends StringLiteral {
13+
ExploitableStringLiteral() { this.getValue().matches(["%+%", "%*%"]) }
14+
}
15+
1216
private class RegexCompileFlowConf extends DataFlow2::Configuration {
1317
RegexCompileFlowConf() { this = "RegexCompileFlowConfig" }
1418

15-
override predicate isSource(DataFlow::Node node) { node.asExpr() instanceof StringLiteral }
19+
override predicate isSource(DataFlow::Node node) {
20+
node.asExpr() instanceof ExploitableStringLiteral
21+
}
1622

1723
override predicate isSink(DataFlow::Node node) {
1824
sinkNode(node, ["regex-compile", "regex-compile-match", "regex-compile-find"])
@@ -203,7 +209,9 @@ private class GuavaRegexFlowStep extends RegexAdditionalFlowStep {
203209
private class RegexMatchFlowConf extends DataFlow2::Configuration {
204210
RegexMatchFlowConf() { this = "RegexMatchFlowConf" }
205211

206-
override predicate isSource(DataFlow::Node src) { src.asExpr() instanceof StringLiteral }
212+
override predicate isSource(DataFlow::Node src) {
213+
src.asExpr() instanceof ExploitableStringLiteral
214+
}
207215

208216
override predicate isSink(DataFlow::Node sink) {
209217
exists(RegexMatchMethodAccess ma | sink.asExpr() = ma.getRegexArg())

0 commit comments

Comments
 (0)