Dependency and Supply Chain Security

Most of your app is other people's code. One bad package can compromise everything (event-stream, ua-parser-js, the xz backdoor).

Tools

ToolUse
npm auditBuilt in: known CVEs in dependencies
Dependabot / RenovateAutomatic update PRs
Snyk / Socket.devVulnerability + malicious-package detection
npm ciInstalls exactly what the lockfile says
lockfile-lintChecks that the lockfile only points to trusted registries
OWASP Dependency-CheckMulti-language CVE scanning
syft / CycloneDXGenerate an SBOM (software bill of materials)

Commands

npm audit --omit=dev          # production dependencies only
npm audit fix                 # safe upgrades
npm ci                        # in CI/Docker; never `npm install`
npm ci --ignore-scripts       # blocks postinstall scripts (a common malware path)
npm outdated

.github/dependabot.yml

version: 2
updates:
  - package-ecosystem: npm
    directory: /
    schedule: { interval: weekly }
  - package-ecosystem: docker
    directory: /
    schedule: { interval: weekly }

Before adding a package, ask

  • Do I need it, or is it a few lines of code / already in the standard library?
  • Is it maintained? Downloads, last release, open issues, number of maintainers
  • Is the name exactly right? Typosquatting: expresss, lodahs, crossenv
  • How many transitive dependencies does it pull in?

Checklist

  • Commit the lockfile; npm ci in CI
  • npm audit / Snyk in CI, failing on high/critical
  • Dependabot or Renovate turned on
  • Pin GitHub Actions to a commit SHA
  • 2FA on npm and GitHub accounts
  • Remove unused dependencies (npx depcheck)