Audit Dependencies for Known CVEs
A vulnerability report is only actionable once you know which resolved version is affected, whether the affected code path runs, and whether a fix exists.
Procedure
- Resolve the full graph first — scanners read lockfiles, not
package.jsonranges:npm cithennpm audit --json > audit.jsonPython:pip-audit -r requirements.txt --format=json. Rust:cargo audit --json. Go:govulncheck ./.... - Prefer a database-agnostic scanner for coverage across ecosystems:
osv-scanner -r .readspackage-lock.json,go.mod,Cargo.lock, andrequirements.txt. - Container images:
grype dir:. -o tableortrivy image --severity HIGH,CRITICAL myimg:latest. - For each finding record: package, installed version, fixed version, CVSS, and path (
npm ls lodashshows the requirer). - Cut noise by reachability.
govulncheckandpip-audit --fix --dry-rundistinguish called functions from mere presence. A CVE in an unused transitive dev dependency is not shipping risk. - Triage with a threshold, e.g. block the release on CVSS >= 7.0 with a fix available; track the rest in a dated exception file with an owner and expiry.
- Apply fixes bottom-up:
npm audit fix(never--forceblindly),pip-audit --fix,cargo update -p crate. - Re-run the scanner and confirm the count drops. Store the JSON as a build artifact for trend tracking.
Pitfalls
npm auditreports the dev-only tree too; a build-tool CVE cannot be exploited at runtime unless the tool runs on untrusted input.- Advisory data lags. A "0 vulnerabilities" result is "none known yet", not "safe".
npm audit fix --forcejumps to a semver-major and can break the build; read the diff first.- Pinning an old version to silence a warning trades a known bug for a known CVE. Upgrade instead.
- Scanners miss vendored or git-URL dependencies that never enter the lockfile.
Verification
osv-scanner -r . --format=json | jq '[.results[].packages[].vulnerabilities[]] | length'
Exit code 0 with a count of 0 (or only accepted exceptions) is a pass. Compare the number against audit.json from the previous run to show the direction of travel.
Report: " advisories, reachable and fixable, all upgraded to ; osv-scanner -r . now exits clean."