Skip to content

Commit 437feeb

Browse files
committed
Python: Make sure all imprecise taint bubbles up
1 parent 290bb5a commit 437feeb

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4319,8 +4319,15 @@ module StdlibPrivate {
43194319
)
43204320
// TODO: Once we have DictKeyContent, we need to transform that into ListElementContent
43214321
) and
4322-
output = "ReturnValue.ListElement" and
4323-
preservesValue = true
4322+
(
4323+
//Element content is mutated into list element content
4324+
output = "ReturnValue.ListElement" and
4325+
preservesValue = true
4326+
or
4327+
// Since list content is imprecise, we also taint the list.
4328+
output = "ReturnValue" and
4329+
preservesValue = false
4330+
)
43244331
or
43254332
input = "Argument[0]" and
43264333
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)