Security operations

npm Supply Chain Attack Explained: Shai-Hulud, Chalk and How to Stay Safe

In September 2025 a self-replicating worm turned trusted npm packages into credential thieves. Here is how npm supply chain attacks work and how to defend your builds.

Cysoro Security TeamPublished · 10 min read
$ npm install + @ctrl/[email protected] ! postinstall: bundle.js ! token harvested 500+ packages hit npm SECURITY OPERATIONS npm supplychain attack One install. Hundreds of victims.
Quick answer

An npm supply chain attack compromises a JavaScript package in the npm registry so that installing or updating it runs malicious code on developer machines and build servers. The Shai-Hulud worm of September 2025 did this at scale, stealing npm, GitHub and cloud credentials and using them to infect more packages. Defense means lockfiles, pinned versions, short-lived publish tokens and scanning dependencies before they run.

Key takeaways

  • Shai-Hulud spread by stealing npm publish tokens at install time and using them to infect the victim's other packages.
  • CISA reported more than 500 compromised packages in September 2025 and urged teams to pin versions and rotate credentials.
  • Lockfiles, trusted publishing, install-script controls and dependency scanning are the practical defenses for most teams.

You did not click a phishing link. You did not download a strange file. You ran npm install on a project you have built a hundred times — and a package you trusted ran code that stole your credentials. That is an npm supply chain attack, and in September 2025 it happened at a scale the JavaScript ecosystem had never seen.

What is an npm supply chain attack?

An npm supply chain attack compromises a JavaScript package in the npm registry, or the account that publishes it, so that installing or updating the package runs malicious code on your machine or build server.

npm is the default package registry for JavaScript and TypeScript. Almost every modern web app, API and command-line tool pulls in dozens or hundreds of packages, and each of those pulls in more. A single compromised package can therefore reach thousands of projects within hours of being published.

Attackers reach packages in a few ways: phishing a maintainer's npm account, stealing a publish token from a laptop or CI runner, taking over an abandoned package, or publishing a look-alike package with a name one letter away from a popular one. The last trick is called typosquatting.

Once the malicious version is live, the damage is automatic. Developers and CI pipelines install it as part of a routine update, and the payload runs with the same access as the build itself.

How does an npm supply chain attack work?

Most npm attacks follow the same chain: get publish access, ship a malicious version, run code at install time, then steal credentials or tamper with the build.

How an npm supply chain attack unfolds 1 Compromise phish a maintainer or steal a token 2 Ship the payload publish a malicious version of the package 3 Run at install install scripts run automatically 4 Steal and spread harvest secrets, then infect more packages The install step is the weak point: code runs before you ever use the package.
The four stages of an npm supply chain attack. Illustration by Cysoro.

The install step is what makes npm attacks so effective. npm packages can include preinstall and postinstall scripts that run automatically when the package is installed. A worm hides its payload in one of those scripts, so the victim only has to install a trusted package.

What the payload does next depends on the attacker. Common goals are stealing credentials stored on the machine, swapping cryptocurrency wallet addresses in the clipboard or code, and injecting a backdoor into the software being built so it ships to users.

What are the main types of npm supply chain attack?

The main types are compromised maintainer accounts, stolen publish tokens, typosquatted packages, malicious install scripts and tampered build pipelines. Most real incidents combine two or more of them.

TypeHow it startsWhat the victim seesExample
Compromised maintainerPhishing steals the maintainer's npm loginA trusted package ships a malicious versionChalk and debug, September 2025
Stolen publish tokenToken leaked from a laptop or CI runnerAttacker publishes as the maintainerShai-Hulud, September 2025
TyposquattingLook-alike package name is publishedA typo in an install command pulls malwareThousands of fake packages yearly
Malicious install scriptPayload hidden in preinstall or postinstallCode runs during a routine installShai-Hulud bundle.js payload
Build pipeline tamperingCI secrets or workflows are abusedMalicious code ships in a real releaseLater Shai-Hulud waves, 2026
Dependency confusionPublic registry shadows a private package nameInternal builds pull the public packageDocumented across registries since 2021

