DIE Community
Ask

Is npm install still safe after the 2026 supply chain attacks?

DIEAbdulHadiFounderAsked 1 viewsEdited 19 hours ago
0

The question says it all.

1 answer

  1. 0

    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 preinstall script, 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-framework package on PyPI were published with a stealer. It used a .pth file, which runs every time Python starts, even if you never import the package. It collected environment variables, .env files 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-pending and commit the allowlist in package.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

    1. Update to npm 12 and leave scripts off. Approve only the few packages that truly need them.
    2. Commit your lockfile and use npm ci in CI.
    3. Do not jump to a version released an hour ago. A few days of waiting lets others find the problem first.
    4. Keep real secrets out of .env files on your laptop where you can. Use short lived tokens.
    5. 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:

    Link

Your answer

↑ ↓ to moveEnter to open