Skip to content

Rugved Koshiya / October 25, 2026

npm supply chain attack protection: a guide

What the 2025 and 2026 npm attacks had in common, the controls that stop most of them, and what to ask whoever maintains your Node.js product.

Most of the big npm attacks of the past year didn’t exploit a bug in npm or in Node.js. Attackers stole a maintainer’s credentials, published a malicious version of a popular package, and let it run on every machine that installed it. The targets were developer laptops and CI pipelines, because that is where the secrets are.

So protecting a Node.js product comes down to three things:

  1. Slow down how quickly new package versions reach your builds.
  2. Stop packages from running code when they are installed.
  3. Limit what a stolen secret can do.

This guide explains each one, what to do when a package you use is reported compromised, and what to ask whoever maintains your product.

What is an npm supply chain attack?

An npm supply chain attack puts malicious code into a package your product depends on, so your own build installs it for you. You never chose to run the attacker’s code; it arrived as an ordinary update, often several levels down in your dependency tree.

Your product is exposed even if you never publish a package. The risk sits wherever npm install runs: on each developer’s machine, in CI, and in any build that produces what you ship.

For example, picture a small team whose CI pipeline runs a fresh install on every pull request, with a cloud deploy key in its environment. If one of those installs picks up a malicious release, the deploy key goes with it. That team is an illustration, not a real case, but it is the exact path the keyv payload was built for: it read the whole environment and the CI secrets [3].

What does a real npm supply chain attack look like?

The axios compromise of March 31, 2026 shows every step. Axios is one of the most used HTTP libraries in JavaScript, with over 100 million weekly downloads on its 1.x line [13].

  1. The account. Attackers took over the lead maintainer’s npm account and changed its email address to one they controlled [12].
  2. The release. They published axios 1.14.1 and 0.30.4 with a long-lived npm token, bypassing the project’s normal release workflow in CI [13]. The axios code itself was unchanged; the new versions only added a dependency, plain-crypto-js, that axios never uses [12].
  3. The payload. That dependency’s postinstall script ran on every machine that installed it. It downloaded a backdoor for Windows, macOS or Linux, then deleted itself and restored its own package.json to hide the traces [12].
  4. The window. The bad versions were live from 00:21 to 03:20 UTC [12], about three hours. Any laptop or CI job that resolved a fresh axios version in that time, through a new install or a lockfile update, got the backdoor.

Google’s advice to anyone affected was to treat the machine as compromised, rebuild it from a known-good state, and rotate every credential on it [12].

Each control in this guide breaks one step of that story. A release-age cooldown would have skipped a three-hour-old version. Blocking install scripts would have stopped the postinstall hook. Publishing only from CI, with no long-lived token, removes the shortcut the attackers used.

What did the recent attacks have in common?

The 2025 and 2026 attacks followed the same pattern: a stolen account, a malicious release, code that ran on install, and stolen credentials that fed the next round.

Attack How it got in What it did
chalk, debug and others, September 2025 A phishing email from a lookalike npm domain Rewrote crypto payments in browsers [14]
Shai-Hulud, September 2025 Stolen developer credentials Infected over 500 packages and stole tokens and keys [1]
axios, March 2026 A hijacked maintainer account and a long-lived token Installed a backdoor through a new dependency [12]
@redhat-cloud-services, May 2026 A malicious VS Code extension took over a GitHub account Published 32 packages with unauthorized changes [2]
keyv and related packages, August 2026 A malicious commit added a preinstall script Stole credentials and republished hundreds of packages [3]

Three things stand out:

  • Code can run at install time. In the keyv attack, a preinstall script ran the payload as soon as the package was installed [3], before any test or code review could see it.
  • Removal comes after the damage. Compromised versions were taken down once they were found [2], but anyone who had installed them was already exposed. Even fast responses leave a gap: in the chalk and debug case, roughly two hours passed before npm and the maintainers began removing the code [14].
  • The prize was credentials. The keyv payload took environment files, SSH keys, and cloud, CI and npm credentials [3]. Tokens taken from one victim were used to publish the next wave, which is why these attacks spread like worms [1][3].

