In the space of two weeks, the JavaScript ecosystem was hit by two serious npm supply chain attacks. On 8 September, after a phishing email, malicious versions of chalk, debug and 16 other popular packages appeared on npm, and from 15 September a self-propagating worm, “Shai-Hulud”, infected several hundred packages and stole the tokens of developers and CI systems. Both cases show that an npm install can now be just as risky as running an unknown script.
Below we summarise what is known as of Friday morning, and show what is worth checking and changing on build servers and in CI/CD pipelines.
8 September: chalk, debug and co.
Josh Junon (Qix-), the maintainer of several core npm packages, received an email that looked like it came from npm support, asking him to update his two-factor authentication. The message came from the npmjs.help domain, which, according to Aikido’s analysis, had been registered three days earlier, on 5 September. With the access they obtained, the attackers published malicious versions of the maintainer’s packages; Aikido flagged the first ones at 13:16 UTC (15:16 Hungarian time).
Together, the affected packages account for more than two billion downloads a week. According to StepSecurity’s list, these versions are malicious:
| Package | Version | Package | Version |
|---|---|---|---|
| chalk | 5.6.1 | debug | 4.4.2 |
| ansi-styles | 6.2.2 | strip-ansi | 7.1.1 |
| ansi-regex | 6.2.1 | color-convert | 3.1.1 |
| color-name | 2.0.1 | supports-color | 10.2.1 |
| wrap-ansi | 9.0.1 | slice-ansi | 7.1.1 |
| color | 5.0.1 | color-string | 2.1.1 |
| is-arrayish | 0.3.3 | simple-swizzle | 0.2.3 |
| supports-hyperlinks | 4.1.1 | has-ansi | 6.0.1 |
| chalk-template | 1.1.1 | backslash | 0.2.1 |
The injected code runs in the browser: it hijacks fetch and XMLHttpRequest calls, watches the operations of crypto wallets (for example window.ethereum), and replaces Bitcoin, Ethereum, Solana, Tron and other addresses with similar-looking addresses belonging to the attackers. Server-side Node.js execution was not the target; the risk lies where the package ended up in a frontend build and, from there, in users’ browsers. The malicious versions were removed within a few hours, so the builds affected are those that pulled them in during this time window, without a lockfile or while updating.
From 15 September: the Shai-Hulud worm
A week later, a much more dangerous attack began. Among the first known affected packages was @ctrl/tinycolor, with more than two million downloads a week; on 16 September BleepingComputer reported 187 infected packages, and security companies have since put the number at around 500. Several of CrowdStrike’s npm packages were also affected; according to the company, the Falcon sensor is not affected.
According to Wiz’s analysis and other researchers, the worm works like this:
- On installation, the infected package launches a multi-megabyte
bundle.jsfile through apostinstallscript. - The script downloads and runs TruffleHog, an otherwise legitimate secret-scanning tool, goes through the environment variables, and when running in the cloud it also requests access keys from the instance metadata service (IMDS).
- With a GitHub token it finds, it creates a public repository called
Shai-Huludin the user’s account and uploads the stolen data there. In the repositories it can access, it adds ashai-huludbranch and a GitHub Actions workflow that sends the repository’s secrets to an external webhook. In some cases it also made the organisation’s private repositories public, with a-migrationsuffix. - If it finds an npm token, it fetches the maintainer’s packages, injects itself into the 20 most popular ones, bumps the version number and republishes them. That is how it keeps spreading without human intervention.
The attack is reminiscent of an incident at the end of August, the “s1ngularity” incident affecting the packages of the Nx build system, where developer tokens also ended up in public GitHub repositories.
Why does an npm supply chain attack affect build servers?
A CI runner or build server is an ideal target: it is where most npm install commands run, and where the most secrets are in one place. The environment of a typical pipeline contains the npm publish token, the GitHub or GitLab token, the key used for deploying to the cloud, and the container registry password. The postinstall script reaches all of this with the same rights as the build itself. If the runner is a cloud virtual machine with an IAM role attached, the cloud account can also be reached through the metadata service.
What should you do now?
1. Find the affected versions
With a jq command, you can list the installed versions of the 8 September packages from the lockfile (for an npm 7 or newer lockfile):
jq -r '.packages | to_entries[]
| select(.key | test("node_modules/(chalk|debug|ansi-styles|strip-ansi|ansi-regex|color-convert|color-name|supports-color|wrap-ansi|slice-ansi|color|color-string|is-arrayish|simple-swizzle|supports-hyperlinks|has-ansi|chalk-template|backslash)$"))
| "\(.key) \(.value.version)"' package-lock.json
Compare the result with the table above. The Shai-Hulud package list is still growing, so it is worth checking against the updated lists from security companies (Wiz, Socket, StepSecurity). In your GitHub organisation, look for a repository called Shai-Hulud, a branch called shai-hulud, unknown workflow files and repositories ending in -migration.
2. Rotate the tokens
If an affected version was installed on any machine or in any pipeline, treat the secrets on that machine as leaked: npm tokens, GitHub and GitLab tokens, SSH keys, cloud access keys, and passwords stored in CI/CD variables. Rotate them in the pipelines’ variables too, not only on developers’ machines.
3. Lockfile and npm ci
Run npm ci instead of npm install in the build: it installs exactly the versions pinned in the lockfile, and fails with an error if package.json and the lockfile differ. A GitLab CI job, for example:
build:
image: node:22
cache:
key:
files:
- package-lock.json
paths:
- .npm/
script:
- npm ci --cache .npm --prefer-offline
- npm run build
Where possible, run npm ci with the --ignore-scripts option: this blocks Shai-Hulud’s way of spreading, the postinstall script. Some packages (for example native modules) rely on their install script, so this has to be tested project by project.
4. Pinned versions, delayed updates
With the save-exact=true setting in .npmrc, an exact version goes into package.json instead of ranges like ^5.6.0. With dependency update tools (for example with Renovate’s minimumReleaseAge setting), it is worth waiting a few days before adopting a new version: in both attacks, it became clear within hours which versions were malicious.
5. Narrowly scoped CI tokens
- In GitLab, store publish and deploy tokens as protected and masked variables, so that only jobs running on protected branches get them, and a merge request pipeline doesn’t.
- On npm, use granular tokens with an expiry date and package-level restrictions instead of classic tokens, or trusted publishing, which became generally available at the end of July: it publishes from GitHub Actions and from gitlab.com shared runners with OIDC, without a stored token.
- In the cloud, use short-lived credentials requested with OIDC instead of static keys, and let the runner’s role allow only what the deployment needs.
- The runner should preferably run every job in a fresh, disposable container, not on a long-lived build server where one job can also see the next one’s secrets.
What can we learn from it?
Last spring, the xz backdoor showed that the account or package of a trusted maintainer can also be an attack vector. The npm cases did the same much faster and on a larger scale: a single phishing email was enough, and the worm now spreads with no maintainer involved at all. As we wrote in the lessons of the CrowdStrike outage, supplier risk has to be accounted for like any other source of failure.
The case isn’t closed yet; the Shai-Hulud package list grows day by day. If you need help reviewing your pipelines, rotating tokens or narrowing CI/CD permissions, get in touch; you can read more on our Cloud and DevOps page.