A typical Node.js application pulls in 800-2000 transitive npm packages. The CVE feed gets a steady stream of disclosures in those packages — sometimes critical, sometimes noise. npm audit is the default first pass; Snyk is the commercial layer with richer remediation, exploitable-path analysis, and license reporting. This walks through making both useful in CI without drowning in advisories you cannot fix.
How to verify
Run a one-shot audit on the repo to see the current state:
npm audit --omit=dev --json | jq '.metadata.vulnerabilities'
npx snyk test --severity-threshold=high
cat package-lock.json | jq '.dependencies | length' # total locked deps
npm ls --all 2>/dev/null | wc -l # nested view
git log -- package-lock.json | head -5 # how often lockfile changes
If npm audit shows hundreds of advisories, most are in transitive dev dependencies you cannot directly fix. Focus on production deps (--omit=dev) and high/critical severity first.
What’s happening
npm audit queries the npm registry’s advisory API with the resolved tree from your package-lock.json and reports CVEs. It is bundled with npm, runs offline against a cached advisory database, and is the cheapest possible scan. It does NOT distinguish exploitable from non-exploitable usage — a vuln in lodash is flagged whether you call the affected function or not.
Snyk goes further: an explicit vulnerability database with curated severity, reachability analysis (does your code path actually call the vulnerable function), license compliance, container/IaC scanning, and a remediation engine that suggests the minimum upgrade chain. The free tier covers small teams and most open source. Both tools read your lockfile — if you don’t commit a lockfile, neither produces reliable results.
The procedure
-
Commit your lockfile.
package-lock.jsonfor npm,yarn.lockfor Yarn,pnpm-lock.yamlfor pnpm. Without it, every install resolves fresh and the scanner sees a tree the build won’t reproduce:git ls-files | grep lock echo 'package-lock=true' >> .npmrc -
Wire
npm auditinto CI. Fail the build on high/critical vulnerabilities only — moderate noise will be ignored otherwise:# .github/workflows/ci.yml - name: npm audit (production) run: npm audit --omit=dev --audit-level=high - name: npm audit (full, report only) run: npm audit --json > audit-report.json || true - uses: actions/upload-artifact@v4 with: { name: audit-report, path: audit-report.json } -
Add Snyk for richer signal. Authenticate with a service token in CI:
- name: snyk test uses: snyk/actions/node@master env: { SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} } with: args: --severity-threshold=high --fail-on=upgradable -
For repos with vulnerable transitive deps you cannot upgrade immediately, declare an exception with
npm-audit-resolveror Snyk’s.snykignore file. This is the right answer when an advisory is in a path your code does not reach:# .snyk ignore: 'SNYK-JS-LODASH-567746': - '*': reason: 'Not reachable in our use of lodash; pinned for upstream fix' expires: '2026-09-01T00:00:00.000Z' -
Schedule Snyk to monitor the deployed manifest, not just the CI-time tree, so an advisory disclosed after the build still raises an alert:
npx snyk monitor --project-name=myapp-prod -
Automate dependency updates with Renovate or Dependabot. Both open PRs when a fixed version is available; combined with the audit step in CI, vulnerable deps stay in the codebase for hours not weeks:
{ "extends": ["config:base", "schedule:weekly"], "vulnerabilityAlerts": { "enabled": true, "labels": ["security"] } }
Common pitfalls
npm audit fix --forceupgrades across major versions silently. It will downgrade your dependencies’ major versions, break the build, and leave the next dev confused. Usenpm audit fixwithout--forceand resolve majors by hand.- The advisory database has false positives — packages are renamed, advisories are reused. Read the advisory before scrambling to fix.
- A CVE in a dev dependency (e.g. a test runner) does not ship to production. Scan production tree separately with
--omit=dev. - Snyk’s reachability analysis assumes static call graphs. Dynamic
require(name)patterns are invisible; a vulnerability “not reachable” by Snyk may still be exploitable through reflection. - Both tools cache. A vulnerability disclosed yesterday may not appear until you
npm audit --refreshor re-runsnyk testwith cleared local cache.
For supply-chain attacks that audit tools cannot detect (typosquatting, dependency confusion), see supply-chain security with LavaMoat. In the engagements Stack Harbor runs, npm audit and Snyk both run on every PR; the Snyk monitor endpoint pings into a service desk on disclosure, and as part of managed operations we own the patch SLA — critical CVEs get a same-day remediation PR, not a quarterly batch.