Security operations

How to Protect Against npm Supply Chain Attacks (2026 Guide)

The 2026 axios compromise showed that one hijacked maintainer account can poison millions of installs. Here is how to protect your projects, step by step.

Cysoro Security TeamPublished · 7 min read
$ npm ci✓ lockfile verified✓ 0 install scripts run! axios 1.14.1 blockedignore-scripts=true$ npm audit signatures✓ provenance verified SECURITY OPERATIONS npm supplychain Stop poisoned packages.
Quick answer

Protect against npm supply chain attacks by committing your lockfile and installing with npm ci, disabling install scripts with ignore-scripts=true, pinning exact versions, verifying provenance with npm audit signatures, and scanning every pull request with npm audit. In CI, use short-lived tokens, a private registry proxy and a release cooldown so newly published malicious versions cannot reach your builds.

Key takeaways

  • Commit your lockfile and install with npm ci so a newly published malicious version cannot slip into your builds.
  • Disable install scripts by default with ignore-scripts=true, because most 2026 npm attacks ran code at install time.
  • The axios attack of 31 March 2026 poisoned versions 1.14.1 and 0.30.4 through a hijacked maintainer account, not through a code flaw.

On 31 March 2026, attackers hijacked the npm account of the axios maintainer and published two poisoned versions of one of the most downloaded packages in the world. Anyone who installed them ran a remote access trojan before a single line of application code executed. This guide explains how that attack worked — and the layered defenses that stop the next one.

What is an npm supply chain attack?

An npm supply chain attack poisons a package that other projects depend on, so that installing the package runs malicious code. Instead of breaking into your application, the attacker breaks into something your application is built from.

Most attacks use one of four techniques: hijacking a maintainer's account and publishing a malicious version, typosquatting a look-alike package name, adding a malicious dependency with an install script, or compromising a build pipeline so the published package differs from the reviewed source. The axios case used the first and third together.

The damage is amplified by automation. A single `npm install` in CI can pull hundreds of transitive dependencies, and a version range such as `^1.14.0` can resolve to a newly published malicious version without anyone approving it.

What happened in the axios supply chain attack?

On 31 March 2026, attackers used the hijacked npm account of axios's lead maintainer to publish axios 1.14.1 and 0.30.4. Neither version changed a line of axios itself. Each added one new dependency, `plain-crypto-js`, whose install script downloaded a remote access trojan.

Axios is an HTTP client with over 100 million weekly downloads, so the exposure was enormous. The malicious versions were live on npm from 00:21 to 03:15 UTC — about three hours — but any fresh install or auto-update in that window could have pulled them. The malware targeted Windows, macOS and Linux with platform-specific payloads, stole cloud keys, database passwords and API tokens, and installed a remote access trojan for persistent access.

GitHub published the incident as malware advisory GHSA-fw8c-xr5c-95f9, listing affected versions 1.14.1 and 0.30.4 and warning that any computer with the package installed should be considered fully compromised, with all secrets rotated immediately from a different computer. Safe versions are 1.14.0 and 0.30.3.

Axios attack timeline — 31 March 2026 00:21 UTCMalicious axios1.14.1 and 0.30.4published to npmvia hijacked account Install timeplain-crypto-jspostinstall scriptdownloads RAT,steals secrets ~03:15 UTCnpm removes bothversions; GitHubpublishes advisoryGHSA-fw8c-xr5c-95f9 AftermathSafe versions:1.14.0 / 0.30.3Rotate all secretsfrom another machine The malicious versions were live for about three hours. Lockfiles and disabled install scripts blocked them.
Timeline of the axios npm supply chain attack, 31 March 2026. Illustration by Cysoro.

SANS analysis noted that the attacker pre-staged the malicious dependency about 18 hours before publishing the poisoned versions, and that organizations with lockfiles pinning axios to a specific version, or CI policies that suppress automatic install scripts, were protected. The window of exposure was measured in hours; the consequences took weeks to assess.

How do npm supply chain attacks work?

Most npm supply chain attacks combine a few techniques. Knowing them helps you see which defense blocks which one.

TechniqueHow it worksWhat stops it
Maintainer account hijackAttacker takes over a maintainer's npm account and publishes a malicious versionProvenance checks, release cooldown, lockfiles
Malicious dependencyA new dependency is added whose only job is to run an install scriptDisable install scripts, review lockfile diffs
TyposquattingA look-alike package name tricks developers into installing the wrong packagePrivate registry proxy, allowlists, code review
Compromised build pipelineThe published package differs from the reviewed source codeProvenance attestations, reproducible builds
Dependency confusionA public package with the same name as a private one is resolved firstScoped registries, private registry proxy

