Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 41e24ae

Browse files
committed
Python: Add non-syntactical test for taint of json methods
1 parent 5f9aa4c commit 41e24ae

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

python/ql/test/experimental/dataflow/tainttracking/defaultAdditionalTaintStep/TestTaint.expected

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
| json.py:27 | fail | test | json.loads(..) |
4040
| json.py:34 | fail | test | tainted_filelike |
4141
| json.py:35 | fail | test | json.load(..) |
42+
| json.py:48 | fail | non_syntacical | dumps(..) |
43+
| json.py:49 | fail | non_syntacical | dumps_alias(..) |
44+
| json.py:50 | fail | non_syntacical | loads(..) |
45+
| json.py:57 | fail | non_syntacical | tainted_filelike |
46+
| json.py:58 | fail | non_syntacical | load(..) |
4247
| string.py:25 | ok | str_operations | ts |
4348
| string.py:26 | ok | str_operations | BinaryExpr |
4449
| string.py:27 | ok | str_operations | BinaryExpr |

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
# Actual tests
1212

13-
import json
1413
from io import StringIO
1514

1615
# Workaround for Python3 not having unicode
@@ -21,6 +20,7 @@
2120
def test():
2221
print("\n# test")
2322
ts = TAINTED_STRING
23+
import json
2424

2525
ensure_tainted(
2626
json.dumps(ts),
@@ -35,7 +35,30 @@ def test():
3535
json.load(tainted_filelike),
3636
)
3737

38+
def non_syntacical():
39+
print("\n# non_syntacical")
40+
ts = TAINTED_STRING
41+
42+
# a less syntactical approach
43+
from json import load, loads, dumps
44+
45+
dumps_alias = dumps
46+
47+
ensure_tainted(
48+
dumps(ts),
49+
dumps_alias(ts),
50+
loads(dumps(ts)),
51+
)
52+
53+
# For Python2, need to convert to unicode for StringIO to work
54+
tainted_filelike = StringIO(unicode(dumps(ts)))
55+
56+
ensure_tainted(
57+
tainted_filelike,
58+
load(tainted_filelike),
59+
)
3860

3961
# Make tests runable
4062

4163
test()
64+
non_syntacical()

0 commit comments

Comments
 (0)