Skip to content

Commit

Permalink
fix: Scan job fails even though CVE is on ignore list
Browse files Browse the repository at this point in the history
  • Loading branch information
taro-kayo authored and alexjurkiewicz committed Oct 31, 2023
1 parent ff9105b commit ac357ae
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,26 @@ function configureGlobalProxy(proxyUrl) {
});
}

function countFailingVulnerabilities(failThreshold, foundCounts, ignoredCounts) {
let count = foundCounts.critical - ignoredCounts.critical;
if (failThreshold === 'critical') {
return count;
}
count += foundCounts.high - ignoredCounts.high;
if (failThreshold === 'high') {
return count;
}
count += foundCounts.medium - ignoredCounts.medium;
if (failThreshold === 'medium') {
return count;
}
count += foundCounts.low - ignoredCounts.low;
if (failThreshold === 'low') {
return count;
}
return count + foundCounts.informational - ignoredCounts.informational;
}

const main = async () => {
core.debug('Entering main')
const repository = core.getInput('repository', { required: true })
Expand Down Expand Up @@ -247,12 +267,11 @@ const main = async () => {
console.log('=================')
console.log(`${total.toString().padStart(3, ' ')} Total ${getCount('total', ignoredCounts)}`)

const numFailingVulns =
failThreshold === 'informational' ? total - ignoredCounts.informational
: failThreshold === 'low' ? critical + high + medium + low - ignoredCounts.low
: failThreshold === 'medium' ? critical + high + medium - ignoredCounts.medium
: failThreshold === 'high' ? critical + high - ignoredCounts.high
: /* failThreshold === 'critical' ? */ critical - ignoredCounts.critical
const numFailingVulns = countFailingVulnerabilities(
failThreshold,
{ informational, low, medium, high, critical },
ignoredCounts,
)

if (numFailingVulns > 0) {
throw new Error(`Detected ${numFailingVulns} vulnerabilities with severity >= ${failThreshold} (the currently configured fail_threshold).`)
Expand Down

0 comments on commit ac357ae

Please sign in to comment.