15
15
from pyt .constraint_table import initialize_constraint_table
16
16
from pyt .fixed_point import analyse
17
17
from pyt .framework_adaptor import FrameworkAdaptor
18
- from pyt .framework_helper import (
18
+ from pyt .framework_helper import (
19
19
is_django_view_function ,
20
- is_flask_route_function
20
+ is_flask_route_function ,
21
+ is_function
21
22
)
22
23
from pyt .node_types import Node
23
24
from pyt .reaching_definitions_taint import ReachingDefinitionsTaintAnalysis
@@ -95,17 +96,15 @@ def test_find_triggers(self):
95
96
l = vulnerabilities .find_triggers (XSS1 .nodes , trigger_words )
96
97
self .assert_length (l , expected_length = 1 )
97
98
98
-
99
99
def test_find_sanitiser_nodes (self ):
100
100
cfg_node = Node (None , None , line_number = None , path = None )
101
- sanitiser_tuple = vulnerabilities .Sanitiser ('escape' , cfg_node )
101
+ sanitiser_tuple = vulnerabilities .Sanitiser ('escape' , cfg_node )
102
102
sanitiser = 'escape'
103
103
104
104
result = list (vulnerabilities .find_sanitiser_nodes (sanitiser , [sanitiser_tuple ]))
105
105
self .assert_length (result , expected_length = 1 )
106
106
self .assertEqual (result [0 ], cfg_node )
107
107
108
-
109
108
def test_build_sanitiser_node_dict (self ):
110
109
self .cfg_create_from_file ('examples/vulnerable_code/XSS_sanitised.py' )
111
110
cfg_list = [self .cfg ]
@@ -114,7 +113,7 @@ def test_build_sanitiser_node_dict(self):
114
113
115
114
cfg = cfg_list [1 ]
116
115
117
- cfg_node = Node (None , None , line_number = None , path = None )
116
+ cfg_node = Node (None , None , line_number = None , path = None )
118
117
sinks_in_file = [vulnerabilities .TriggerNode ('replace' , ['escape' ], cfg_node )]
119
118
120
119
sanitiser_dict = vulnerabilities .build_sanitiser_node_dict (cfg , sinks_in_file )
@@ -142,7 +141,6 @@ def run_analysis(self, path):
142
141
)
143
142
)
144
143
145
-
146
144
def test_find_vulnerabilities_assign_other_var (self ):
147
145
vulnerabilities = self .run_analysis ('examples/vulnerable_code/XSS_assign_to_other_var.py' )
148
146
self .assert_length (vulnerabilities , expected_length = 1 )
@@ -555,3 +553,37 @@ def test_django_view_param(self):
555
553
~call_1 = ret_render(request, 'templates/xss.html', 'param'param)
556
554
"""
557
555
self .assertTrue (self .string_compare_alpha (vulnerability_description , EXPECTED_VULNERABILITY_DESCRIPTION ))
556
+
557
+
558
+ class EngineEveryTest (BaseTestCase ):
559
+ def run_empty (self ):
560
+ return
561
+
562
+ def run_analysis (self , path ):
563
+ self .cfg_create_from_file (path )
564
+ cfg_list = [self .cfg ]
565
+
566
+ FrameworkAdaptor (cfg_list , [], [], is_function )
567
+ initialize_constraint_table (cfg_list )
568
+
569
+ analyse (cfg_list , analysis_type = ReachingDefinitionsTaintAnalysis )
570
+
571
+ trigger_word_file = os .path .join (
572
+ 'pyt' ,
573
+ 'vulnerability_definitions' ,
574
+ 'all_trigger_words.pyt'
575
+ )
576
+
577
+ return vulnerabilities .find_vulnerabilities (
578
+ cfg_list ,
579
+ ReachingDefinitionsTaintAnalysis ,
580
+ UImode .NORMAL ,
581
+ VulnerabilityFiles (
582
+ default_blackbox_mapping_file ,
583
+ trigger_word_file
584
+ )
585
+ )
586
+
587
+ def test_self_is_not_tainted (self ):
588
+ vulnerabilities = self .run_analysis ('examples/example_inputs/def_with_self_as_first_arg.py' )
589
+ self .assert_length (vulnerabilities , expected_length = 0 )
0 commit comments