Skip to content

Commit 4e75793

Browse files
authored
fix(general): Support CVE suppressions with the root file in repo (#6948)
support suppressions with the root file in repo
1 parent 638682e commit 4e75793

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

checkov/common/bridgecrew/integration_features/features/suppressions_integration.py

+20-15
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,25 @@ def _check_suppressions(self, record: Record, suppressions: Optional[list[dict[s
169169
return suppression
170170
return None
171171

172+
def _check_cve_suppression(self, record: Record, suppression: dict[str, Any]) -> bool:
173+
if 'accountIds' not in suppression:
174+
return False
175+
if self.bc_integration.repo_id and self.bc_integration.source_id and self.bc_integration.source_id in \
176+
suppression['accountIds'] \
177+
and suppression['cves']:
178+
repo_name = align_path(self.bc_integration.repo_id).split('/')[-1]
179+
suppression_path = self._get_cve_suppression_path(suppression)
180+
repo_file_path = align_path(record.repo_file_path)
181+
file_abs_path = align_path(record.file_abs_path)
182+
if file_abs_path == suppression_path[1:] or \
183+
file_abs_path == suppression_path or \
184+
file_abs_path.endswith("".join([repo_name, suppression_path])) or \
185+
removeprefix(repo_file_path, '/') == removeprefix(suppression_path, '/') \
186+
or record.file_path == suppression_path:
187+
return any(record.vulnerability_details and record.vulnerability_details['id'] == cve['cve']
188+
for cve in suppression['cves'])
189+
return False
190+
172191
def _check_suppression(self, record: Record, suppression: dict[str, Any]) -> bool:
173192
"""
174193
Returns True if and only if the specified suppression applies to the specified record.
@@ -217,21 +236,7 @@ def _check_suppression(self, record: Record, suppression: dict[str, Any]) -> boo
217236
return False
218237

219238
elif type == 'Cves':
220-
if 'accountIds' not in suppression:
221-
return False
222-
if self.bc_integration.repo_id and self.bc_integration.source_id and self.bc_integration.source_id in suppression['accountIds']\
223-
and suppression['cves']:
224-
repo_name = align_path(self.bc_integration.repo_id).split('/')[-1]
225-
suppression_path = self._get_cve_suppression_path(suppression)
226-
repo_file_path = align_path(record.repo_file_path)
227-
file_abs_path = align_path(record.file_abs_path)
228-
if file_abs_path == suppression_path[1:] or \
229-
file_abs_path == suppression_path or \
230-
file_abs_path.endswith("".join([repo_name, suppression_path])) or \
231-
removeprefix(repo_file_path, '/') == removeprefix(suppression_path, '/'):
232-
return any(record.vulnerability_details and record.vulnerability_details['id'] == cve['cve']
233-
for cve in suppression['cves'])
234-
return False
239+
return self._check_cve_suppression(record, suppression)
235240

236241
elif type == 'LicenseType':
237242
return any(record.vulnerability_details and record.vulnerability_details['license'] == license_type

tests/common/integration_features/test_suppressions_integration.py

+8
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,19 @@ def test_supress_by_cve_for_package_scan(self):
515515
resource=None, evaluations=None,
516516
check_class=None, file_abs_path='notrequirements.txt', entity_tags=None,
517517
vulnerability_details={'id': 'CVE-2022-45452'})
518+
record5 = Record(check_id='BC_VUL_2', check_name=None, check_result=None,
519+
code_block=None, file_path=None,
520+
file_line_range=None,
521+
resource=None, evaluations=None,
522+
check_class=None, file_abs_path='home/requirements.txt', entity_tags=None,
523+
vulnerability_details={'id': 'CVE-2021-23727'})
524+
record5.file_path = '/requirements.txt'
518525

519526
self.assertTrue(suppressions_integration._check_suppression(record1, suppression))
520527
self.assertTrue(suppressions_integration._check_suppression(record2, suppression))
521528
self.assertFalse(suppressions_integration._check_suppression(record3, suppression))
522529
self.assertFalse(suppressions_integration._check_suppression(record4, suppression))
530+
self.assertTrue(suppressions_integration._check_suppression(record5, suppression))
523531

524532
def test_suppress_by_cve_with_empty_cves(self):
525533
instance = BcPlatformIntegration()

0 commit comments

Comments
 (0)