Dependency Supply Chain Risk
npm malware, lockfiles, pin policies, and practical frontend controls against dependency attacks.
- security
- supply-chain
- npm
- dependencies
- sri
Your production bundle is mostly other people’s code. Supply-chain attacks (typosquats, compromised maintainers, malicious postinstall) target that trust. Frontend teams pull thousands of transitive packages — risk is real even if you never write a vulnerability yourself.
Docs: OWASP Dependency Check, npm security, SLSA.
Attack shapes
| Shape | Example |
|---|---|
| Typosquat | lodahs instead of lodash |
| Account takeover | Maintainer publishes malware update |
| Dependency confusion | Private name resolved to public registry |
| Postinstall scripts | Steal env tokens during npm i |
| CDN compromise | Third-party script swaps payload |
Practical controls
- Lockfiles (
package-lock.json/pnpm-lock.yaml) committed and used in CI (npm ci). - Pin versions in apps; renovate/dependabot with review.
- Minimize deps — every library is attack surface and bytes.
- Avoid
latesttags in production pipelines. - Audit
npm audit/ OSV / Snyk as signal, not sole truth. - Disable scripts when possible (
ignore-scripts) in CI with care. - Private registry + deny unknown scopes for internal packages.
- SRI for third-party CDN scripts — SRI.
- CSP reduces impact of injected script hosts.
- Code review for new deps: maintainer health, size, necessity.
Install hygiene
npm ci --ignore-scripts
# run only needed build scripts deliberately
Protect CI secrets: install hooks shouldn’t see cloud credentials if avoidable (separate jobs).
Runtime third parties
Even perfect npm hygiene fails if the page loads https://random-tag.com/x.js without SRI/CSP. Treat runtime tags as deps with owners — third-party cost.
Incident posture
- Ability to yank/pin versions quickly
- SBOM for what shipped
- Monitor package sudden version jumps
Interview out-loud
“Supply-chain risk is typosquats, compromised packages, and third-party scripts. I commit lockfiles, npm ci, minimize deps, review new packages, use SRI/CSP for CDNs, and isolate install scripts from secrets.”
Reviewer prompts
- What is the asset (session, PII, money movement)?
- What is the attacker capability (web, XSS, network, dependency)?
- Which control fails closed if misconfigured?
- Is the server still enforcing authz?
- Any new third party, iframe, or URL sink?
Residual risk note
Browser controls reduce likelihood and impact; they do not eliminate bugs. Prefer defense in depth: safe defaults in code, strict headers, and monitoring (CSP reports, auth anomaly alerts). When product pressure weakens a control, write down the accepted risk and a revisit date.
Related
Further depth
Teams often under-invest in this topic until an incident or CWV regression. Schedule a one-hour drill: reproduce the failure mode in DevTools, list the top three mitigations for your stack, and file tickets with owners. Revisit after the next major feature that touches networking, rendering, auth, or third parties — those are the moments regressions land. Keep primary documentation links in the runbook so on-call is not searching chat history at 2am.
Concrete artifacts to leave behind: a short architecture note, a CI assertion or header snapshot, and a dashboard panel (lab or field) that would have caught the last bug. Teaching the rest of the team the mental model matters as much as the one-line fix.
Further reading
Related guides
- Subresource IntegritySRI hashes on script/link tags so CDN tampering fails closed; generate integrity and pair with CSP.
- Auth Session UX SecuritySession UX that doesn’t weaken security: login states, logout everywhere, idle timeouts, and step-up auth.
- Clickjacking and X-Frame-OptionsStop UI redress attacks with frame-ancestors CSP and X-Frame-Options; know when embedding is intentional.
- Content Security Policy (CSP)Reduce XSS blast radius with CSP — script-src nonces/hashes, strict-dynamic, report-only rollout, and what CSP does not fix.
- CSRF Basics for SPAsCross-site request forgery against cookie sessions: SameSite, CSRF tokens, and SPA fetch patterns.