Security Auditing (`npm audit`)
Complete guide to vulnerability scanning with npm audit and pnpm audit, severity levels (low, moderate, high, critical), npm audit fix, and handling overrides.
The npm audit command scans your project's dependency tree against the GitHub Advisory Database to find known security vulnerabilities and security advisories (CVEs).
Running an Audit
# npm
npm audit
# pnpm
pnpm auditJSON Output (CI/CD Pipelines)
npm audit --json > audit-report.jsonVulnerability Severity Levels
| Severity | Description | Action Required |
|---|---|---|
| Low | Minor risk, difficult to exploit in typical environments | Review during scheduled maintenance |
| Moderate | Moderate risk, requires specific configuration or inputs | Update at earliest convenience |
| High | Significant security flaw, denial of service, data leakage | Update immediately |
| Critical | Remote code execution (RCE), unauthenticated compromise | Emergency hotfix |
Fixing Vulnerabilities
1. Automatic Non-Breaking Fixes
Updates compatible minor/patch versions:
npm audit fix2. Automatic Major Version Fixes (Use Caution)
Upgrades to breaking major versions if required to resolve the advisory:
npm audit fix --force[!CAUTION]
--forcecan break application code by installing major breaking releases. Always run test suites afterwards!
3. Forcing Transitive Fixes via overrides
If a vulnerable transitive dependency is nested inside an unmaintained parent package, enforce the safe sub-package version using overrides in package.json:
{
"overrides": {
"axios": "^1.7.7",
"cookie": "^0.7.0"
}
}Related Guides
Checking Outdated Dependencies (`npm outdated`)
Complete guide to analyzing outdated dependencies with npm outdated and pnpm outdated, interpreting Current, Wanted, and Latest columns, and automation.
Workspaces & Monorepos Introduction
Complete introduction to monorepos, npm workspaces, pnpm workspaces, inter-package dependencies, shared configs, and unified dependency management.