Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Inspector reports should link to CVEs (#6557) #6562

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions scripts/export_inspector_findings.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def parse_finding(self, finding: JSON) -> tuple[str, SummaryType]:
resource_type = resource['type']
summary = {
'severity': severity,
'source_url': finding['packageVulnerabilityDetails']['sourceUrl'],
'resource_type': resource_type,
'resources': set(),
}
Expand Down Expand Up @@ -169,10 +170,21 @@ def column_alpha(self, col: int) -> str:
def findings_sort(self, item: tuple[str, list[SummaryType]]) -> tuple[int, str]:
score = 0
weights = {'HIGH': 1, 'CRITICAL': 10}
for summary in item[1]:
vulnerability, summaries = item
for summary in summaries:
count = len(summary['resources'])
score += count * weights.get(summary['severity'], 0)
return score, item[0]
if vulnerability.startswith('CVE-'):
# Best effort on sorting CVEs by descending year and sequence
# number. Other types of findings are sorted strictly
# alphanumerically.
sequence = vulnerability.rsplit('-', 1)[1]
# The sequence number portion of CVE IDs is at most seven digits
# long. We pad it to that length so that, for example, a CVE with
# sequence number 11 precedes one with number 2.
# See https://cve.mitre.org/cve/identifiers/syntaxchange.html#new.
vulnerability = vulnerability.removesuffix(sequence) + f'{sequence:0>7}'
return score, vulnerability

def write_to_csv(self, findings: dict[str, list[SummaryType]]) -> None:
titles = [
Expand All @@ -198,7 +210,9 @@ def write_to_csv(self, findings: dict[str, list[SummaryType]]) -> None:
row_num = len(rows) + 1
col_range = f'C{row_num}:{last_col}{row_num}'
severity_formula = f'=(COUNTIF({col_range},"C")*10)+(COUNTIF({col_range},"H"))'
row = [vulnerability, severity_formula]
urls = sorted([summary['source_url'] for summary in summaries], reverse=True)
hyperlink = f'=HYPERLINK("{urls.pop(0)}","{vulnerability}")'
row = [hyperlink, severity_formula]
for column_index in range(len(row), len(titles) + 1):
row.append(column_values.get(column_index, ''))
rows.append(row)
Expand Down
Loading