← Back to blog

Nov 1, 2026 · 9 min read

The Shai-Hulud Worm: How 500+ npm Packages Got Compromised

In September 2025, a self-replicating worm spread through npm, stealing credentials and republishing infected packages. Here's what happened, how it worked, and what your team should do about it.

SecurityNode.jsSupply Chain

On September 15, 2025, an engineer noticed something wrong with a popular npm package called @ctrl/tinycolor. It had over two million weekly downloads. The package's latest version contained a 3.7 MB obfuscated JavaScript file called bundle.js that ran automatically during installation.

That file was a worm. It stole credentials, exfiltrated them to a GitHub repository, and then used those stolen credentials to infect other packages by the same maintainer. Within 24 hours, at least 200 packages were compromised. By the time CISA published their advisory a week later, the number had passed 500.

Security researchers named it Shai-Hulud, after the sandworm in Dune. The name fits. It spread under the surface, quietly, and by the time anyone noticed, it had already burrowed into hundreds of dependency trees.

How the worm worked

The attack had three stages, and each one fed the next.

Stage 1: Initial access. The worm started by compromising a maintainer's npm credentials. Unit 42's later investigation suggested this may have come from a phishing campaign that spoofed npm's MFA login page. Once the attacker had a valid npm token, they could publish new versions of any package that maintainer owned.

Stage 2: Credential harvesting. When someone installed an infected package, the postinstall script ran bundle.js. That script scanned the local environment for credentials: .npmrc files, environment variables, GitHub Personal Access Tokens, AWS keys, GCP keys, Azure keys. Anything it found got exfiltrated to an attacker-controlled endpoint and also uploaded to a public GitHub repository called "Shai-Hulud" under the victim's own account.

Stage 3: Self-propagation. Using the stolen npm token, the worm called getPackagesByMaintainer() to find every other package the compromised developer maintained. It downloaded each one, injected bundle.js into the postinstall script, republished the infected version, and moved on. The whole process was automated. No human intervention needed.

This is what made Shai-Hulud different from every npm attack before it. Previous supply chain compromises were one-shot events: an attacker publishes a malicious package, people install it, the attacker moves on. Shai-Hulud replicated. Each new victim became a new vector.

What made it spread so fast

A few things lined up to make this worse than it should have been.

npm's install model runs arbitrary code by default. When you run npm install, any package can include a postinstall script that executes with your full system permissions. This has been a known risk for years, but the ecosystem has resisted changing it because so many legitimate packages depend on build scripts.

Maintainer credentials are high-value targets. One compromised npm account can infect every package that account owns, and every project that depends on those packages, and every project that depends on those, and so on. The blast radius of a single stolen token is enormous.

Dependency trees are deep and opaque. Most teams don't know what's in their node_modules. A typical Next.js project has hundreds of transitive dependencies. When one of them turns malicious, the surface area is already there, waiting.

By November 2025, a second wave dubbed "Shai-Hulud 2.0" had spread to over 25,000 GitHub repositories across roughly 350 unique users. Unit 42 noted that the bash scripts in the second wave contained comments and emojis consistent with LLM-assisted writing. The attacker was apparently using AI to help write the malware.

What your team should do

If you're running Node.js in production, treat this as a wake-up call, not a one-time incident. The structural problems that made Shai-Hulud possible are still there.

Pin your dependencies. Use package-lock.json or pnpm-lock.yaml and commit it. Pin to specific versions, not ranges. If a maintainer's account gets compromised tomorrow, your lockfile prevents the malicious version from being installed until you explicitly update.

Audit your install scripts. Run npm config set ignore-scripts true in CI and see what breaks. If something legitimately needs a postinstall script, document why and scope it as tightly as possible.

Rotate credentials. If you have GitHub PATs, npm tokens, or cloud API keys that have been sitting in CI for months, rotate them now. Assume they've been seen.

Turn on MFA. Phishing-resistant MFA on npm and GitHub accounts is the single most effective control against this class of attack. Shai-Hulud's initial access came from stolen credentials, not a software vulnerability.

Use a dependency scanner. Tools like Socket, Snyk, or Endor Labs can flag packages with suspicious install scripts or sudden version jumps. They're not perfect, but they catch the obvious cases.

The bigger picture

Shai-Hulud is not the last worm. The npm ecosystem has 17 million packages and over a trillion downloads. The incentives for attacking it are only going up. The defenses that worked in 2023 (basic dependency hygiene, occasional audits) are not enough anymore.

The teams that weathered this attack well were the ones who had already locked their dependencies, rotated their credentials regularly, and treated their supply chain as part of their security perimeter. The ones who got hurt were running npm install with floating version ranges and a CI pipeline full of tokens that hadn't been rotated in two years.

If that sounds like your setup, fix it this week. Not next quarter.

Need help applying this?

Schedule call →