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

Skip to content

Commit b9f740c

Browse files
bcallerBen Caller
authored andcommitted
AugAssign propagates taint
Before, the variable would be tainted only if the last += was tainted. Now url = 'http://' url += TAINT url += '?x=y' Is marked as vulnerable.
1 parent 8c24cc8 commit b9f740c

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

pyt/cfg/stmt_visitor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,11 +499,12 @@ def visit_AugAssign(self, node):
499499
rhs_visitor = RHSVisitor()
500500
rhs_visitor.visit(node.value)
501501

502+
lhs = extract_left_hand_side(node.target)
502503
return self.append_node(AssignmentNode(
503504
label.result,
504-
extract_left_hand_side(node.target),
505+
lhs,
505506
node,
506-
rhs_visitor.result,
507+
rhs_visitor.result + [lhs],
507508
path=self.filenames[-1]
508509
))
509510

tests/cfg/cfg_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,14 @@ def test_assignment_starred_list(self):
820820
[('a', ['d']), ('b', ['d']), ('c', ['e'])],
821821
)
822822

823+
def test_augmented_assignment(self):
824+
self.cfg_create_from_ast(ast.parse('a+=f(b,c)'))
825+
826+
(node,) = self.cfg.nodes[1:-1]
827+
self.assertEqual(node.label, 'a += f(b, c)')
828+
self.assertEqual(node.left_hand_side, 'a')
829+
self.assertEqual(node.right_hand_side_variables, ['b', 'c', 'a'])
830+
823831

824832
class CFGComprehensionTest(CFGBaseTestCase):
825833
def test_nodes(self):

tests/main_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ def test_targets_with_recursive(self):
8484
excluded_files = ""
8585

8686
included_files = discover_files(targets, excluded_files, True)
87-
self.assertEqual(len(included_files), 31)
87+
self.assertEqual(len(included_files), 32)
8888

8989
def test_targets_with_recursive_and_excluded(self):
9090
targets = ["examples/vulnerable_code/"]
9191
excluded_files = "inter_command_injection.py"
9292

9393
included_files = discover_files(targets, excluded_files, True)
94-
self.assertEqual(len(included_files), 30)
94+
self.assertEqual(len(included_files), 31)

0 commit comments

Comments
 (0)