Skip to content

Commit 31faf91

Browse files
committed
Python: recover taint for % format strings
1 parent 060d0b4 commit 31faf91

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowPrivate.qll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,10 +1012,21 @@ module Conversions {
10121012
)
10131013
}
10141014

1015+
predicate formatReadStep(Node nodeFrom, ContentSet c, Node nodeTo) {
1016+
// % formatting
1017+
exists(BinaryExprNode fmt | fmt = nodeTo.asCfgNode() |
1018+
fmt.getOp() instanceof Mod and
1019+
fmt.getRight() = nodeFrom.asCfgNode()
1020+
) and
1021+
c instanceof TupleElementContent
1022+
}
1023+
10151024
predicate readStep(Node nodeFrom, ContentSet c, Node nodeTo) {
10161025
decoderReadStep(nodeFrom, c, nodeTo)
10171026
or
10181027
encoderReadStep(nodeFrom, c, nodeTo)
1028+
or
1029+
formatReadStep(nodeFrom, c, nodeTo)
10191030
}
10201031
}
10211032

python/ql/test/library-tests/dataflow/tainttracking/defaultAdditionalTaintStep/test_string.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def percent_fmt():
115115
ensure_tainted(
116116
tainted_fmt % (1, 2), # $ tainted
117117
"%s foo bar" % ts, # $ tainted
118-
"%s %s %s" % (1, 2, ts), # $ MISSING: tainted
118+
"%s %s %s" % (1, 2, ts), # $ tainted
119119
)
120120

121121

0 commit comments

Comments
 (0)