Supply chainSep 2025

Shai-Hulud npm Worm

A worm stole npm developers' tokens and used them to publish infected versions of their other packages. Over 500 were hit.

Severity
Front-page news
Difficulty
intermediate
Companies
GitHub, npm
Tech
npm, JavaScript, Post-install scripts, GitHub tokens, Cloud credentials
Root cause
poisoned dependency, stolen credentials

The story

Quick (1 min)

In September 2025, a worm spread through npm, the main registry of JavaScript packages. It was nicknamed Shai-Hulud (after the giant sandworms in Dune).

When a developer installed an infected package, hidden code ran automatically (a post-install script) and searched the computer for secrets: GitHub tokens and cloud keys for AWS, Google Cloud and Azure. It sent them to the attacker and even posted them publicly on GitHub.

Then came the worm part. Using the stolen npm access, it logged in as that developer, injected itself into their other packages, and published new infected versions. Each new victim spread it further. CISA said over 500 packages were compromised before GitHub removed them.

The lesson: install scripts run code on your machine automatically, and long-lived publishing tokens let one infection spread itself across an ecosystem.

Keep reading to the end to earn XP.Read. XP earned.

Engineer (2 min)

Entry point. GitHub says the worm "infiltrated the npm ecosystem via compromised maintainer accounts by injecting malicious post-install scripts into popular JavaScript packages." npm runs postinstall scripts automatically on npm install, so simply installing a dependency executes the attacker's code.

What the malware did (CISA):

  1. Scanned the environment for sensitive credentials, targeting GitHub Personal Access Tokens and API keys for AWS, GCP and Azure.
  2. Exfiltrated them to an attacker-controlled endpoint.
  3. Uploaded them to a public GitHub repository named "Shai-Hulud" via the GitHub API.
  4. Self-replicated: "authenticating to the npm registry as the compromised developer, injecting code into other packages, and publishing compromised versions to the registry."

Why worms work here. Many maintainers have long-lived npm publish tokens in their environment. Steal one token and you can publish to every package that maintainer controls, each of which installs on thousands of machines, some belonging to other maintainers with their own tokens.

Containment (GitHub). Notified on 14 September 2025. GitHub removed 500+ compromised packages and had npm block uploads containing the malware's indicators of compromise, "cutting off the self-replicating pattern."

Platform changes announced by GitHub: required 2FA for local publishing; granular tokens limited to seven days; trusted publishing (OIDC from CI); deprecating legacy classic tokens; moving from TOTP to FIDO-based 2FA; disallowing tokens for publishing by default.

Interview takeaway: disable or sandbox install scripts, don't keep long-lived publish tokens on developer machines, use trusted publishing and phishing-resistant MFA, and pin dependencies with lockfiles.

Keep reading to the end to earn XP.Read. XP earned.

Deep dive (2 min)

Timeline (GitHub, CISA)

  • 14 September 2025: GitHub is notified of the Shai-Hulud attack.
  • Mid-September: the worm spreads via compromised maintainer accounts and post-install scripts. CISA later advises pinning dependencies to versions published before 16 September 2025.
  • Response: GitHub removes 500+ compromised packages, and npm blocks new uploads matching the malware's indicators.
  • 22 September 2025: GitHub publishes "Our plan for a more secure npm supply chain."
  • 23 September 2025: CISA alert: over 500 packages compromised.

CISA's recommendations

  • Review all npm dependencies, including nested ones in package-lock.json or yarn.lock.
  • Search artifact caches for affected versions.
  • Pin to known safe releases from before 16 September 2025.
  • Immediately rotate all developer credentials.
  • Mandate phishing-resistant MFA for developer accounts on GitHub and npm.
  • Monitor network behaviour; block outbound connections to webhook.site domains.
  • Remove unnecessary GitHub Apps and OAuth apps; audit webhooks and secrets; enable branch protection, secret scanning and Dependabot.

GitHub's planned npm changes

  • Local publishing with required 2FA, and no option to bypass 2FA.
  • Granular tokens with a seven-day lifetime; shorter for publishing tokens.
  • Trusted publishing (with more eligible CI providers).
  • Deprecate legacy classic tokens and TOTP 2FA, moving to FIDO-based 2FA.
  • Disallow tokens for publishing by default.

Why it matters

Earlier npm incidents (left-pad, event-stream) involved one package. Shai-Hulud automated the attacker's job: each infection harvested what it needed to cause the next. GitHub said the worm "could have enabled an endless stream of attacks" without quick action.

Keep reading to the end to earn XP.Read. XP earned.

Failure replay