Which controls stop most npm supply chain attacks?

Six controls cover most of the pattern above, and none of them needs a paid tool.

1. Commit the lockfile and install from it exactly

A lockfile records the exact version of every package, including indirect ones. Commit it, and make CI install from it without changes. npm ci exits with an error rather than updating the lockfile when it doesn’t match package.json [4]; pnpm’s equivalent is a frozen-lockfile install [5].

A lockfile alone doesn’t help if a bad version is already in it, so review changes to it like any other code.

2. Wait before adopting new versions

A release-age cooldown means a new version is only installed after it has been public for a set time. Your builds are then never among the first to install a release, which is when a compromised version is most likely to still be live.

npm, pnpm and Dependabot all support a cooldown, but only pnpm 11 turns one on by default:

Tool Setting Notes
npm min-release-age, in days [6] Off by default. min-release-age-exclude exempts named packages
pnpm minimumReleaseAge, in minutes [5] 1,440 minutes (one day) by default since pnpm 11; off in earlier versions
Dependabot Cooldown on version updates [7] Version updates wait three days; security updates don’t

The trade-off is that urgent security fixes are delayed too. Keep an exclusion list for the cases where you need a patched version the same day, and use it deliberately.

3. Don’t let dependencies run install scripts by default

This stops the kind of preinstall payload used in the keyv attack from running when the package is installed [3]. Both major package managers now block dependency install scripts unless you approve them:

  • npm 12 doesn’t run dependency install scripts unless they are allowed in the allowScripts field of package.json, and npm approve-scripts records approvals. Setting strict-allow-scripts turns a blocked script from a warning into a failed install, which suits CI [8].
  • pnpm treats any package not listed in allowBuilds as unreviewed, and with strictDepBuilds on (the default) the install fails rather than running its script [9].

A few packages genuinely need a build step, usually those with native code. Approve those by name, and treat a new approval request in a pull request as something to look at, not wave through.

4. Block dependencies that skip the registry

Dependencies pulled straight from a git repository or a tarball URL avoid the registry’s checks. In npm 12, allow-git and allow-remote default to none [8]. pnpm’s blockExoticSubdeps, on by default, allows git and URL sources only for your direct dependencies [5]. If an older setup turns these off, find out why.

5. Limit what a stolen secret can do

Assume that one day something malicious will run on a developer machine or in CI. What it can steal is what’s there.

  • Give CI jobs only the secrets they need, and keep production credentials out of jobs that install dependencies.
  • Prefer short-lived credentials to long-lived keys, in CI and on laptops.
  • Turn on phishing-resistant multi-factor authentication for GitHub and npm accounts, as CISA recommended after Shai-Hulud [1]. The chalk and debug maintainer was caught by an email from npmjs.help, a lookalike of npm’s real domain, and approved a reset of his two-factor settings [14].
  • If you publish packages, use npm trusted publishing from CI, which works without a long-lived npm token [10]. The axios attackers published with exactly that kind of token [13].

6. Check signatures and provenance

npm audit signatures checks registry signatures on installed packages and verifies their provenance attestations [11]. pnpm’s trustPolicy: no-downgrade fails an install when a package’s trust level drops compared with earlier releases, for example a version published without the provenance its predecessors had [5]. Neither catches everything, but both are cheap to add to CI.

Do you need to upgrade your package manager?

Often, yes. The safer defaults above are recent. npm 12 is the release that blocks install scripts and git and URL dependencies by default [8], and pnpm’s one-day cooldown default arrived in pnpm 11 [5]. A project pinned to an older version gets none of this unless it is configured by hand. Upgrading the package manager is a small change with a large effect; plan it like any other dependency upgrade, because blocked install scripts will break packages that need a build step until you approve them.

What should you do when a package you use is compromised?

