26
26
Each processing step can be turned on or off. At least one step must be run. Default
27
27
is to run both.
28
28
29
- The script get's it CVE and orign lists from CSV files. The CSV filenames are loaded
29
+ The script can get's its CVE and orign lists from CSV files. The CSV filenames are loaded
30
30
from Custom Fields in the Black Duck project. This allows different groups of projects to
31
31
use different remeidation settings. If a CVE remediation status should apply globally
32
32
to all projects, Black Duck's global remediation feature should be used.
33
33
34
+ The script can also get the CSV filenames from the command line arguments.
35
+
34
36
Here is an example of the CSV data for the CVE list:
35
37
36
38
"CVE-2016-1840","IGNORED","Applies only to Apple OS"
@@ -114,9 +116,19 @@ def find_custom_field_value (custom_fields, custom_field_label):
114
116
return None
115
117
return None
116
118
119
+
120
+
121
+ def set_vulnerablity_remediation (hub , vuln , remediation_status , remediation_comment ):
122
+ url = vuln ['_meta' ]['href' ]
123
+ update = {}
124
+ update ['remediationStatus' ] = remediation_status
125
+ update ['comment' ] = remediation_comment
126
+ response = hub .execute_put (url , data = update )
127
+ return response
128
+
117
129
def process_vulnerabilities (hub , vulnerable_components , remediation_data = None , exclusion_data = None ):
118
130
count = 0
119
- print ('"Component Name","Component Version","Component OriginID"," CVE","Reason","Remeidation Status","HTTP response code"' )
131
+ print ('"Component Name","Component Version","CVE","Reason","Remeidation Status","HTTP response code"' )
120
132
121
133
for vuln in vulnerable_components ['items' ]:
122
134
if vuln ['vulnerabilityWithRemediation' ]['remediationStatus' ] == "NEW" :
@@ -125,6 +137,8 @@ def process_vulnerabilities(hub, vulnerable_components, remediation_data=None, e
125
137
126
138
if (exclusion_data ):
127
139
exclusion_action = origin_is_excluded (vuln , exclusion_data )
140
+ else :
141
+ exclusion_action = None
128
142
129
143
# If vuln has both a remdiation action and an origin exclusion action, set remdiation status
130
144
# to the remdiation action. Append the exclusion action's comment to the overall comment.
@@ -137,13 +151,14 @@ def process_vulnerabilities(hub, vulnerable_components, remediation_data=None, e
137
151
reason = 'origin-exclusion'
138
152
139
153
if (remediation_action ):
140
- resp = hub . set_vulnerablity_remediation (vuln , remediation_action [0 ],remediation_action [1 ])
154
+ resp = set_vulnerablity_remediation (hub , vuln , remediation_action [0 ],remediation_action [1 ])
141
155
count += 1
142
- print ('\" {}\" ,\" {}\" ,\" {}\" ,\" {}\" ,\" {}\" ,\" {}\" , \" {} \" ' .
156
+ print ('\" {}\" ,\" {}\" ,\" {}\" ,\" {}\" ,\" {}\" ,\" {}\" ' .
143
157
format (vuln ['componentName' ], vuln ['componentVersionName' ],
144
- vuln ['componentVersionOriginId' ],
145
158
vuln ['vulnerabilityWithRemediation' ]['vulnerabilityName' ],
146
159
reason , remediation_action [0 ], resp .status_code ))
160
+
161
+
147
162
print (f'Remediated { count } vulnerabilities.' )
148
163
149
164
def main (argv = None ): # IGNORE:C0111
@@ -178,7 +193,9 @@ def main(argv=None): # IGNORE:C0111
178
193
parser = ArgumentParser (description = program_license , formatter_class = RawDescriptionHelpFormatter )
179
194
parser .add_argument ("projectname" , help = "Project nname" )
180
195
parser .add_argument ("projectversion" , help = "Project vesrsion" )
181
- parser .add_argument ("--no-process-cve-remediation-list" , dest = 'process_cve_remediation_list' , action = 'store_false' , help = "Disbable processing CVE-Remediation-list" )
196
+ parser .add_argument ("--remediation-list" , dest = "local_remediation_list" , default = None , help = "Filename of cve remediation list csv file" )
197
+ parser .add_argument ("--origin-exclusion-list" , dest = "local_origin_exclusion_list" , default = None , help = "Filename of origin exclusion list csv file" )
198
+ parser .add_argument ("--no-process-cve-remediation-list" , dest = 'process_cve_remediation_list' , action = 'store_false' , help = "Disable processing CVE-Remediation-list" )
182
199
parser .add_argument ("--no-process-origin-exclusion-list" , dest = 'process_origin_exclusion_list' , action = 'store_false' , help = "Disable processing Origin-Exclusion-List" )
183
200
parser .add_argument ("--cve-remediation-list-custom-field-label" , default = 'CVE Remediation List' , help = 'Label of Custom Field on Black Duck that contains remeidation list file name' )
184
201
parser .add_argument ("--origin-exclusion-list-custom-field-label" , default = 'Origin Exclusion List' , help = 'Label of Custom Field on Black Duck that containts origin exclusion list file name' )
@@ -189,6 +206,8 @@ def main(argv=None): # IGNORE:C0111
189
206
190
207
projectname = args .projectname
191
208
projectversion = args .projectversion
209
+ local_cve_remediation_file = args .local_remediation_list
210
+ local_origin_exclusion_file = args .local_origin_exclusion_list
192
211
process_cve_remediation = args .process_cve_remediation_list
193
212
process_origin_exclulsion = args .process_origin_exclusion_list
194
213
@@ -203,21 +222,34 @@ def main(argv=None): # IGNORE:C0111
203
222
hub = HubInstance ()
204
223
project = hub .get_project_by_name (projectname )
205
224
version = hub .get_project_version_by_name (projectname , projectversion )
206
- custom_fields = hub .get_cf_values (project )
225
+
226
+ custom_fields = hub .get_cf_values (project )
207
227
208
228
if (process_cve_remediation ):
209
- cve_remediation_file = find_custom_field_value (custom_fields , args .cve_remediation_list_custom_field_label )
210
- print (f' Opening: { args .cve_remediation_list_custom_field_label } :{ cve_remediation_file } ' )
229
+
230
+ if (local_cve_remediation_file ):
231
+ cve_remediation_file = local_cve_remediation_file
232
+ print (f' Opening: { cve_remediation_file } ' )
233
+ else :
234
+ cve_remediation_file = find_custom_field_value (custom_fields , args .cve_remediation_list_custom_field_label )
235
+ print (f' Opening: { args .cve_remediation_list_custom_field_label } :{ cve_remediation_file } ' )
236
+
211
237
remediation_data = load_remediation_input (cve_remediation_file )
212
238
else :
213
239
remediation_data = None
214
240
215
241
if (process_origin_exclulsion ):
216
- exclusion_list_file = find_custom_field_value (custom_fields , args .origin_exclusion_list_custom_field_label )
217
- print (f' Opening: { args .origin_exclusion_list_custom_field_label } :{ exclusion_list_file } ' )
242
+
243
+ if local_origin_exclusion_file :
244
+ exclusion_list_file = local_origin_exclusion_file
245
+ print (f' Opening: { exclusion_list_file } ' )
246
+ else :
247
+ exclusion_list_file = find_custom_field_value (custom_fields , args .origin_exclusion_list_custom_field_label )
248
+ print (f' Opening: { args .origin_exclusion_list_custom_field_label } :{ exclusion_list_file } ' )
218
249
exclusion_data = load_remediation_input (exclusion_list_file )
219
250
else :
220
251
exclusion_data = None
252
+
221
253
222
254
# Retrieve the vulnerabiltites for the project version
223
255
vulnerable_components = hub .get_vulnerable_bom_components (version )
0 commit comments