Skip to content

Commit

Permalink
feat: order packages by vulnerability
Browse files Browse the repository at this point in the history
  • Loading branch information
tembleking committed Jul 29, 2024
1 parent 921d841 commit 47e6cda
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function addVulnTableToSummary(data: Report) {
]);
}


function addVulnsByLayerTableToSummary(data: Report) {
if (!data.result.layers) {
return
Expand All @@ -53,17 +54,31 @@ function addVulnsByLayerTableToSummary(data: Report) {

data.result.layers.forEach((layer, index) => {
core.summary.addCodeBlock(`LAYER ${index} - ${layer.command.replace(new RegExp('\$', 'g'), "$").replace(new RegExp('\&', 'g'), '&')}`);

if (!layer.digest) {
return;
}

let packagesWithVulns = (packagesPerLayer[layer.digest] ?? [])
.filter(pkg => pkg.vulns);

if (packagesWithVulns.length == 0) {
return;
}

let orderedPackagesBySeverity = packagesWithVulns.sort((a, b) => {
const getSeverityCount = (pkg: Package, severity: string) =>
pkg.vulns?.filter((vul: any) => vul.severity.value === severity).length || 0;

const severities = ['Critical', 'High', 'Medium', 'Low', 'Negligible'];
for (const severity of severities) {
const countA = getSeverityCount(a, severity);
const countB = getSeverityCount(b, severity);
if (countA !== countB) {
return countB - countA;
}
}
return 0;
})

core.summary.addTable([
[
{ data: 'Package', header: true },
Expand All @@ -77,7 +92,7 @@ function addVulnsByLayerTableToSummary(data: Report) {
{ data: '⚪ Negligible', header: true },
{ data: 'Exploit', header: true },
],
...packagesWithVulns.map(layerPackage => {
...orderedPackagesBySeverity.map(layerPackage => {
let criticalVulns = layerPackage.vulns?.filter(vuln => vuln.severity.value.toLowerCase() == 'critical').length ?? 0;
let highVulns = layerPackage.vulns?.filter(vuln => vuln.severity.value.toLowerCase() == 'high').length ?? 0;
let mediumVulns = layerPackage.vulns?.filter(vuln => vuln.severity.value.toLowerCase() == 'medium').length ?? 0;
Expand Down

0 comments on commit 47e6cda

Please sign in to comment.