npm is safer than it was in 2025, but it is not safe by default. After the Shai-Hulud worm compromised more than 500 packages in September 2025 and later waves hit axios, TanStack, and keyv, npm revoked all classic tokens, made two-factor authentication the default, and pushed trusted publishing. You can use npm safely if you pin dependencies, block install scripts, and audit your lockfile — but blindly running npm install remains risky.
Key takeaways
- The attacks abused maintainer accounts and CI pipelines, not bugs in your code — one poisoned publish could reach millions of installs.
- npm revoked every classic token on December 9, 2025, and now defaults new packages to two-factor authentication.
- Pin your lockfile, block install scripts, and delay new releases a few days — those three habits stop most of what the worms relied on.
In September 2025, a worm called Shai-Hulud started spreading through npm — not by exploiting your code, but by publishing poisoned versions of packages you already trusted. The waves kept coming into 2026. So is npm safe now? The honest answer is: safer than it was, but not safe by default.
Is npm safe to use right now?
Yes, with controls in place — and no, if you install packages blindly. npm has made the biggest security changes in its history since the attacks began: long-lived tokens are gone, two-factor authentication is now the default, and publishing through CI uses short-lived credentials instead of stored secrets.
But the attacks did not stop. New waves hit major packages through 2026, including axios, TanStack, and the keyv family of caching libraries, and several of those poisoned releases carried valid provenance — the cryptographic proof that a package came from its real repository. That means the old advice to "check the signature" is no longer enough on its own.
The right way to think about it: npm is a public registry where anyone can publish, and a compromised maintainer account can push a malicious version of a package with millions of weekly downloads. Your safety comes from what you do on your side — pinning, delaying, and blocking install scripts — not from trusting the registry alone.
What happened in the recent npm supply chain attacks?
The attacks came in waves from mid-2025 through 2026, each one finding a different way in. The first Shai-Hulud wave in September 2025 compromised more than 500 packages, a second wave followed in November, and further waves hit new packages through 2026.
| Incident | When | How it got in | Scale |
|---|---|---|---|
| Shai-Hulud wave 1 | Sep 2025 | Compromised maintainer accounts; self-propagating worm | 500+ packages |
| debug / chalk phishing | Sep 2025 | Phishing against maintainers | 2B+ weekly downloads affected |
| Shai-Hulud 2.0 | Nov 2025 | Same worm, timed before token revocation | About 700 packages |
| axios | Mar 2026 | Compromised maintainer account | Versions 1.14.1 and 0.30.4 |
| TanStack | May 2026 | CI pipeline and trusted publishing abuse | 84 versions across 42 packages |
| keyv family | Aug 2026 | Compromised maintainer GitHub account | 444 packages, 1,381 versions |
The pattern matters more than any single incident. Each wave got in through a different door — a phished maintainer, a misconfigured CI workflow, a compromised GitHub account — so no single fix closes them all.
The August 2026 keyv attack is a good example of the shape: attackers compromised the maintainer's GitHub account, pushed malicious files to the main branch, cut a new release, and the poisoned versions shipped with valid provenance, as Aikido's published analysis documents.
How did the attacks actually work?
Almost every wave followed the same three moves: steal publishing access, ship a malicious version that runs at install time, and use the victim's own credentials to spread further. Understanding the moves tells you which defenses matter.
Move 1: get publish rights. Attackers phished maintainers, stole tokens from developer machines and CI runners, or abused a CI workflow that ran untrusted input. In the TanStack case, researchers reported the publish went through the project's own trusted-publisher setup, with no npm token stolen at all.
Move 2: run code at install time. The poisoned package added a preinstall or postinstall script to package.json. Anyone who ran npm install against the affected version executed that script automatically, before importing anything. In the keyv wave, the script downloaded the Bun runtime and ran a 728 KB obfuscated payload.
Move 3: harvest and spread. The payload scanned the machine for npm tokens, GitHub tokens, AWS keys, Kubernetes service account files, Vault tokens, SSH keys, Stripe and Slack tokens, and .env files — then encrypted the haul and uploaded it to a public GitHub repository.
It then used the stolen npm token to republish the victim's own packages with the worm inside. That is why one compromise became hundreds within days.
Note what the payload did not need: a bug in your code, a vulnerability in the package's features, or your permission. Installing was enough. That is also why the phishing angle matters — several waves began with a maintainer clicking a phishing message, the same attack our spear phishing guide describes.
What did npm and GitHub change in response?
npm and GitHub responded in stages through late 2025, and the changes are real. The most important one landed on December 9, 2025: npm permanently revoked all existing classic tokens, which could no longer authenticate, be recreated, or be recovered.
- Classic tokens are gone.
npm loginnow issues a two-hour session token instead of a long-lived one, and two-factor authentication is enforced for publishing during the session. - Granular tokens are short-lived. New write-enabled granular tokens default to a seven-day expiry, with a 90-day maximum, and can be created, listed, and revoked from the CLI with
npm token. - 2FA is the default. Two-factor authentication is now enabled by default for all newly created packages, and new TOTP setups for npm access were disabled to close bypass routes.
- Trusted publishing is the recommended path. CI workflows should publish with OpenID Connect instead of stored tokens, which eliminates the long-lived secret the worms stole.
GitHub also announced short-lived tokens and stronger two-factor requirements after the first waves. And CISA's advisory on the Shai-Hulud compromise told organizations to review lockfiles, pin dependencies to known-safe releases, rotate developer credentials, and use phishing-resistant multi-factor authentication. You can read the token changes in GitHub's December 2025 changelog.
These changes raise the cost of the old attacks considerably. They do not end the problem: the 2026 waves showed attackers adapting to trusted publishing itself, by compromising the CI pipeline that the trust is anchored to.
How do you check if your project was affected?
Do this now if your team installs JavaScript dependencies, even if nothing looks wrong. The payloads in these attacks were silent — they stole credentials and left no visible trace on the machine.
- Check your lockfile. Search package-lock.json for the affected versions named in the published lists, such as the keyv family versions from August 2026, axios 1.14.1 and 0.30.4, and the TanStack versions from May 2026. Any match means the install ran the payload.
- Check your install dates. If CI installed dependencies during a known compromise window — for example, the first days after a poisoned version was published — assume exposure even if the version was later removed.
- Run npm audit and review the output, but do not stop there: audit only knows about reported vulnerabilities, and a fresh malicious version may not be listed yet.
- Look for the indicators. Aikido published hashes and network indicators for the keyv wave, including the setup.mjs file and the npm-cache.com exfiltration domain. Check your CI logs for unexpected network calls during installs.
- Rotate secrets. If any machine or CI job ran an affected version, rotate every secret that job could see: npm and GitHub tokens, cloud keys, SSH keys, and deployment credentials. CISA's advisory on the Shai-Hulud compromise urged organizations to rotate developer credentials.
How do you protect your project going forward?
There is no single setting that makes npm safe. The defense is a short list of habits, and the first three stop most of what the worms relied on.
Pin your lockfile. Commit package-lock.json and install with npm ci, which installs exactly what the lockfile says. A floating install can pull a poisoned version published minutes ago; a pinned one cannot.
Block install scripts. Set ignore-scripts=true in your .npmrc or CI config. This was CISA's recommendation after the axios compromise, and it stops the preinstall and postinstall hooks that every one of these worms used. If a package genuinely needs a build step, run it explicitly and review it first.
Delay new releases. Set min-release-age to a few days so your installs skip versions published very recently. Poisoned versions are usually pulled within hours; a delay means someone else finds them first.
Publish with trusted publishing. If you maintain a package, configure OIDC trusted publishing and remove stored npm tokens from CI entirely. Then protect the workflow itself: require review for changes to release workflows, pin your GitHub Actions to commit SHAs, and never run untrusted input in a workflow that can publish.
Limit what CI can see. Give install jobs no secrets at all, and keep publishing in a separate job with minimal permissions. Turn on secret scanning and push protection so a leaked token is caught before it is used. For a wider view of what your organization exposes, see our attack surface management platform.
Should you switch away from npm?
For most teams, switching registries is the wrong response. The attacks targeted the publishing and account layer — phished maintainers, stolen tokens, abused CI — which every registry shares in some form. Moving to another registry without fixing your lockfile, install scripts, and secret handling would move the same risk somewhere else.
What is worth considering is a private registry or proxy for production builds: a mirror that only serves versions you have approved, with new versions held for review. That is a bigger investment, and it makes sense for larger teams or regulated work, not for a side project.
Also worth doing is reducing your dependency count. Every package you install is code you run with full access to your machine at install time. Audit your tree, remove what you do not use, and prefer well-maintained packages with multiple active maintainers over single-maintainer utilities for critical paths.
The bottom line
npm in late 2026 is meaningfully safer than npm in mid-2025: the long-lived tokens the worms stole are gone, two-factor authentication is the default, and trusted publishing removes stored secrets from CI. But the 2026 waves proved that attackers adapt, and several poisoned releases carried valid provenance.
So use npm — but use it like a public registry that can publish a bad version at any moment. Pin your lockfile, block install scripts, delay new releases, and rotate secrets the moment you suspect exposure. That combination is what stands between your team and the next wave, and you can start with the Cysoro attack surface platform to see what your organization exposes today.
Frequently asked questions
Is npm safe to use in 2026?
Yes, with controls. npm revoked all long-lived classic tokens in December 2025, made two-factor authentication the default for new packages, and promotes trusted publishing. But waves of attacks continued into 2026, so you should pin your lockfile, block install scripts, and audit dependencies rather than trusting every install.
What was the Shai-Hulud npm attack?
Shai-Hulud was a self-replicating npm worm first seen in September 2025. It hid in trusted packages, ran at install time, harvested developer credentials with a tool called TruffleHog, published the stolen secrets to a public GitHub repository, and used stolen npm tokens to republish other packages with itself inside. CISA counted more than 500 compromised packages in the first wave.
How do I check if my project used a compromised npm package?
Check your lockfile against the published lists of affected versions, run npm audit, and look for unexpected versions of packages you depend on. If your CI installed a package during a known compromise window, treat every secret that job could see as exposed and rotate it.
What is npm trusted publishing?
Trusted publishing lets a CI workflow publish a package using OpenID Connect instead of a stored token. You register the repository and workflow as a trusted publisher, and npm issues a short-lived credential for that single publish. It removes the long-lived token that worms like Shai-Hulud stole and reused.
Should I stop using npm and switch to another registry?
For most teams, no. The attacks targeted the publishing and account layer, which every registry shares in some form, and npm has made the biggest hardening changes. Switching registries without fixing your lockfile, install scripts, and secret handling would move the same risk somewhere else.
What does npm audit actually catch?
npm audit checks your dependency tree against a database of known vulnerabilities and reports them by severity. It does not catch a freshly published malicious version that has not been reported yet, which is why it is a backstop, not a defense on its own. Pair it with lockfile pinning and install-script blocking.
Do I need to rotate secrets after an npm supply chain attack?
Yes, if your machine or CI ran an affected version. The payloads in these attacks harvested npm tokens, GitHub tokens, cloud keys, SSH keys, and environment variables, then exfiltrated them. CISA urged organizations to rotate all developer credentials that could have been exposed after Shai-Hulud.
Sources
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.
Checked against GitHub's npm security changelogs, CISA's Shai-Hulud advisory of 23 September 2025, and Aikido's published analysis of the August 2026 keyv compromise.
How we write and fact-check →