Skip to content

Commit 44637e2

Browse files
authored
Merge pull request github#3716 from RasmusWL/python-fix-re-escape-fp
Python: Fix FP in treating re.escape as regex
2 parents 03c6d7a + c0043eb commit 44637e2

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

python/ql/src/semmle/python/regex.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ predicate used_as_regex(Expr s, string mode) {
2828
/* Call to re.xxx(regex, ... [mode]) */
2929
exists(CallNode call, string name |
3030
call.getArg(0).refersTo(_, _, s.getAFlowNode()) and
31-
call.getFunction().pointsTo(Module::named("re").attr(name))
31+
call.getFunction().pointsTo(Module::named("re").attr(name)) and
32+
not name = "escape"
3233
|
3334
mode = "None"
3435
or

python/ql/test/library-tests/regex/test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,7 @@
6262
re.compile(r"\[(?P<txt>[^[]*)\]\((?P<uri>[^)]*)")
6363

6464
re.compile("", re.M) # ODASA-8056
65+
66+
# FP reported in https://github.com/github/codeql/issues/3712
67+
# This does not define a regex (but could be used by other code to do so)
68+
escaped = re.escape("https://www.humblebundle.com/home/library")

python/ql/test/query-tests/Security/CWE-020/hosttest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ def safe(request):
1717
target = request.args.get('target', '')
1818
if SAFE_REGEX.match(target):
1919
return redirect(target)
20+
21+
# FP reported in https://github.com/github/codeql/issues/3712
22+
# This does not define a regex (but could be used by other code to do so)
23+
escaped = re.escape("https://www.humblebundle.com/home/library")

0 commit comments

Comments
 (0)