Skip to content

Commit e5ca924

Browse files
Allow quantifiers invoving {}; add comments
1 parent bc17d4b commit e5ca924

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ private import RegexFlowModels
1010
private import semmle.code.java.security.SecurityTests
1111

1212
private class ExploitableStringLiteral extends StringLiteral {
13-
ExploitableStringLiteral() { this.getValue().matches(["%+%", "%*%"]) }
13+
ExploitableStringLiteral() { this.getValue().matches(["%+%", "%*%", "%{%}%"]) }
1414
}
1515

1616
private class RegexCompileFlowConf extends DataFlow2::Configuration {
@@ -32,6 +32,9 @@ private class RegexCompileFlowConf extends DataFlow2::Configuration {
3232
/**
3333
* Holds if `s` is used as a regex, with the mode `mode` (if known).
3434
* If regex mode is not known, `mode` will be `"None"`.
35+
*
36+
* As an optimisation, only regexes containing an infinite repitition quatifier (`+`, `*`, or `{x,}`)
37+
* and therefore may be relevant for ReDoS queries are considered.
3538
*/
3639
predicate usedAsRegex(StringLiteral s, string mode, boolean match_full_string) {
3740
exists(DataFlow::Node sink |
@@ -224,6 +227,9 @@ private class RegexMatchFlowConf extends DataFlow2::Configuration {
224227

225228
/**
226229
* Holds if the string literal `regex` is a regular expression that is matched against the expression `str`.
230+
*
231+
* As an optimisation, only regexes containing an infinite repitition quatifier (`+`, `*`, or `{x,}`)
232+
* and therefore may be relevant for ReDoS queries are considered.
227233
*/
228234
predicate regexMatchedAgainst(StringLiteral regex, Expr str) {
229235
exists(

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,12 @@ class RegExpParent extends TRegExpParent {
7171
abstract Regex getRegex();
7272
}
7373

74-
/** A string literal used as a regular expression */
74+
/**
75+
* A string literal used as a regular expression.
76+
*
77+
* As an optimisation, only regexes containing an infinite repitition quatifier (`+`, `*`, or `{x,}`)
78+
* and therefore may be relevant for ReDoS queries are considered.
79+
*/
7580
class RegExpLiteral extends TRegExpLiteral, RegExpParent {
7681
Regex re;
7782

0 commit comments

Comments
 (0)