Dependency confusion deserves a note even though it is less common in npm than in some other ecosystems. If your private package shares a name with a public one and your tooling checks the public registry first, an attacker can claim the public name and get your builds to pull their code.

What happened in the Shai-Hulud npm attack?

Shai-Hulud was a self-replicating worm that spread through npm in waves from September 2025, stealing developer and cloud credentials and using them to infect more packages. It was the largest npm supply chain incident to date.

The first wave surfaced on 15 September 2025, when researchers found trojanized versions of @ctrl/tinycolor, a color-manipulation library with about 2 million weekly downloads. The malicious code was an obfuscated file called bundle.js that ran through a postinstall script.

On the infected machine, the payload downloaded the open-source secret scanner TruffleHog and used it to harvest credentials from the filesystem and environment variables: npm tokens, GitHub tokens and AWS, Google Cloud and Azure keys. It then published the stolen secrets to public GitHub repositories and used any npm token it found to inject itself into the victim's other packages and republish them.

That loop is what made it a worm rather than a one-off compromise. Each new victim became a launch point, so the infection grew on its own with no further attacker input. Within days it had reached packages maintained by CrowdStrike and other well-known organizations.

CISA issued an alert on 23 September 2025, reporting more than 500 compromised packages and urging organizations to review dependencies, pin versions from before 16 September 2025, rotate developer credentials and require phishing-resistant MFA. GitHub removed more than 500 compromised packages from the registry.

A second wave, Shai-Hulud 2.0, arrived on 24 November 2025. It ran during preinstall instead of postinstall, which widened its reach, and it affected roughly 800 packages and more than 25,000 GitHub repositories holding stolen secrets, according to researchers tracking the campaign. Palo Alto Networks Unit 42, which investigated both waves, also assessed with moderate confidence that a large language model helped generate the malicious script.

What is the timeline of the 2025 npm attacks?

The 2025 npm attacks came in two clusters a week apart, then kept returning in waves through 2026. The timeline below covers the verified milestones.

  • 8 September 2025: an attacker phishes a well-known maintainer's npm account and publishes malicious versions of 18 widely used packages, including chalk and debug.
  • 14 September 2025: GitHub is notified of a self-replicating worm in npm packages; the first malicious publish is recorded that day.
  • 15 September 2025: researchers report trojanized versions of @ctrl/tinycolor carrying the Shai-Hulud worm.
  • 22 September 2025: GitHub reports removing more than 500 compromised packages and announces plans to harden npm publishing.
  • 23 September 2025: CISA publishes its alert on the widespread npm supply chain compromise.
  • 24 November 2025: Shai-Hulud 2.0 surfaces, running in preinstall and exfiltrating secrets to public repositories.
  • 9 December 2025: npm revokes all remaining classic tokens, forcing maintainers onto short-lived granular tokens or trusted publishing.

The chalk and debug incident matters because it shows the simpler attack path. No worm was needed: one phished account was enough to poison 18 packages that sit deep inside countless projects. Singapore's IMDA advisory put the affected packages' combined download rate at more than 2.6 billion per week.

Why are npm supply chain attacks so damaging?

They are damaging because trust is transitive: you trust a package, that package trusts its dependencies, and a compromise anywhere in the tree reaches everyone downstream before anyone notices.

First, the blast radius is enormous. A small utility with millions of weekly downloads can sit inside applications its own author has never heard of. The 2025 incidents showed that even security companies' packages could be reached through a stolen token.

Second, the stolen goods are the keys to everything else. Developer machines and CI runners hold the credentials that publish software, deploy infrastructure and access cloud accounts. Shai-Hulud harvested npm tokens, GitHub tokens and cloud keys in one pass, then published them in public repositories where anyone could use them.

