@@ -97,7 +97,7 @@ def remediation_is_valid(vuln, remediation_data):
97
97
98
98
if vulnerability_name in remediation_data .keys ():
99
99
remediation = remediation_data [vulnerability_name ]
100
- if (remediation_status == remediation [0 ] and remediation_comment == remediation [1 ]):
100
+ if (remediation_status == remediation [0 ] and remediation_comment == remediation [1 ]. replace ( ' \\ n' , ' \n ' ) ):
101
101
return None
102
102
return remediation_data [vulnerability_name ]
103
103
else :
@@ -133,7 +133,7 @@ def set_vulnerablity_remediation(hub, vuln, remediation_status, remediation_comm
133
133
response = hub .execute_put (url , data = update )
134
134
return response
135
135
136
- def process_vulnerabilities (hub , vulnerable_components , remediation_data = None , exclusion_data = None , dry_run = False ):
136
+ def process_vulnerabilities (hub , vulnerable_components , remediation_data = None , exclusion_data = None , dry_run = False , overwrite_existing = False ):
137
137
138
138
if (dry_run ):
139
139
print (f"Opening dry run output file: { dry_run } " )
@@ -144,8 +144,8 @@ def process_vulnerabilities(hub, vulnerable_components, remediation_data=None, e
144
144
print ('"Component Name","Component Version","CVE","Reason","Remeidation Status","HTTP response code"' )
145
145
146
146
for vuln in vulnerable_components ['items' ]:
147
- if vuln ['vulnerabilityWithRemediation' ]['remediationStatus' ] == "NEW" :
148
- remediation_action = None
147
+ if overwrite_existing or vuln ['vulnerabilityWithRemediation' ]['remediationStatus' ] == "NEW" :
148
+ remediation_action = None
149
149
exclusion_action = None
150
150
151
151
if (remediation_data ):
@@ -166,8 +166,7 @@ def process_vulnerabilities(hub, vulnerable_components, remediation_data=None, e
166
166
167
167
if (remediation_action ):
168
168
if (dry_run ):
169
- remediation_action .insert (0 , vuln ['vulnerabilityWithRemediation' ]['vulnerabilityName' ])
170
- csv_writer .writerow (remediation_action )
169
+ csv_writer .writerow ([vuln ['vulnerabilityWithRemediation' ]['vulnerabilityName' ]] + remediation_action )
171
170
else :
172
171
resp = set_vulnerablity_remediation (hub , vuln , remediation_action [0 ],remediation_action [1 ])
173
172
count += 1
@@ -220,6 +219,7 @@ def main(argv=None): # IGNORE:C0111
220
219
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' )
221
220
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' )
222
221
parser .add_argument ('-V' , '--version' , action = 'version' , version = program_version_message )
222
+ parser .add_argument ("--overwrite-existing" , dest = 'overwrite_existing' , action = "store_true" , help = 'By default only NEW vulnerabilities are remediated. Enabling this flag will update all vulnerabilities.' )
223
223
224
224
# Process arguments
225
225
args = parser .parse_args ()
@@ -233,6 +233,7 @@ def main(argv=None): # IGNORE:C0111
233
233
#dry_run = args.dry_run
234
234
#dry_run_output = args.dry_run_output
235
235
dry_run = args .dry_run
236
+ overwrite_existing = args .overwrite_existing
236
237
print (args .dry_run )
237
238
238
239
message = f"{ program_version_message } \n \n Project: { projectname } \n Version: { projectversion } \n Process origin exclusion list: { process_origin_exclulsion } \n Process CVE remediation list: { process_cve_remediation } "
@@ -276,8 +277,9 @@ def main(argv=None): # IGNORE:C0111
276
277
277
278
# Retrieve the vulnerabiltites for the project version. Newer API versions only allow 1000 items at most.
278
279
vulnerable_components = hub .get_vulnerable_bom_components (version , 1000 )
279
- process_vulnerabilities (hub , vulnerable_components , remediation_data , exclusion_data , dry_run )
280
-
280
+
281
+ process_vulnerabilities (hub , vulnerable_components , remediation_data , exclusion_data , dry_run , overwrite_existing )
282
+
281
283
return 0
282
284
except Exception :
283
285
### handle keyboard interrupt ###
0 commit comments