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 the audit json report inconsistent via property format #7915

Draft
wants to merge 1 commit into
base: latest
Choose a base branch
from
Draft
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
48 changes: 45 additions & 3 deletions workspaces/arborist/lib/audit-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,33 @@ class AuditReport extends Map {
// require a semver major update.
const vulnerabilities = []
for (const [name, vuln] of this.entries()) {
vulnerabilities.push([name, vuln.toJSON()])
const vulnJson = vuln.toJSON()

// **Modification Start**
// Ensure that the 'via' property is consistently an array of objects
vulnJson.via = vulnJson.via.map(viaEntry => {
if (typeof viaEntry === 'string') {
return {
name: viaEntry,
source: null,
dependency: viaEntry,
title: `Vulnerability in ${viaEntry}`,
url: null,
severity: vulnJson.severity,
range: vulnJson.range,
via: [],
effects: [],
type: 'indirect',
vulnerableVersions: vulnJson.range,
patchedVersions: vulnJson.patchedVersions,
}
} else {
return viaEntry
}
})
// **Modification End**

vulnerabilities.push([name, vulnJson])
obj.metadata.vulnerabilities[vuln.severity]++
}

Expand Down Expand Up @@ -157,9 +183,25 @@ class AuditReport extends Map {
continue
}

// we will have loaded the source already if this is a metavuln
if (advisory.type === 'metavuln') {
vuln.addVia(this.get(advisory.dependency))
// **Modification Start**
// Ensure that 'vuln.addVia' always receives an object
const depVuln = this.get(advisory.dependency)
vuln.addVia(depVuln || {
name: advisory.dependency,
source: null,
dependency: advisory.dependency,
title: `Vulnerability in ${advisory.dependency}`,
url: null,
severity: advisory.severity || vuln.severity,
range: advisory.vulnerable_versions || vuln.range,
via: [],
effects: [],
type: 'indirect',
vulnerableVersions: advisory.vulnerable_versions || vuln.range,
patchedVersions: advisory.patched_versions || vuln.patchedVersions,
})
// **Modification End**
}

// already marked this one, no need to do it again
Expand Down
Loading