Third, detection is hard. A malicious version looks identical to a legitimate one in your lockfile until someone diffs the code. Install scripts run silently, and a worm that republishes under a legitimate maintainer's identity leaves no obvious sign of an intruder.

Finally, cleanup is slow and expensive. Every credential that could have been exposed must be rotated, every build from the exposure window must be checked, and every downstream package must be audited. CISA's advice to rotate all developer credentials after Shai-Hulud reflects that reality.

How do I check if I was affected?

Check your lockfiles against published lists of compromised versions, review publish and audit logs for anything you did not do, and rotate credentials if there is any doubt. Do the checks in that order.

  1. Search your lockfiles. Grep package-lock.json, yarn.lock and pnpm-lock.yaml — including nested dependencies — for the compromised package names and versions in the published indicators of compromise.
  2. Check for new workflow files. Shai-Hulud added GitHub Actions workflow files and created public repositories named after the worm. Look for unfamiliar workflows or repositories in your organizations.
  3. Review npm and GitHub audit logs. Look for package publishes, token creations or repository changes you do not recognize, especially between 14 and 23 September 2025 and around 24 November 2025.
  4. Search for the payload. Look for bundle.js files with unusual size or obfuscation in installed packages, and for outbound connections to webhook.site, which CISA named in its guidance.
  5. Rotate everything that could have been exposed. npm tokens, GitHub personal access tokens, cloud keys and API keys — then check cloud audit logs for use of the old credentials.

If you find a compromised version, remove it, pin a known-good version published before 16 September 2025, rebuild, and re-check. Our free hash generator can help you compare file hashes against published indicators when you are verifying a suspicious file.

How do you prevent npm supply chain attacks?

No single control stops npm supply chain attacks. The goal is to make each stage of the attack harder, so a phished account or a stolen token does not become an ecosystem-wide incident.

Six defenses that break the npm attack chain 1 Pin versions with a lockfilecommit the lockfile; never install floating ranges in production builds 2 Block or audit install scriptsinstall scripts are where worms run — allow only packages you have checked 3 Scan dependencies before they runuse npm audit, Socket or a software composition analysis tool in CI 4 Use trusted publishing, not long-lived tokensshort-lived OIDC identities replace tokens that can be stolen 5 Require phishing-resistant MFAsecurity keys for npm and GitHub accounts, especially maintainers 6 Isolate builds and rotate secrets fastephemeral CI runners, scoped tokens, and a rehearsed rotation plan
Defense in depth for npm: each layer catches what the one above misses. Illustration by Cysoro.

For developers and teams

Commit your lockfile and review dependency updates. Treat a lockfile change like a code change: review it in the pull request, and be suspicious of version bumps in packages you did not expect to change. Tools like npm audit and Socket flag known malicious packages before they run.

Control install scripts. npm lets you disable scripts with --ignore-scripts, and newer npm versions block dependency install scripts by default in some configurations. If your project needs scripts, list which packages use them and why.

Keep publish tokens out of laptops and long-lived CI secrets. Use trusted publishing with OIDC where possible, scope tokens to the packages they need, and set short expiry times. npm's revocation of classic tokens in December 2025 pushed the ecosystem in exactly this direction.

For package maintainers

Use a security key for npm and GitHub. Phishing-resistant MFA stops the account-takeover path that started the chalk incident. Enable two-factor authentication for publishing, not just for login.

Publish from CI with trusted publishing. A short-lived identity issued to a specific workflow cannot be stolen from your laptop and reused, which removes the credential Shai-Hulud harvested.

Sign your packages. npm provenance attestations link a published version to the exact CI workflow and commit that built it, so consumers can verify a version really came from your pipeline. You can read more about verifying what you install in our guide to how spear phishing targets the people behind the accounts.

What tools and practices help after an incident?

