Skip to content

Commit b276b2d

Browse files
committed
Python: Clean up taint steps for attributes
1 parent 59160ee commit b276b2d

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,25 @@ predicate stringManipulation(DataFlow::CfgNode nodeFrom, DataFlow::CfgNode nodeT
167167
*/
168168
predicate containerStep(DataFlow::CfgNode nodeFrom, DataFlow::Node nodeTo) {
169169
// construction by literal
170-
// TODO: Not limiting the content argument here feels like a BIG hack, but we currently get nothing for free :|
171-
DataFlowPrivate::storeStep(nodeFrom, _, nodeTo)
170+
//
171+
// TODO: once we have proper flow-summary modeling, we might not need this step any
172+
// longer -- but there needs to be a matching read-step for the store-step, and we
173+
// don't provide that right now.
174+
DataFlowPrivate::listStoreStep(nodeFrom, _, nodeTo)
175+
or
176+
DataFlowPrivate::setStoreStep(nodeFrom, _, nodeTo)
177+
or
178+
DataFlowPrivate::tupleStoreStep(nodeFrom, _, nodeTo)
179+
or
180+
DataFlowPrivate::dictStoreStep(nodeFrom, _, nodeTo)
181+
or
182+
// comprehension, so there is taint-flow from `x` in `[x for x in xs]` to the
183+
// resulting list of the list-comprehension.
184+
//
185+
// TODO: once we have proper flow-summary modeling, we might not need this step any
186+
// longer -- but there needs to be a matching read-step for the store-step, and we
187+
// don't provide that right now.
188+
DataFlowPrivate::comprehensionStoreStep(nodeFrom, _, nodeTo)
172189
or
173190
// constructor call
174191
exists(DataFlow::CallCfgNode call | call = nodeTo |

python/ql/test/experimental/dataflow/tainttracking/defaultAdditionalTaintStep/test_attr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_tainted_attr():
2525
# https://github.com/github/codeql/issues/7786
2626

2727
f = Foo(TAINTED_STRING)
28-
ensure_not_tainted(f) # $ SPURIOUS: tainted
28+
ensure_not_tainted(f)
2929
ensure_tainted(f.arg) # $ tainted
3030
ensure_not_tainted(f.other_arg)
3131

@@ -34,7 +34,7 @@ def test_tainted_attr():
3434
ensure_not_tainted(x, x.arg, x.other_arg)
3535

3636
x.arg = TAINTED_STRING
37-
ensure_not_tainted(x) # $ SPURIOUS: tainted
37+
ensure_not_tainted(x)
3838
ensure_tainted(x.arg) # $ tainted
3939
ensure_not_tainted(f.other_arg)
4040

python/ql/test/experimental/dataflow/tainttracking/defaultAdditionalTaintStep/test_with.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def __exit__(self, exc_type, exc, tb):
4949
def test_with_arg():
5050
ctx = Context_arg(TAINTED_STRING)
5151
with ctx as tainted:
52-
ensure_tainted(tainted) # $ tainted
52+
ensure_tainted(tainted) # $ MISSING: tainted
5353

5454

5555

0 commit comments

Comments
 (0)