The common thread is trust and automation: trusted maintainers, trusted tools and automatic installs. Every defense in this guide either removes a piece of blind trust or slows automation down enough for a check to happen.

How do I protect my project? The 30-minute checklist

There is no single fix, so the goal is layered defense. Work through these eight steps in order — the first three alone would have blocked the axios attack for most projects.

Eight defenses, in order of impact 1. Commit lockfile + npm ci 2. Disable install scripts 3. Review lockfile diffs 4. Add a release cooldown 5. Verify provenance 6. Run npm audit in CI 7. Use a private registry 8. Harden CI tokens
Layered defenses against npm supply chain attacks — each layer catches what the one above misses. Illustration by Cysoro.

1. Commit your lockfile and install with npm ci

Your `package-lock.json` records the exact version and integrity hash of every dependency, including transitive ones. Installing from it with `npm ci` means a newly published malicious version cannot silently slip in, and the install fails if `package.json` and the lockfile disagree.

Commit the lockfile to version control and treat lockfile changes in a pull request as code changes. A new, unfamiliar transitive dependency — like `plain-crypto-js` appearing under axios — is a red flag worth a human review.

2. Disable install scripts by default

Most 2026 npm attacks relied on `preinstall` or `postinstall` scripts. Set `ignore-scripts=true` in `.npmrc` so dependency scripts never run during install. Some packages genuinely need build scripts, such as native modules — run their scripts explicitly after install, for example with `npm rebuild`, or approve them one by one.

This single setting would have stopped the axios payload from executing, because the malware ran inside the `plain-crypto-js` postinstall script during `npm install`, before any application code ran.

3. Review lockfile diffs in every pull request

Automated dependency updates are convenient and dangerous. Require a human to review lockfile changes, and use a tool that flags new dependencies, removed dependencies and version jumps. Pay special attention to new packages with few downloads, recent creation dates or names similar to well-known libraries.

4. Add a release cooldown

Malicious versions are usually caught within hours — the axios versions were live for about three hours. If your package manager refuses versions newer than a day or two, you skip most of that window. npm, pnpm and Yarn all support release-date filtering in different ways; configure it in your registry proxy or CI policy.

5. Verify provenance and signatures

Provenance is a signed attestation linking a published package to the source repository and build that produced it. Run `npm audit signatures` to verify registry signatures and provenance attestations for your dependencies, and prefer packages that publish provenance. A hijacked-account publish without the project's normal build attestation is easier to spot.

6. Run npm audit on every pull request

npm audit submits your dependency tree to the registry and reports known vulnerabilities with remediation advice. Run it in CI with a failure threshold such as `--audit-level=moderate`, and run `npm audit fix` only after review — it runs a full install under the hood, so it can itself change what gets installed.

7. Mirror packages through a private registry

A private registry proxy caches the packages you use and lets you allowlist them. New packages and new versions only enter your builds after approval, which blocks typosquatting and dependency confusion. It also keeps your builds working if the public registry has an outage.

8. Harden CI tokens and runners

Use short-lived, scoped tokens for publishing and installing, never long-lived npm tokens in CI. Run builds in isolated, ephemeral runners, and never let a build job read production secrets it does not need. The axios attack's follow-on risk was credential theft: any secret a compromised build could read had to be treated as exposed.

What should I do if I installed a malicious package?

Act fast and assume the worst. The GitHub advisory for axios is blunt: any computer with the package installed should be considered fully compromised, and removing the package does not guarantee the malware is gone.

  1. Check lockfiles for axios 1.14.1 or 0.30.4, or any reference to `plain-crypto-js`. If present, the malicious package was installed.
  2. Downgrade immediately to axios 1.14.0 (or 0.30.3 for legacy users) and delete the `node_modules/plain-crypto-js` directory.
  3. Rotate every secret the machine could read — npm tokens, cloud keys, SSH keys, database credentials and API tokens — from a different, clean computer.
  4. Check for persistence: review shell profiles (`.bashrc`, `.zshrc`) for unauthorized changes, and look for the RAT artifacts SANS lists, such as `%PROGRAMDATA%\wt.exe` on Windows or `/tmp/ld.py` on Linux.
  5. Scope the investigation to CI runners and build infrastructure, not just developer laptops. Automated pipelines that installed the affected versions may have exposed production secrets.
