Skip to content

Commit 13148b4

Browse files
committed
Python: Handle taint of f-strings
1 parent 2f090df commit 13148b4

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

change-notes/1.25/analysis-python.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ The following changes in version 1.25 affect Python analysis in all applications
2020
## Changes to libraries
2121

2222
* Importing `semmle.python.web.HttpRequest` will no longer import `UntrustedStringKind` transitively. `UntrustedStringKind` is the most commonly used non-abstract subclass of `ExternalStringKind`. If not imported (by one mean or another), taint-tracking queries that concern `ExternalStringKind` will not produce any results. Please ensure such queries contain an explicit import (`import semmle.python.security.strings.Untrusted`).
23+
* Added support for tainted f-strings.

python/ql/src/semmle/python/security/strings/Basic.qll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ abstract class StringKind extends TaintKind {
2727
os_path_join(fromnode, tonode) or
2828
str_format(fromnode, tonode) or
2929
encode_decode(fromnode, tonode) or
30-
to_str(fromnode, tonode)
30+
to_str(fromnode, tonode) or
31+
f_string(fromnode, tonode)
3132
)
3233
or
3334
result = this and copy_call(fromnode, tonode)
@@ -107,6 +108,11 @@ private predicate os_path_join(ControlFlowNode fromnode, CallNode tonode) {
107108
tonode.getAnArg() = fromnode
108109
}
109110

111+
/** tonode = f"... {fromnode} ..." */
112+
private predicate f_string(ControlFlowNode fromnode, ControlFlowNode tonode) {
113+
tonode.getNode().(Fstring).getAValue() = fromnode.getNode()
114+
}
115+
110116
/**
111117
* A kind of "taint", representing a dictionary mapping str->"taint"
112118
*
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| test.py:4 | fail | fstring | Fstring | <NO TAINT> |
1+
| test.py:4 | ok | fstring | Fstring | externally controlled string |

0 commit comments

Comments
 (0)