npm audit: what it checks, and what it misses
Updated November 22, 2026
npm audit sends the name and version of every package in your lockfile to the npm registry, which checks them against the GitHub Advisory Database and returns the known vulnerabilities, with a severity and a fix for each. npm audit fix applies the fixes that stay within your declared version ranges; --force also installs breaking major versions. It's free, built into npm, and worth running in CI. What it can't tell you is whether you installed a malicious version before its advisory existed, or one your lockfile has since moved past.
What npm audit does
npm audit reads your whole dependency tree, direct and transitive, and posts each package's name and versions to the registry's bulk advisory endpoint. Since October 2021 that endpoint has been backed by the GitHub Advisory Database (opens in a new tab). The report lists each vulnerable package, its severity (low, moderate, high or critical), the dependency path that pulls it in, and whether a fix is available.
Two details from npm's documentation (opens in a new tab) trip people up: it needs a package-lock.json or npm-shrinkwrap.json by default, and it exits with a non-zero code as soon as it finds any vulnerability. Install commands also submit an audit by default (the audit setting defaults to true), which is the "found N vulnerabilities" line at the end of npm install.
npm audit commands
| Command | What it does |
|---|---|
npm audit | Prints the vulnerability report for the whole tree |
npm audit --json | The same report as JSON, for scripts and CI |
npm audit --audit-level=high | Fails only on high or critical findings; it changes the exit code, not what's printed |
npm audit --omit=dev | Leaves devDependencies out of the report |
npm audit fix | Updates vulnerable packages to fixed versions within your declared ranges |
npm audit fix --force | Also installs versions outside your ranges, including breaking major versions |
npm audit fix --package-lock-only | Updates package-lock.json without touching node_modules |
npm audit signatures | Verifies the registry signatures and provenance attestations of downloaded packages |
Is npm audit fix safe?
Plain npm audit fix is usually safe: it only moves packages to versions your package.json already allows, which a fresh npm install could pick anyway. Review the lockfile diff and run your tests, as with any update.
npm audit fix --force is different. When the only fixed version is outside your range, it installs it anyway, including SemVer-major releases that can break your build. Run it on a branch, read the changes, or update the direct dependency yourself.
Some findings can't be fixed yet: no patched version exists, or the vulnerable package sits deep in a dependency that hasn't updated. Check whether the vulnerable code is reachable at all (many findings are in build tools that never run in production), and use overrides in package.json to force a patched transitive version when one exists.
Running npm audit in CI
npm ci
npm audit --omit=dev --audit-level=high
npm audit signaturesnpm ci installs exactly what the lockfile says, so the audit checks what you'll ship. --omit=dev and --audit-level=high keep the build from failing on low-severity findings in build tools. Some teams run the audit on a schedule instead of on every pull request, so a new advisory doesn't block an unrelated change.
What npm audit misses
npm audit answers one question: does any version in my lockfile today have a published advisory? A supply chain attack asks a different one: did we install the bad version while it was live? Four gaps follow.
- The advisory comes after the attack. On September 8, 2025, a phished maintainer account published
debug@4.4.2with code that redirected cryptocurrency transactions in browsers. It reached the registry at 13:12 UTC. GitHub's malware advisory, mirrored in OSV as MAL-2025-46974 (opens in a new tab), followed at 14:26 UTC, and the reviewed advisory with a CVE (GHSA-4x49-vf9v-38px (opens in a new tab)) on September 15. For its first 74 minutes, the advisory databases had no record of it. - Malware runs before any audit. Install scripts run during
npm installornpm ci, and a package's code runs the first time you import it. The Shai-Hulud (opens in a new tab) worm compromised over 500 npm packages in 2025: it scanned machines for GitHub tokens and cloud keys and used them to publish infected versions of its victims' own packages. Once it has run, a red audit only tells you it happened. - Your lockfile moves on. npm removes malicious versions, and your next update replaces them. Audit today's lockfile and it's clean, even if the bad version sat in it last week. The answer is in git history: what your lockfile held when the attack started and in every commit during it. CISA's advice for Shai-Hulud was to check lockfiles, nested dependencies included.
- It only sees this project's tree. Not the CLIs installed globally on a developer's laptop, other repositories, CI caches, Docker images or GitHub Actions. A malicious package installed anywhere a token lives is enough.
What to add to npm audit
- Commit the lockfile and install with
npm ci, so every machine and CI run gets the same versions and the audit checks what actually runs. - Let new releases age. npm 11.10 added
min-release-age: withmin-release-age=3in.npmrc, npm installs only versions published more than three days ago. The malicious debug version above was flagged in under 75 minutes. pnpm hasminimumReleaseAge, and the update bots have cooldowns (Renovate vs Dependabot shows both). - Limit install scripts.
ignore-scripts=truein.npmrcstops packages running scripts on install (packages with native builds may need an exception). npm 12'sallow-scriptssetting lists the packages allowed to run them, and pnpm 10 and later skip dependency scripts unless you allow them. - Verify what you download.
npm audit signatureschecks registry signatures and provenance attestations. - Turn on Dependabot malware alerts. They're opt-in, under Settings, Code security, Dependabot, and match your dependencies against GitHub's malware advisories. Socket and similar tools analyze package code for malicious behavior instead of waiting for an advisory; see software supply chain security tools.
- Plan for the incident anyway. When the next compromise lands, you need to know which repos and machines installed the bad version during the window, and which secrets were on them.
That last step is what Pharon does. It keeps a live inventory of every repo's packages, images, actions and runtimes, matches it against new supply chain incidents within minutes, and alerts the team that owns the repo. /pharon:check-incident then checks a machine read-only: the lockfile at the start of the exposure window and every lockfile commit during it, what's installed in node_modules (the pnpm store included), and which secrets to rotate. It's free and needs no account.
Questions
- What does npm audit do?
- It sends the names and versions of the packages in your lockfile to the npm registry, which checks them against the GitHub Advisory Database and reports known vulnerabilities with their severity and available fixes.
- Is npm audit fix safe?
- Usually. Plain npm audit fix only installs versions within the ranges in your package.json. npm audit fix --force can install breaking major versions, so run it on a branch and test.
- Does npm audit check transitive dependencies?
- Yes. It checks every package in the lockfile, not just the ones in package.json, and shows the dependency path to each vulnerable package.
- Does npm audit detect malicious packages?
- Only once an advisory exists for that version. The malicious debug 4.4.2 had no advisory for its first 74 minutes on the registry, and install scripts run before any audit. Pair it with a release-age delay and a malware check.
- How do I make npm audit fail CI only on serious issues?
- Use npm audit --audit-level=high, or critical. Add --omit=dev to leave development dependencies out.
- How do I fix a vulnerability npm audit can't fix?
- Update the direct dependency that pulls it in, or use overrides in package.json to force a patched transitive version. If no fix exists, check whether the vulnerable code is reachable and watch the advisory.
- What are npm vulnerabilities?
- Known security flaws in published npm package versions, recorded as advisories, often with a CVE, in the GitHub Advisory Database. npm audit reports the ones in your dependency tree.