Rotate secrets from a clean machineIf a malicious package ran on your laptop, do not rotate secrets from that laptop. Use a different, clean computer — the compromised machine may still be under the attacker's control.

What mistakes make npm attacks worse?

Four mistakes turn a small incident into a large one. First, running `npm install` with floating version ranges in CI, so every build can pull a brand-new version. Second, committing no lockfile, so nobody can tell what was actually installed.

Third, letting builds run with broad secrets — a test job that can read production cloud keys turns a package compromise into a cloud compromise. Fourth, ignoring install scripts: if you never set `ignore-scripts=true`, every dependency you add gets to run arbitrary code on your machine at install time.

Fix these four and you have removed most of the attack surface. The remaining risk is real but much smaller, and it is the risk that provenance checks, audits and private registries are designed to catch. Keep the rest of your security baseline tight too — our small business cybersecurity checklist covers patching, backups and access control alongside dependency hygiene.

The bottom line

npm supply chain attacks work because developers trust packages and automate installs. The axios attack of 31 March 2026 showed how fast that trust can be weaponized: three hours on the registry, and every fresh install in that window ran a trojan.

Protect yourself with layers: commit your lockfile, install with `npm ci`, disable install scripts, verify provenance, audit every pull request and harden your CI tokens. Lock down the accounts those tokens protect as well — see how to secure your Wi-Fi for the network basics.

Finally, check whether your credentials have appeared in breaches with our free pwned password checker — and rotate anything that was on a machine that installed a malicious package.

Frequently asked questions

What is an npm supply chain attack?

An npm supply chain attack poisons a package that other projects depend on, so installing it runs malicious code. Attackers do this by hijacking a maintainer account, publishing a look-alike package, or adding a malicious dependency with an install script.

How do I know if my project was affected by the axios attack?

Check your lockfile for axios 1.14.1 or 0.30.4, or for any reference to plain-crypto-js. If either is present and was installed between 00:21 and 03:15 UTC on 31 March 2026, treat the machine as compromised and rotate every secret it could read.

Does npm audit protect against supply chain attacks?

Partly. npm audit reports known vulnerabilities in your dependencies, and npm audit signatures verifies registry signatures and provenance. It cannot catch a brand-new malicious version that has no advisory yet, which is why lockfiles and install script controls matter too.

Should I disable install scripts in npm?

Yes, by default. Set ignore-scripts=true in .npmrc, then explicitly allow the scripts of packages you trust. Most 2026 npm attacks relied on preinstall or postinstall scripts to run malware during installation.

What is a lockfile and why does it protect me?

A lockfile such as package-lock.json records the exact version and integrity hash of every dependency. Installing from it with npm ci means a newly published malicious version cannot silently replace the version you tested.

What is npm provenance and should I check it?

Provenance is a signed attestation linking a published package to the source repository and build that produced it. Check it with npm audit signatures, and prefer packages that publish provenance, because it makes a hijacked-account publish easier to spot.

How do I protect CI pipelines from npm supply chain attacks?

Use npm ci from a committed lockfile, disable install scripts, use short-lived tokens, run builds in isolated runners, and mirror packages through a private registry proxy. Never let CI install with floating version ranges.

What should I do if I installed a malicious npm package?

Treat the machine as fully compromised. Remove the package, rotate every secret the machine could read from a different computer, check for persistence such as modified shell profiles, and review your CI runners and build infrastructure, not just your laptop.

Sources

  1. SANS — Axios NPM Supply Chain Compromise
  2. GitHub Advisory Database — Malware in axios (GHSA-fw8c-xr5c-95f9)
  3. npm Docs — npm-audit
  4. CISA — Software Supply Chain Security
  5. OWASP — Software Supply Chain Security
Written & fact-checked byCysoro Security Team

The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.

  • Email authentication
  • Phishing & BEC
  • Domain & DNS security
  • Small-business security

Checked against the SANS axios analysis, GitHub advisory GHSA-fw8c-xr5c-95f9, npm audit documentation and CISA supply chain guidance.

How we write and fact-check →

Free tools for this topic

No account needed.

See where your domain stands

Free for up to 3 domains. No card, no installs.

Start free