Skip to content

Commit af91a2d

Browse files
authored
Python: Prevent explosion in poly-ReDoS query
I consider this to be a short-term solution to the performance problems we identified. The choice of "at most ten occurrences of `.*`" is somewhat arbitrary, and it's possible a higher limit would work just as well.
1 parent 92804a3 commit af91a2d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

python/ql/src/semmle/python/security/performance/RegExpTreeView.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ import semmle.python.RegexTreeView
1111
* For javascript we make the pragmatic performance optimization to ignore files we did not extract.
1212
*/
1313
predicate isExcluded(RegExpParent parent) {
14-
not exists(parent.getRegex().getLocation().getFile().getRelativePath())
14+
not exists(parent.getRegex().getLocation().getFile().getRelativePath()) or
15+
// Regexes with many occurrences of ".*" may cause the polynomial ReDoS computation to explode, so
16+
// we explicitly exclude these.
17+
count(int i | exists(parent.getRegex().getText().regexpFind("\\.\\*", i, _)) | i) > 10
1518
}

0 commit comments

Comments
 (0)