Skip to content

Commit ee96655

Browse files
committed
Python: Make sure all imprecise taint bubbles up
1 parent 53b1678 commit ee96655

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

python/ql/lib/semmle/python/frameworks/Stdlib.qll

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4157,8 +4157,15 @@ module StdlibPrivate {
41574157
)
41584158
// TODO: Once we have DictKeyContent, we need to transform that into ListElementContent
41594159
) and
4160-
output = "ReturnValue.ListElement" and
4161-
preservesValue = true
4160+
(
4161+
//Element content is mutated into list element content
4162+
output = "ReturnValue.ListElement" and
4163+
preservesValue = true
4164+
or
4165+
// Since list content is imprecise, we also taint the list.
4166+
output = "ReturnValue" and
4167+
preservesValue = false
4168+
)
41624169
or
41634170
input = "Argument[0]" and
41644171
output = "ReturnValue" and

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,11 @@ def test_construction():
2727
tainted_dict, # $ tainted
2828
)
2929

30-
# There are no implicit reads for list content as it is imprecise
31-
# Therefore, list content stemming from precise content does not end up on the list itself.
3230
ensure_tainted(
3331
list(tainted_list), # $ tainted
34-
list(tainted_tuple)[0], # $ tainted
32+
list(tainted_tuple), # $ tainted
3533
list(tainted_set), # $ tainted
36-
list(tainted_dict.values())[0], # $ tainted
37-
list(tainted_dict.items())[0], # $ tainted
34+
list(tainted_dict.values()), # $ tainted
3835

3936
tuple(tainted_list), # $ tainted
4037
set(tainted_list), # $ tainted
@@ -46,7 +43,8 @@ def test_construction():
4643
)
4744

4845
ensure_not_tainted(
49-
dict(k = tainted_string)["k1"]
46+
dict(k = tainted_string)["k1"],
47+
list(tainted_dict.items()),
5048
)
5149

5250

0 commit comments

Comments
 (0)