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
| Tool | Use |
|---|---|
npm audit | Built in: known CVEs in dependencies |
| Dependabot / Renovate | Automatic update PRs |
| Snyk / Socket.dev | Vulnerability + malicious-package detection |
npm ci | Installs exactly what the lockfile says |
lockfile-lint | Checks that the lockfile only points to trusted registries |
| OWASP Dependency-Check | Multi-language CVE scanning |
syft / CycloneDX | Generate 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 ciin 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)