Skip to content

Commit d4d2e95

Browse files
authored
Merge pull request #166 from bcaller/shorter-reassignments
Remove extraneous reassignments in output
2 parents c0e6ace + c4893e7 commit d4d2e95

File tree

2 files changed

+6
-60
lines changed

2 files changed

+6
-60
lines changed

pyt/vulnerabilities/vulnerability_helper.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
from enum import Enum
55
from collections import namedtuple
6+
from itertools import takewhile
67

78
from ..core.node_types import YieldNode
89

@@ -56,16 +57,13 @@ def __init__(
5657
self.sink = sink
5758
self.sink_trigger_word = sink_trigger_word
5859

59-
self.reassignment_nodes = reassignment_nodes
60-
self._remove_sink_from_secondary_nodes()
60+
# Remove the sink node and all nodes after the sink from the list of reassignments.
61+
self.reassignment_nodes = list(takewhile(
62+
lambda node: node is not sink,
63+
reassignment_nodes
64+
))
6165
self._remove_non_propagating_yields()
6266

63-
def _remove_sink_from_secondary_nodes(self):
64-
try:
65-
self.reassignment_nodes.remove(self.sink)
66-
except ValueError: # pragma: no cover
67-
pass
68-
6967
def _remove_non_propagating_yields(self):
7068
"""Remove yield with no variables e.g. `yield 123` and plain `yield` from vulnerability."""
7169
for node in list(self.reassignment_nodes):

tests/vulnerabilities/vulnerabilities_test.py

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,6 @@ def test_XSS_result(self):
150150
Reassigned in:
151151
File: examples/vulnerable_code/XSS.py
152152
> Line 6: param = ~call_1
153-
File: examples/vulnerable_code/XSS.py
154-
> Line 9: ~call_3 = ret_make_response(~call_4)
155-
File: examples/vulnerable_code/XSS.py
156-
> Line 9: resp = ~call_3
157-
File: examples/vulnerable_code/XSS.py
158-
> Line 10: ret_XSS1 = resp
159153
File: examples/vulnerable_code/XSS.py
160154
> reaches line 9, sink "replace(":
161155
~call_4 = ret_html.replace('{{ param }}', param)
@@ -274,8 +268,6 @@ def test_path_traversal_sanitised_result(self):
274268
> Line 10: image_name = ~call_2
275269
File: examples/vulnerable_code/path_traversal_sanitised.py
276270
> Line 12: ~call_4 = ret_os.path.join(~call_5, image_name)
277-
File: examples/vulnerable_code/path_traversal_sanitised.py
278-
> Line 12: ret_cat_picture = ~call_3
279271
File: examples/vulnerable_code/path_traversal_sanitised.py
280272
> reaches line 12, sink "send_file(":
281273
~call_3 = ret_send_file(~call_4)
@@ -297,8 +289,6 @@ def test_path_traversal_sanitised_2_result(self):
297289
> Line 8: image_name = ~call_1
298290
File: examples/vulnerable_code/path_traversal_sanitised_2.py
299291
> Line 12: ~call_3 = ret_os.path.join(~call_4, image_name)
300-
File: examples/vulnerable_code/path_traversal_sanitised_2.py
301-
> Line 12: ret_cat_picture = ~call_2
302292
File: examples/vulnerable_code/path_traversal_sanitised_2.py
303293
> reaches line 12, sink "send_file(":
304294
~call_2 = ret_send_file(~call_3)
@@ -318,8 +308,6 @@ def test_sql_result(self):
318308
Reassigned in:
319309
File: examples/vulnerable_code/sql/sqli.py
320310
> Line 26: param = ~call_1
321-
File: examples/vulnerable_code/sql/sqli.py
322-
> Line 27: result = ~call_2
323311
File: examples/vulnerable_code/sql/sqli.py
324312
> reaches line 27, sink "execute(":
325313
~call_2 = ret_db.engine.execute(param)
@@ -335,13 +323,6 @@ def test_XSS_form_result(self):
335323
File: examples/vulnerable_code/XSS_form.py
336324
> User input at line 14, source "form[":
337325
data = request.form['my_text']
338-
Reassigned in:
339-
File: examples/vulnerable_code/XSS_form.py
340-
> Line 15: ~call_1 = ret_make_response(~call_2)
341-
File: examples/vulnerable_code/XSS_form.py
342-
> Line 15: resp = ~call_1
343-
File: examples/vulnerable_code/XSS_form.py
344-
> Line 17: ret_example2_action = resp
345326
File: examples/vulnerable_code/XSS_form.py
346327
> reaches line 15, sink "replace(":
347328
~call_2 = ret_html1.replace('{{ data }}', data)
@@ -360,12 +341,6 @@ def test_XSS_url_result(self):
360341
Reassigned in:
361342
File: examples/vulnerable_code/XSS_url.py
362343
> Line 6: param = url
363-
File: examples/vulnerable_code/XSS_url.py
364-
> Line 9: ~call_2 = ret_make_response(~call_3)
365-
File: examples/vulnerable_code/XSS_url.py
366-
> Line 9: resp = ~call_2
367-
File: examples/vulnerable_code/XSS_url.py
368-
> Line 10: ret_XSS1 = resp
369344
File: examples/vulnerable_code/XSS_url.py
370345
> reaches line 9, sink "replace(":
371346
~call_3 = ret_html.replace('{{ param }}', param)
@@ -390,12 +365,6 @@ def test_XSS_reassign_result(self):
390365
> Line 6: param = ~call_1
391366
File: examples/vulnerable_code/XSS_reassign.py
392367
> Line 8: param = param + ''
393-
File: examples/vulnerable_code/XSS_reassign.py
394-
> Line 11: ~call_3 = ret_make_response(~call_4)
395-
File: examples/vulnerable_code/XSS_reassign.py
396-
> Line 11: resp = ~call_3
397-
File: examples/vulnerable_code/XSS_reassign.py
398-
> Line 12: ret_XSS1 = resp
399368
File: examples/vulnerable_code/XSS_reassign.py
400369
> reaches line 11, sink "replace(":
401370
~call_4 = ret_html.replace('{{ param }}', param)
@@ -418,12 +387,6 @@ def test_XSS_sanitised_result(self):
418387
> Line 9: ~call_2 = ret_Markup.escape(param)
419388
File: examples/vulnerable_code/XSS_sanitised.py
420389
> Line 9: param = ~call_2
421-
File: examples/vulnerable_code/XSS_sanitised.py
422-
> Line 12: ~call_4 = ret_make_response(~call_5)
423-
File: examples/vulnerable_code/XSS_sanitised.py
424-
> Line 12: resp = ~call_4
425-
File: examples/vulnerable_code/XSS_sanitised.py
426-
> Line 13: ret_XSS1 = resp
427390
File: examples/vulnerable_code/XSS_sanitised.py
428391
> reaches line 12, sink "replace(":
429392
~call_5 = ret_html.replace('{{ param }}', param)
@@ -449,12 +412,6 @@ def test_XSS_variable_assign_result(self):
449412
> Line 6: param = ~call_1
450413
File: examples/vulnerable_code/XSS_variable_assign.py
451414
> Line 8: other_var = param + ''
452-
File: examples/vulnerable_code/XSS_variable_assign.py
453-
> Line 11: ~call_3 = ret_make_response(~call_4)
454-
File: examples/vulnerable_code/XSS_variable_assign.py
455-
> Line 11: resp = ~call_3
456-
File: examples/vulnerable_code/XSS_variable_assign.py
457-
> Line 12: ret_XSS1 = resp
458415
File: examples/vulnerable_code/XSS_variable_assign.py
459416
> reaches line 11, sink "replace(":
460417
~call_4 = ret_html.replace('{{ param }}', other_var)
@@ -479,12 +436,6 @@ def test_XSS_variable_multiple_assign_result(self):
479436
> Line 10: not_the_same_var = '' + other_var
480437
File: examples/vulnerable_code/XSS_variable_multiple_assign.py
481438
> Line 12: another_one = not_the_same_var + ''
482-
File: examples/vulnerable_code/XSS_variable_multiple_assign.py
483-
> Line 15: ~call_3 = ret_make_response(~call_4)
484-
File: examples/vulnerable_code/XSS_variable_multiple_assign.py
485-
> Line 15: resp = ~call_3
486-
File: examples/vulnerable_code/XSS_variable_multiple_assign.py
487-
> Line 17: ret_XSS1 = resp
488439
File: examples/vulnerable_code/XSS_variable_multiple_assign.py
489440
> reaches line 15, sink "replace(":
490441
~call_4 = ret_html.replace('{{ param }}', another_one)
@@ -550,9 +501,6 @@ def test_django_view_param(self):
550501
File: examples/vulnerable_code/django_XSS.py
551502
> User input at line 4, source "Framework function URL parameter":
552503
param
553-
Reassigned in:
554-
File: examples/vulnerable_code/django_XSS.py
555-
> Line 5: ret_xss1 = ~call_1
556504
File: examples/vulnerable_code/django_XSS.py
557505
> reaches line 5, sink "render(":
558506
~call_1 = ret_render(request, 'templates/xss.html', 'param'param)

0 commit comments

Comments
 (0)