Skip to content

Commit 320c33e

Browse files
committed
fix(audit): fail on a severity the wrapper cannot rank
Severity is ranked by index into a fixed list, and an unrecognized string yields -1, which sorts below every configured threshold. A renamed or newly added bun severity therefore skips every advisory carrying it and the job reports a clean tree, which is the failure the wrapper exists to prevent rather than one it can absorb quietly.
1 parent 922b9dc commit 320c33e

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

scripts/audit.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ function runAudit (directory) {
7878
// match, so surface it instead.
7979
if (!advisory?.url) throw new Error(`Advisory for ${packageName} in '${directory}' has no URL to identify it.`)
8080
const id = ghsaId(advisory.url)
81+
// An unrecognized severity would rank below every threshold and skip the advisory silently, so a renamed or
82+
// added bun severity has to fail here rather than turn the whole job green.
83+
if (!SEVERITIES.includes(advisory.severity)) {
84+
throw new Error(`Advisory ${id} in '${directory}' reports unknown severity '${advisory.severity}'.`)
85+
}
8186
advisories.set(id, { id, package: packageName, severity: advisory.severity, title: advisory.title })
8287
}
8388
}

scripts/test/audit.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ describe('scripts/audit.js', () => {
5151
assert.match(result.stderr, /unaccepted high advisory GHSA-bbbb-bbbb-bbbb in some-package/)
5252
})
5353

54+
it('fails on a severity it cannot rank instead of skipping the advisory', () => {
55+
const result = runAudit({
56+
report: { 'some-package': [advisory('GHSA-ffff-ffff-ffff', 'medium')] },
57+
allow: [],
58+
})
59+
60+
assert.strictEqual(result.status, 1)
61+
assert.match(result.stderr, /GHSA-ffff-ffff-ffff .* reports unknown severity 'medium'/)
62+
})
63+
5464
it('ignores an advisory below the directory threshold', () => {
5565
const result = runAudit({
5666
report: { 'some-package': [advisory('GHSA-cccc-cccc-cccc', 'moderate')] },

0 commit comments

Comments
 (0)