Software supply chain: other people's code in your build
A typical web app pulls in hundreds of packages, each able to run code at install time. Typosquatting, hijacked maintainers and dependency confusion turn that trust into an attack path. The practical defenses, and what an SBOM is for.
In one sentence
Pin versions with a lockfile and npm ci, restrict install scripts, review new dependencies and updates, keep an SBOM, and give your build as few secrets as possible.
Three ways a malicious package gets in
A popular package's maintainer is phished. Version 4.2.1 ships with a credential stealer; ^4.2.0 in your package.json picks it up on the next install.
your-app ├─ express@4.21.2 ├─ popular-lib@4.2.1 ← compromised release │ └─ postinstall: node steal.js └─ zod@4.6.7
✕ Install script ran in CI: npm token and cloud credentials stolen
A practical baseline
| Practice | Stops |
|---|---|
Commit the lockfile, install with npm ci (no silent upgrades) | Surprise malicious releases picked up by ^ranges |
ignore-scripts by default, allowlist the few packages that need them | Most install-time payloads |
| Review new deps: age, downloads, maintainers, repo link; delay brand-new versions a few days | Typosquats and freshly hijacked releases |
| Scoped registry config for private packages | Dependency confusion |
| Automated updates (Dependabot / Renovate) + vulnerability scanning | Known CVEs lingering for months |
| SBOM (CycloneDX / SPDX) generated in CI | Answering "are we affected?" in minutes (Log4Shell) |
Key takeaways
- 01Every dependency is code you run, often at install time.
- 02Lockfiles, npm ci and restricted install scripts block most attacks.
- 03Review new packages and updates before they reach main.
- 04An SBOM tells you instantly where a vulnerable component lives.
Check your understanding
1 of 3
When can a malicious npm package run code?
Related concepts
CI/CD security
Treat PRs from forks as untrusted code, pin actions to a commit SHA, use OIDC instead of stored cloud keys, and gate deploys behind protected branches and reviewers.
6 min read →Secrets management
A secret in a repo is leaked, even after you delete it. Keep secrets in a vault or the platform's secret store, scan before push, scope every key, and revoke first, investigate second.
6 min read →Defense in depth
Every control has holes. Line up several independent ones and the holes rarely align: the Swiss cheese model.
6 min read →