After an incident, the priority is containment, then evidence, then a rebuild from known-good versions. Speed matters because stolen credentials are used within hours.

  • Freeze publishes. Revoke npm tokens and GitHub tokens, disable the affected CI workflows, and stop new deployments until the scope is known.
  • Preserve evidence. Save lockfiles, CI logs and the malicious package versions before you delete them, so you can answer what ran and where.
  • Rebuild from pinned versions. Restore from versions published before the compromise window, then scan the rebuilt tree before deploying.
  • Monitor for reuse of stolen secrets. Watch cloud audit logs and GitHub audit logs for the revoked credentials, and check for new public repositories containing your secrets.
  • Report it. Report compromised packages to npm and GitHub, and report the incident to CISA in the US. Public reporting is how the next team learns the indicators before they are hit.

For a wider starting point, our small business cybersecurity checklist covers secrets management, MFA and incident response alongside the basics.

The bottom line

Shai-Hulud showed that the npm registry's greatest strength — instant, frictionless reuse of other people's code — is also its greatest risk. A worm that steals credentials at install time can turn one phished account into hundreds of compromised packages.

Pin your versions, control install scripts, scan dependencies in CI, and replace long-lived tokens with trusted publishing. Then check your own exposure: review your lockfiles, rotate anything that could have been exposed, and verify your public services with the free SSL checker.

Frequently asked questions

What is an npm supply chain attack?

It is an attack that compromises a package in the npm registry, or the account that publishes it, so that developers who install the package run malicious code. The code can steal credentials, inject malware into builds or exfiltrate data.

What was the Shai-Hulud npm worm?

Shai-Hulud was a self-replicating worm first seen in September 2025. It ran at install time, stole npm, GitHub and cloud credentials from the machine, published the stolen secrets to public GitHub repositories and used stolen npm tokens to infect the victim's other packages.

How many packages did Shai-Hulud compromise?

CISA reported more than 500 compromised packages in its alert of 23 September 2025. A second wave in November 2025 affected roughly 800 more packages and touched more than 25,000 GitHub repositories, according to researchers tracking the campaign.

How do I know if my project installed a compromised npm package?

Check your lockfile against published lists of compromised package versions, look for unexpected install scripts or new workflow files, and review npm and GitHub audit logs for publishes you did not make. If in doubt, rotate credentials and rebuild from pinned, known-good versions.

Does a lockfile protect against npm supply chain attacks?

A lockfile helps a lot because it pins exact versions, so a malicious new version is not pulled in silently. It does not help if the pinned version itself is compromised, or if a dependency of a dependency is swapped, which is why scanning and provenance checks still matter.

What is trusted publishing for npm?

Trusted publishing lets a package be published from a CI workflow using a short-lived OIDC identity instead of a long-lived npm token. There is no token to steal from a developer laptop, which removes the exact credential Shai-Hulud harvested.

Should I disable npm install scripts?

Blocking install scripts stops the most common npm attack path, since worms like Shai-Hulud ran through postinstall and preinstall scripts. Many projects need some scripts, so the safer default is to audit which packages use them and allow only known ones.

Who is responsible for npm supply chain security?

Everyone in the chain shares it: npm and GitHub harden the registry, maintainers protect their accounts with phishing-resistant MFA, and your team pins versions, scans dependencies and keeps publish tokens out of developer machines and CI runners.

Sources

  1. CISA — Widespread Supply Chain Compromise Impacting npm Ecosystem
  2. Palo Alto Networks Unit 42 — Shai-Hulud Worm Compromises npm Ecosystem
  3. Socket — Shai-Hulud (npm worm)
  4. Chainguard — The npm registry can't protect you: the new JavaScript supply chain attacks
  5. IMDA Singapore — NPM supply chain attack advisory
  6. Cybersecurity Dive — CISA urges dependency checks following Shai-Hulud compromise
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 CISA alert of 23 September 2025, Palo Alto Unit 42 research and Socket's Shai-Hulud timeline.

How we write and fact-check →

See where your domain stands

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

Start free