The question says it all.
Is npm install still safe after the 2026 supply chain attacks?
1 answer
It can be, if you use npm 12 and keep its new defaults. Install scripts are now off unless you approve them, which blocks the trick the 2026 worms used. Add pinned versions, a committed lockfile and short lived tokens, and you are far safer than you were a year ago.
I run installs for our projects every day, so this one matters to me.
What happened
In August 2026 Microsoft described a self spreading worm in more than 400 npm packages from unrelated publishers, including keyv, flat-cache and cache-manager. It ran from a
preinstallscript, stole developer and CI credentials, then used the stolen tokens to publish poisoned versions of other packages.Python was hit too. On 17 November 2026, versions 1.26.1 and 1.26.2 of Microsoft's
agent-frameworkpackage on PyPI were published with a stealer. It used a.pthfile, which runs every time Python starts, even if you never import the package. It collected environment variables,.envfiles and cloud and CI tokens. The last clean version is 1.26.0.What changed in npm
npm 12 became generally available in July 2026:
- Install scripts from dependencies (
preinstall,install,postinstall) do not run by default, and neither do implicit native builds. - Git and remote URL dependencies are off by default.
- When a package really needs its script, you approve it with
npm approve-scripts --allow-scripts-pendingand commit the allowlist inpackage.json.
GitHub also added protections: important npm accounts go read-only for 72 hours after an email change or a recovery code is used, publishers can opt in to staged publishing, and Dependabot now waits 3 days by default before suggesting a brand new version.
My checklist
- Update to npm 12 and leave scripts off. Approve only the few packages that truly need them.
- Commit your lockfile and use
npm ciin CI. - Do not jump to a version released an hour ago. A few days of waiting lets others find the problem first.
- Keep real secrets out of
.envfiles on your laptop where you can. Use short lived tokens. - If you publish packages, move to trusted publishing. GitHub says tokens that bypass 2FA lose direct publishing, expected around January 2027.
None of this needs a security team. It is a one-time setup, and then the defaults protect you.
Sources:
- Install scripts from dependencies (
Your answer
Know the answer? Sign in and share it. Useful answers earn points.
Sign in to answer