3030)
3131
3232
33- def main (command_line_args = sys .argv [1 :]): # noqa: C901
33+ def discover_files (targets , excluded_files , recursive = False ):
34+ included_files = list ()
35+ excluded_list = excluded_files .split ("," )
36+ for target in targets :
37+ if os .path .isdir (target ):
38+ for root , dirs , files in os .walk (target ):
39+ for f in files :
40+ fullpath = os .path .join (root , f )
41+ if os .path .splitext (fullpath )[1 ] == '.py' and fullpath .split ("/" )[- 1 ] not in excluded_list :
42+ included_files .append (fullpath )
43+ if not recursive :
44+ break
45+ else :
46+ if target not in excluded_list :
47+ included_files .append (target )
48+ return included_files
49+ 50+ 51+ def main (command_line_args = sys .argv [1 :]):
3452 args = parse_args (command_line_args )
3553
3654 ui_mode = UImode .NORMAL
@@ -39,60 +57,67 @@ def main(command_line_args=sys.argv[1:]): # noqa: C901
3957 elif args .trim_reassigned_in :
4058 ui_mode = UImode .TRIM
4159
42- path = os .path .normpath (args .filepath )
60+ files = discover_files (
61+ args .targets ,
62+ args .excluded_paths ,
63+ args .recursive
64+ )
65+ 66+ for path in files :
67+ vulnerabilities = list ()
68+ if args .ignore_nosec :
69+ nosec_lines = set ()
70+ else :
71+ file = open (path , 'r' )
72+ lines = file .readlines ()
73+ nosec_lines = set (
74+ lineno for
75+ (lineno , line ) in enumerate (lines , start = 1 )
76+ if '#nosec' in line or '# nosec' in line
77+ )
4378
44- if args .ignore_nosec :
45- nosec_lines = set ()
46- else :
47- file = open (path , 'r' )
48- lines = file .readlines ()
49- nosec_lines = set (
50- lineno for
51- (lineno , line ) in enumerate (lines , start = 1 )
52- if '#nosec' in line or '# nosec' in line
53- )
79+ if args .project_root :
80+ directory = os .path .normpath (args .project_root )
81+ else :
82+ directory = os .path .dirname (path )
83+ project_modules = get_modules (directory )
84+ local_modules = get_directory_modules (directory )
85+ tree = generate_ast (path )
5486
55- if args .project_root :
56- directory = os .path .normpath (args .project_root )
57- else :
58- directory = os .path .dirname (path )
59- project_modules = get_modules (directory )
60- local_modules = get_directory_modules (directory )
87+ cfg = make_cfg (
88+ tree ,
89+ project_modules ,
90+ local_modules ,
91+ path
92+ )
93+ cfg_list = [cfg ]
6194
62- tree = generate_ast (path )
6395
64- cfg = make_cfg (
65- tree ,
66- project_modules ,
67- local_modules ,
68- path
69- )
70- cfg_list = [cfg ]
71- framework_route_criteria = is_flask_route_function
72- if args .adaptor :
73- if args .adaptor .lower ().startswith ('e' ):
74- framework_route_criteria = is_function
75- elif args .adaptor .lower ().startswith ('p' ):
76- framework_route_criteria = is_function_without_leading_
77- elif args .adaptor .lower ().startswith ('d' ):
78- framework_route_criteria = is_django_view_function
79- # Add all the route functions to the cfg_list
80- FrameworkAdaptor (
81- cfg_list ,
82- project_modules ,
83- local_modules ,
84- framework_route_criteria
85- )
96+ framework_route_criteria = is_flask_route_function
97+ if args .adaptor :
98+ if args .adaptor .lower ().startswith ('e' ):
99+ framework_route_criteria = is_function
100+ elif args .adaptor .lower ().startswith ('p' ):
101+ framework_route_criteria = is_function_without_leading_
102+ elif args .adaptor .lower ().startswith ('d' ):
103+ framework_route_criteria = is_django_view_function
104+ # Add all the route functions to the cfg_list
105+ FrameworkAdaptor (
106+ cfg_list ,
107+ project_modules ,
108+ local_modules ,
109+ framework_route_criteria
110+ )
86111
87- initialize_constraint_table (cfg_list )
88- analyse (cfg_list )
89- vulnerabilities = find_vulnerabilities (
90- cfg_list ,
91- ui_mode ,
92- args .blackbox_mapping_file ,
93- args .trigger_word_file ,
94- nosec_lines
95- )
112+ initialize_constraint_table (cfg_list )
113+ analyse (cfg_list )
114+ vulnerabilities . extend ( find_vulnerabilities (
115+ cfg_list ,
116+ ui_mode ,
117+ args .blackbox_mapping_file ,
118+ args .trigger_word_file ,
119+ nosec_lines
120+ ) )
96121
97122 if args .baseline :
98123 vulnerabilities = get_vulnerabilities_not_in_baseline (
0 commit comments