Step by step, what broke and what it hit next.

  1. Sep 2025
    Compromised maintainer accountcompromised

    Attackers control a maintainer account and add a malicious post-install script to a popular package.

    Affects: Infected npm package

  2. Sep 2025
    Infected npm packagecompromised

    A developer runs npm install, and the post-install script executes automatically on their machine or CI runner.

    Affects: Developer environment

  3. Sep 2025
    Developer environmentcompromised

    The malware harvests GitHub tokens and AWS, GCP and Azure keys, sends them out, and posts them to a public "Shai-Hulud" repo.

    Affects: npm registry

  4. Sep 2025
    npm registryfailing

    Using the victim's npm credentials, it injects itself into their other packages and publishes infected versions.

    Affects: Infected npm package

  5. Sep 2025
    Infected npm packagecompromised

    Each new victim spreads it further. Over 500 packages are compromised.

  6. Sep 14+
    npm registryrecovering

    GitHub removes the 500+ packages and npm blocks uploads matching the worm's indicators, breaking the chain.

  7. Sep 22–23
    Developer environmentrecovering

    CISA urges rotating all developer credentials. GitHub announces short-lived tokens, trusted publishing and FIDO 2FA.

Impact

Who was affected
Over 500 npm packages compromised; developers and CI systems that installed them had GitHub tokens and AWS/GCP/Azure keys exposed.
How long
Spread in mid-September 2025; GitHub was notified on 14 September and removed the packages; follow-up guidance through 22–23 September.
Cost
not disclosed

Lessons

  • Install scripts run code automatically; disable them (npm --ignore-scripts) or sandbox installs where possible.
  • Long-lived publishing tokens let malware spread itself; use short-lived tokens and trusted publishing.
  • Phishing-resistant MFA (FIDO) should be required for package maintainers.
  • Pin dependencies with lockfiles and roll back to known-good versions during incidents.
  • Rotate every credential an infected environment could see.

Quiz

  1. How did Shai-Hulud's code run on developers' machines?

    Check answer

    Via malicious post-install scripts that run automatically on npm install. npm executes postinstall scripts automatically when packages are installed.

  2. What made it self-replicating?

    Check answer

    It used stolen npm credentials to inject itself into the victim's other packages and publish them. Each infected developer's packages became new infection vectors.

  3. Roughly how many npm packages were compromised, according to CISA?

    Check answer

    Over 500. CISA and GitHub cite over 500 compromised packages.

  4. Which change did GitHub announce for npm publishing?

    Check answer

    Granular tokens with a seven-day lifetime, trusted publishing, and FIDO-based 2FA. GitHub's plan shortens token lifetimes, promotes trusted publishing and moves to FIDO 2FA.

Interview prep

Try answering out loud before you open the model answer.

  1. security

    What made Shai-Hulud a worm rather than a one-off malicious package?

    Show model answer

    It self-replicated. After running through a post-install script, it stole credentials, including npm and GitHub tokens, from the developer's environment. Then it used those credentials to authenticate to npm as the victim, inject itself into the victim's other packages, and publish new infected versions. Anyone installing those spread it further, especially other maintainers. One-off attacks need the attacker to act each time; this one used each victim to reach the next. Breaking the chain means removing long-lived publish tokens, requiring 2FA for publishing, and blocking known-bad uploads.

    A strong answer hits:

    • Post-install execution
    • Credential theft including publish tokens
    • Automated republishing to the victim's packages
    • Short-lived tokens and 2FA break the loop
  2. system design

    How would you redesign package publishing for a registry like npm to resist self-spreading malware?

    Show model answer

    Remove long-lived, broadly scoped tokens: use trusted publishing (OIDC from CI with provenance) and short-lived granular tokens. Require phishing-resistant 2FA for any interactive publish. Add anomaly detection for unusual publishing bursts (many packages updated by one account quickly) and scanning of new versions for known indicators, with automatic quarantine. Make install-time scripts opt-in or sandboxed. Support fast revocation and bulk takedown. GitHub's plan follows much of this.

    A strong answer hits:

    • Trusted publishing and short-lived tokens
    • FIDO 2FA for publishing
    • Burst-publishing detection and quarantine
    • Opt-in or sandboxed install scripts
  3. behavioural

    Your team discovers one of your dependencies was infected by Shai-Hulud and installed on developer laptops and CI. What do you do?

    Show model answer

    Identify where the infected version was installed using lockfiles and build logs. Treat every secret on those machines and runners as compromised: rotate GitHub tokens, npm tokens and cloud keys, and audit their use. Check whether your own packages were republished by the worm and unpublish or deprecate any malicious versions. Pin to known-good versions and clear caches. Then harden: ignore-scripts in CI, scoped short-lived credentials, FIDO 2FA, and egress controls.

    A strong answer hits:

    • Scope installs via lockfiles and logs
    • Rotate all reachable secrets and audit
    • Check and clean your own published packages
    • Harden pipelines and accounts

Go deeper