🕑 Estimated reading time: 4 minutes | Last updated: May 8, 2026
On 15 September 2025, malicious versions of popular npm packages began spreading a worm dubbed Shai-Hulud. Its install script harvested secrets such as npm tokens, GitHub tokens and cloud keys, published them to public repositories, and used stolen npm tokens to push infected versions of other packages, making it the first widely reported self-propagating attack in the npm ecosystem. A second wave followed later in 2025. Defences include pinning dependencies, using lockfiles, delaying adoption of brand-new versions, disabling install scripts where possible, short-lived tokens and secret scanning.

Modern JavaScript applications are built from hundreds, sometimes thousands, of open-source packages pulled from the npm registry. Developers install them in seconds with a single command. That convenience is also a risk: if one widely used package is poisoned, the malware can reach thousands of projects almost instantly. In September 2025, the npm ecosystem saw a nightmare version of that scenario, a worm that spread itself.
Table of Contents
What Shai-Hulud Did
On 15 September 2025, security researchers spotted malicious versions of popular npm packages. Named after the giant sandworms in Dune, the malware, “Shai-Hulud,” ran when a developer or build system installed an infected package:
- A post-install script searched the machine for secrets, using a legitimate secret-scanning tool, and collected environment variables and cloud credentials.
- If it found GitHub tokens, it created public repositories named “Shai-Hulud” containing the stolen secrets, and in some cases made private repositories public.
- It added malicious GitHub Actions workflows to repositories to exfiltrate more secrets.
- Most alarmingly, if it found npm publishing tokens, it automatically published infected versions of other packages that the token could access, spreading itself further.
Security firms described it as the first successful self-propagating attack in the npm ecosystem. Hundreds of package versions were affected before npm and GitHub responded, and a further wave, often called Shai-Hulud 2.0, appeared later in 2025. Earlier that summer, attackers had also compromised other widely used packages and the Nx build system, showing a sustained campaign against developer tooling.
Why Developers Are Prime Targets
- Developer machines and build pipelines hold powerful secrets: cloud keys, deployment credentials and publishing tokens.
- Install scripts run automatically with the developer’s permissions.
- Many projects automatically pick up new minor versions of dependencies.
- Open-source maintainers are often volunteers with limited security resources, and their accounts are attractive targets for phishing.
How to Protect Your Projects
Control what you install
- Use lockfiles and commit them, so builds use exact, known versions.
- Pin versions for critical dependencies and review upgrades rather than accepting them automatically.
- Add a cooling-off period: avoid adopting package versions published only hours ago; many malicious versions are caught within a day or two.
- Use a private registry or proxy that can block known-bad packages.
Limit what packages can do
- Disable lifecycle scripts by default where your tooling allows, enabling them only for packages that genuinely need them.
- Run installs and builds in isolated, ephemeral environments without access to production secrets.
Protect your secrets
- Use short-lived, narrowly scoped tokens, such as trusted publishing with OIDC for npm and cloud credentials issued per build.
- Never store long-lived secrets in environment variables on developer laptops if you can avoid it; use a secrets manager.
- Enable secret scanning and push protection on your repositories.
Protect maintainer accounts
- Require phishing-resistant MFA for npm and GitHub accounts.
- Be wary of emails claiming you must “update MFA” on the registry; phishing of maintainers has preceded several compromises.
Detect and respond
- Monitor dependencies with software composition analysis tools and subscribe to security advisories.
- Keep a software bill of materials so you can quickly check exposure.
- If you installed an affected version, assume secrets on that machine are compromised: rotate npm, GitHub and cloud tokens, check for unexpected repositories or workflows, and review audit logs.
How the Ecosystem Is Responding
GitHub, which runs npm, announced plans after the attacks to tighten publishing security, including shorter-lived tokens, broader MFA requirements and wider use of trusted publishing. Regulations are pushing in the same direction: the EU Cyber Resilience Act will require commercial software makers to manage vulnerabilities in the open-source components they ship.
Review dependency updates before they reach production
Shai-Hulud proved that a supply chain attack can spread on its own. Every team that uses open source, which is virtually every team, should treat dependency installation as a security-sensitive operation: pin versions, slow down upgrades, isolate builds and keep secrets short-lived. Those habits turn a worm outbreak from a crisis into a manageable incident.
Frequently Asked Questions
Do I need to stop using npm?
No. Open source is essential; the goal is to consume it more safely.
How do I know if I was affected?
Check your lockfiles and build logs against published lists of compromised versions, and look for unexpected repositories, workflows or token activity.
Does this only affect JavaScript?
Similar attacks have targeted Python, Ruby and other package ecosystems; the defences are much the same.