Skip to content

Commit f669a4f

Browse files
yoffowen-mc
authored andcommitted
Python: Make sure all imprecise taint bubbles up
1 parent 3275c81 commit f669a4f

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
@@ -4244,8 +4244,15 @@ module StdlibPrivate {
42444244
)
42454245
// TODO: Once we have DictKeyContent, we need to transform that into ListElementContent
42464246
) and
4247-
output = "ReturnValue.ListElement" and
4248-
preservesValue = true
4247+
(
4248+
//Element content is mutated into list element content
4249+
output = "ReturnValue.ListElement" and
4250+
preservesValue = true
4251+
or
4252+
// Since list content is imprecise, we also taint the list.
4253+
output = "ReturnValue" and
4254+
preservesValue = false
4255+
)
42494256
or
42504257
input = "Argument[0]" and
42514258
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)