Skip to content

Commit 59160ee

Browse files
committed
Python: Add test showing taint for attr store
In `x.arg = TAINTED_STRING` there is a store step to the attribute `arg` of `x`. In our taint modeling, we allow _any_ store step with the code below. This means that we also say there is a taint-step directly from `TAINTED_STRING` to `x` :| ```codeql // construction by literal // TODO: Not limiting the content argument here feels like a BIG hack, but we currently get nothing for free :| DataFlowPrivate::storeStep(nodeFrom, _, nodeTo) ```
1 parent e9b496b commit 59160ee

File tree

1 file changed

+43
-0
lines changed
  • python/ql/test/experimental/dataflow/tainttracking/defaultAdditionalTaintStep

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Add taintlib to PATH so it can be imported during runtime without any hassle
2+
import sys; import os; sys.path.append(os.path.dirname(os.path.dirname((__file__))))
3+
from taintlib import *
4+
5+
# This has no runtime impact, but allows autocomplete to work
6+
from typing import TYPE_CHECKING
7+
if TYPE_CHECKING:
8+
from ..taintlib import *
9+
10+
11+
# Actual tests
12+
13+
class Foo:
14+
def __init__(self, arg):
15+
self.arg = arg
16+
self.other_arg = "other_arg"
17+
18+
19+
def test_tainted_attr():
20+
# The following demonstrates how tainting an attribute affected the taintedness of
21+
# the object.
22+
#
23+
# Previously we would (wrongly) treat the object as tainted if we noticed a write of
24+
# a tainted value to any of its' attributes. This lead to FP, highlighted in
25+
# https://github.com/github/codeql/issues/7786
26+
27+
f = Foo(TAINTED_STRING)
28+
ensure_not_tainted(f) # $ SPURIOUS: tainted
29+
ensure_tainted(f.arg) # $ tainted
30+
ensure_not_tainted(f.other_arg)
31+
32+
33+
x = Foo("x")
34+
ensure_not_tainted(x, x.arg, x.other_arg)
35+
36+
x.arg = TAINTED_STRING
37+
ensure_not_tainted(x) # $ SPURIOUS: tainted
38+
ensure_tainted(x.arg) # $ tainted
39+
ensure_not_tainted(f.other_arg)
40+
41+
42+
b = Foo("bar")
43+
ensure_not_tainted(b, b.arg, b.other_arg)

0 commit comments

Comments
 (0)