ESC

Type to search the knowledge base.

Dependency Supply Chain Risk

npm malware, lockfiles, pin policies, and practical frontend controls against dependency attacks.

intermediate3 min read
  • 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

  1. Lockfiles (package-lock.json / pnpm-lock.yaml) committed and used in CI (npm ci).
  2. Pin versions in apps; renovate/dependabot with review.
  3. Minimize deps — every library is attack surface and bytes.
  4. Avoid latest tags in production pipelines.
  5. Audit npm audit / OSV / Snyk as signal, not sole truth.
  6. Disable scripts when possible (ignore-scripts) in CI with care.
  7. Private registry + deny unknown scopes for internal packages.
  8. SRI for third-party CDN scripts — SRI.
  9. CSP reduces impact of injected script hosts.
  10. 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.

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