Code you did not write, and secrets you should not ship · senior
Supply-chain risk: npm, lockfiles, install scripts and SRI
Most of your bundle is other people's code, so a compromised package or CDN runs with full access to your page and your CI; you reduce the risk with lockfiles and reproducible installs, fewer and vetted dependencies, blocked install scripts, delayed adoption of new versions, SRI for CDN files and short-lived publish credentials.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Real incidents: in Sep 2025 attackers phished an npm maintainer and published malicious versions of very popular packages (chalk, debug); days later the Shai-Hulud worm spread through post-install scripts, stole tokens and other secrets from developer machines and CI, and republished itself (GitHub removed 500+ packages).
- npm's response (Dec 2025): classic tokens revoked, npm login gives 2-hour sessions, write tokens last at most 90 days, 2FA by default for new packages, and OIDC trusted publishing from CI is recommended.
- Lockfile committed + npm ci (or pnpm install --frozen-lockfile) gives the same tree on every machine. Review lockfile diffs in PRs.
- Install scripts (postinstall) run arbitrary code on install. pnpm 10 does not run dependency install scripts by default; with npm you can use --ignore-scripts. Waiting a few days before adopting brand-new versions avoids most worm waves.
- Subresource Integrity for CDN files: <script src=... integrity="sha384-..." crossorigin="anonymous">; on mismatch the browser refuses to run it. It protects against a changed file, not a changed URL. (The polyfill.io domain takeover in 2024 is the classic example of trusting a CDN.)
- Also: Dependabot/Renovate with review, npm audit or Socket-style scanners, minimum permissions for CI tokens, and CSP to limit what injected code can reach.
The red pen
Common traps: mistake → fix
Mistake: "npm install in CI is fine"
Fix: it can change versions within your ranges; use npm ci with a committed lockfile.
Mistake: "npm audit clean means safe"
Fix: audit knows only reported CVEs, not a fresh malicious release.
Mistake: "SRI protects dynamic scripts like analytics that change every day"
Fix: SRI needs a fixed file; for changing files you must trust or self-host.
Easy to hard
Questions interviewers ask, easy to hard
- What is a supply-chain attack in frontend? Give a real example.
- How do lockfiles help, and what is the difference between npm install and npm ci?
- What is SRI and when can't you use it?
- Design a dependency policy for a 30-engineer frontend team after the 2025 npm worms.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.