Treat any machine that installed the bad version as exposed, and act in this order:

  1. Find out if you installed it. Search every lockfile, including nested dependencies, and any cached builds or artifact stores for the affected versions [1].
  2. Find out where it ran. List the developer machines, CI runs and builds that installed it during the window.
  3. Rotate every secret those machines could reach. That includes cloud keys, CI secrets, GitHub and npm tokens, and anything in environment files [1].
  4. Pin to a known safe version and rebuild from a clean lockfile [1].
  5. Look for anything left behind. The keyv worm wrote files to repository branches that ran when a developer opened the folder in their editor [3], so removing the package isn’t always enough.

Getting the order right matters. Rotating secrets before you know where the package ran can leave a key you missed.

What should you ask whoever maintains your product?

If an agency or contractor maintains your Node.js product, these questions show quickly whether the basics are in place:

  • Is the lockfile committed, and does CI install from it without changes?
  • Is there a release-age cooldown, and how are urgent patches handled?
  • Are dependency install scripts blocked by default? Which packages are allowed to run them, and why?
  • Which package manager version do we use, and when was it last upgraded?
  • Which secrets can a CI job that installs dependencies reach?
  • Who would tell us if a package we depend on was compromised, and how fast?

Good answers are short and specific. If the answer to most of them is “we’d have to check”, that is your answer.

Most of these controls live in the build pipeline, which is what Grey Time Labs’ DevOps and platform engineering service sets up, and regular security patching is part of cloud operations. For the application itself, see our backend and API development service.

Common questions

Does npm audit catch malicious packages?

Only after they are reported. npm audit checks your dependencies against published advisories, so a new malicious version isn’t flagged until someone has found it and filed it. That gap is why the cooldown and install-script controls matter.

How do I check whether we installed a compromised version?

Search every lockfile for the exact versions named in the advisory, including nested dependencies, and check build caches and artifact stores too [1]. For axios, Google’s advice was to look for axios 1.14.1 or 0.30.4 and for plain-crypto-js anywhere in the tree [12]. If you find one, follow the response steps above and treat the machine as compromised.

Will a cooldown delay security fixes?

Yes, unless you exempt them. npm and pnpm both let you exclude named packages from the cooldown [5][6], and GitHub says Dependabot’s cooldown applies to version updates, not security updates [7].

Do we need to switch package managers?

No. npm and pnpm both offer the controls in this guide [5][6][8][9]. Upgrading the one you already use and setting it up properly is usually the smaller change.

Does this matter if our product isn’t open source?

Yes. A private product installs the same public packages as everyone else, so it is exposed in the same way.

If you’d like a second opinion on how your Node.js product handles its dependencies, tell us about the project.

Sources

  1. Widespread Supply Chain Compromise Impacting npm Ecosystem, CISA, September 23, 2025.
  2. RHSB-2026-006: Supply chain compromise of @redhat-cloud-services npm packages, Red Hat.
  3. Worm compromises popular npm packages, Datadog Security Labs, August 2026.
  4. npm ci, npm Docs.
  5. Dependency resolution settings and settings reference, pnpm.
  6. npm config: min-release-age, npm Docs.
  7. Disrupting supply chain attacks on npm and GitHub Actions, GitHub Blog, July 28, 2026.
  8. npm 12 config: allow-scripts, allow-git, allow-remote, strict-allow-scripts, npm Docs.
  9. Build settings, pnpm.
  10. Trusted publishing for npm packages, npm Docs.
  11. npm audit, npm Docs.
  12. North Korea-nexus actor compromises axios npm package, Google Threat Intelligence Group, April 1, 2026.
  13. Frequently asked questions about the axios npm supply chain attack, Tenable.
  14. Dev falls for phishing email, npm packages with billions of weekly downloads compromised, The Register, September 8, 2025.

Ideas Engineered At Scale

Have something to build?

Tell us what you are working on. We will reply with questions, not a sales pitch.