Skip to content

Commit 9d81fd3

Browse files
committed
Python: Improve sanitizer/guards tests
Based on review conversation
1 parent 7aa559f commit 9d81fd3

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed

python/ql/test/experimental/dataflow/tainttracking/customSanitizer/InlineTaintTest.expected

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@ untaintedArgumentToEnsureTaintedNotMarkedAsMissing
33
failures
44
isSanitizer
55
| TestTaintTrackingConfiguration | test.py:21:39:21:39 | ControlFlowNode for s |
6-
| TestTaintTrackingConfiguration | test.py:53:10:53:29 | ControlFlowNode for emulated_escaping() |
6+
| TestTaintTrackingConfiguration | test.py:34:39:34:39 | ControlFlowNode for s |
7+
| TestTaintTrackingConfiguration | test.py:66:10:66:29 | ControlFlowNode for emulated_escaping() |
78
isSanitizerGuard
8-
| TestTaintTrackingConfiguration | test.py:38:8:38:26 | ControlFlowNode for emulated_is_safe() |
9+
| TestTaintTrackingConfiguration | test.py:51:8:51:26 | ControlFlowNode for emulated_is_safe() |
910
| TestTaintTrackingConfiguration | test_logical.py:29:8:29:17 | ControlFlowNode for is_safe() |
1011
| TestTaintTrackingConfiguration | test_logical.py:44:8:44:17 | ControlFlowNode for is_safe() |
11-
| TestTaintTrackingConfiguration | test_logical.py:52:12:52:21 | ControlFlowNode for is_safe() |
12-
| TestTaintTrackingConfiguration | test_logical.py:72:8:72:17 | ControlFlowNode for is_safe() |
13-
| TestTaintTrackingConfiguration | test_logical.py:80:12:80:21 | ControlFlowNode for is_safe() |
14-
| TestTaintTrackingConfiguration | test_logical.py:104:8:104:17 | ControlFlowNode for is_safe() |
15-
| TestTaintTrackingConfiguration | test_logical.py:127:12:127:21 | ControlFlowNode for is_safe() |
16-
| TestTaintTrackingConfiguration | test_logical.py:132:16:132:25 | ControlFlowNode for is_safe() |
17-
| TestTaintTrackingConfiguration | test_logical.py:137:20:137:29 | ControlFlowNode for is_safe() |
12+
| TestTaintTrackingConfiguration | test_logical.py:49:8:49:17 | ControlFlowNode for is_safe() |
13+
| TestTaintTrackingConfiguration | test_logical.py:59:8:59:17 | ControlFlowNode for is_safe() |
14+
| TestTaintTrackingConfiguration | test_logical.py:67:12:67:21 | ControlFlowNode for is_safe() |
15+
| TestTaintTrackingConfiguration | test_logical.py:87:8:87:17 | ControlFlowNode for is_safe() |
16+
| TestTaintTrackingConfiguration | test_logical.py:95:12:95:21 | ControlFlowNode for is_safe() |
17+
| TestTaintTrackingConfiguration | test_logical.py:119:8:119:17 | ControlFlowNode for is_safe() |
18+
| TestTaintTrackingConfiguration | test_logical.py:142:12:142:21 | ControlFlowNode for is_safe() |
19+
| TestTaintTrackingConfiguration | test_logical.py:147:16:147:25 | ControlFlowNode for is_safe() |
20+
| TestTaintTrackingConfiguration | test_logical.py:152:20:152:29 | ControlFlowNode for is_safe() |
1821
| TestTaintTrackingConfiguration | test_reference.py:30:8:30:17 | ControlFlowNode for is_safe() |
1922
| TestTaintTrackingConfiguration | test_reference.py:40:8:40:25 | ControlFlowNode for is_safe() |
2023
| TestTaintTrackingConfiguration | test_reference.py:55:8:55:21 | ControlFlowNode for is_safe() |

python/ql/test/experimental/dataflow/tainttracking/customSanitizer/test.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def emulated_authentication_check(arg):
1414
raise Exception("user unauthenticated")
1515

1616

17-
def test_custom_sanitizer_exception():
17+
def test_custom_sanitizer_exception_raise():
1818
s = TAINTED_STRING
1919

2020
try:
@@ -27,6 +27,19 @@ def test_custom_sanitizer_exception():
2727
ensure_not_tainted(s)
2828

2929

30+
def test_custom_sanitizer_exception_pass():
31+
s = TAINTED_STRING
32+
33+
try:
34+
emulated_authentication_check(s)
35+
ensure_not_tainted(s)
36+
except:
37+
ensure_tainted(s) # $ tainted
38+
pass
39+
40+
ensure_tainted(s) # $ tainted
41+
42+
3043
def emulated_is_safe(arg):
3144
# emulating something we won't be able to look at source code for
3245
return eval("False")
@@ -52,12 +65,14 @@ def test_escape():
5265

5366
s2 = emulated_escaping(s)
5467
ensure_not_tainted(s2)
68+
ensure_tainted(s) # $ tainted
5569

5670

5771
# Make tests runable
5872

73+
test_custom_sanitizer_exception_pass()
5974
try:
60-
test_custom_sanitizer_exception()
75+
test_custom_sanitizer_exception_raise()
6176
except Exception:
6277
pass
6378
test_custom_sanitizer_guard()

python/ql/test/experimental/dataflow/tainttracking/customSanitizer/test_logical.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ def test_basic():
3737
ensure_not_tainted(s) # $ SPURIOUS: tainted
3838

3939

40+
def test_if_in_depth():
41+
s = TAINTED_STRING
42+
43+
# ensure that value is still considered tainted after guard check
44+
if is_safe(s):
45+
ensure_not_tainted(s)
46+
ensure_tainted(s) # $ tainted
47+
48+
# ensure new tainted assignment to variable is not treated as safe by guard
49+
if is_safe(s):
50+
ensure_not_tainted(s)
51+
s = TAINTED_STRING
52+
ensure_tainted(s) # $ tainted
53+
54+
4055
def test_or():
4156
s = TAINTED_STRING
4257

@@ -160,6 +175,7 @@ def test_with_exception():
160175
# Make tests runable
161176

162177
test_basic()
178+
test_if_in_depth()
163179
test_or()
164180
test_and()
165181
test_tricky()

0 commit comments

Comments
 (0)