Skip to content

Shai-Hulud and npm i -g: never install a CLI that handles secrets through npm

A malicious postinstall harvests environment variables, tokens and SSH keys, during a 90-minute window and without a trace. The four layers that would have stopped it.

In short

Symptom
No visible symptom. The install takes six seconds, raises no error, and the CLI works perfectly afterwards. The consequences arrive later, and elsewhere.
Real cause
npm install does not just install code: it runs it, with your rights and your environment. The publishing account had been compromised through a CI action referenced by a mutable tag; the payload sat in an install script, and it targeted environment variables, tokens and keys.
Fix
Four layers: a signed official binary rather than a language package manager, an adoption delay on dependencies, install scripts disabled by default with a minimal allowlist, and CI actions pinned by commit digest.
Prevention
The adoption delay gives the most protection for the least effort: a malicious release is pulled within hours, so a few days of waiting are enough to close this vector.

The answer, in three lines

npm install does not just install code: it runs it, with your rights and your environment. A CLI that handles secrets combines both risks. You install it through a channel that runs arbitrary code, then you run it exactly where all your keys are.

Four layers of defence, from the most to the least rewarding: a signed official binary rather than a language package manager, an adoption delay of a few days, install scripts disabled by default with a minimal allowlist, and CI actions pinned by commit digest.

The symptom

This is the only entry in the notebook whose symptom is the absence of a symptom. A malicious postinstall succeeds precisely when nothing shows:

$ npm i -g @un-outil/cli
added 214 packages in 6s
$

The install takes six seconds, with no error, and the CLI works perfectly afterwards. It is the official CLI, with extra code.

During those six seconds, an install script read the process environment (your environment variables, your platform tokens, your SSH keys and your infrastructure credentials) and sent it elsewhere. The symptoms arrive later, and elsewhere: a modified repository nobody recognises, a token used from an unknown address, a package published under your name.

You only see the compromise if you go looking for it:

$ npm ls -g --depth=0
$ ls ~/.npm/_logs/                # install timestamp
$ npm view @un-outil/cli time --json | tail -20   # was the installed version published that day?

The wrong diagnosis

In the April 2026 incident, the compromised package was the official CLI of a widely used and audited password manager. Trust in the vendor was justified, but it did not answer the question.

The second wrong reflex is the technical trap of this entry: "let's disable install scripts everywhere, right now". That measure breaks everything. I checked: in a workspace in daily use, every JavaScript repository had dependencies with native build scripts (mobile apps, a desktop app, image processing engines, compilers, embedded database drivers, test browsers). A global disable breaks installs and builds, it gets reverted within the week, and you conclude that "supply chain security is just not practical". A measure that is too broad does worse than nothing: it keeps you from taking a good one afterwards.

The third reflex is the most common one after an incident: "we'll audit our dependencies". An audit answers "which versions do I have today?". The question that matters is "what is going to run tomorrow, automatically, on my machine?".

What is actually happening

npm install does not just install code: it runs it, with your rights and your environment.

The April 2026 incident (@bitwarden/cli, the "Shai-Hulud: The Third Coming" worm) follows the usual playbook for this kind of attack:

  1. The entry point is not npm. The publishing account was compromised through a third-party CI action, itself booby-trapped and referenced by a mutable tag. An attacker can re-point an action referenced as @v3.
  2. The payload is an install script. preinstall and postinstall run automatically, with the user's rights and full access to the process environment, the disk and the network.
  3. The target is the environment: environment variables, platform tokens, SSH keys, cloud credentials. That is exactly what a developer machine or a CI runner holds in memory at the moment it installs.
  4. The window lasted about 90 minutes between the poisoned release and its removal.

That last point is the one you can use most: the window is short. It holds for every attack of this kind, not just this incident: a malicious release is detected and pulled within hours, sometimes within tens of minutes. An adoption delay of a few days is therefore enough to close this vector completely.

The entry's title targets a special case: a CLI that handles secrets combines both risks. You install it through a channel that runs arbitrary code, then you run it in an environment that holds all your keys. The tool meant to protect your secrets becomes the way to steal them.

The fix

Four layers. None is enough on its own, and the first two protect the most, straight away.

Step 1: No global package-manager install for a tool that touches secrets

Install the signed official binary, and check its digest and its signature:

VER=v3.9.4
curl -fsSLO https://github.com/getsops/sops/releases/download/${VER}/sops-${VER}.linux.amd64
curl -fsSLO https://github.com/getsops/sops/releases/download/${VER}/sops-${VER}.checksums.txt
curl -fsSLO https://github.com/getsops/sops/releases/download/${VER}/sops-${VER}.checksums.sig

# 1) the digest
grep 'linux.amd64' sops-${VER}.checksums.txt | sha256sum -c -

# 2) the signature over the digest list
cosign verify-blob \
  --certificate-identity-regexp '.*' --certificate-oidc-issuer-regexp '.*' \
  --signature sops-${VER}.checksums.sig sops-${VER}.checksums.txt

People often skip step 2, yet it is the one that protects you: a digest served from the same origin as the binary proves nothing if that origin is compromised.

Step 2: The adoption delay

This is the measure on the list that gives the most protection for the least effort: one configuration key is enough, and the risk from the short window disappears.

# .github/dependabot.yml
updates:
  - package-ecosystem: npm
    directory: /
    cooldown:
      default-days: 7
      semver-major-days: 14
    schedule:
      interval: weekly
// renovate.json — équivalent
{
  "minimumReleaseAge": "7 days",
  "internalChecksFilter": "strict",
  "github-actions": { "pinDigests": true }
}

Step 3: Scripts off by default, allowed one at a time

This time the measure is targeted, not global:

# .yarnrc.yml
enableScripts: false
// package.json — the allowlist, built by iteration, never in bulk
{
  "dependenciesMeta": {
    "esbuild": { "built": true },
    "sharp":   { "built": true }
  }
}

To build the list, work locally, in a throwaway environment:

yarn config set enableScripts false
yarn install --immutable && yarn build     # note every package whose build fails
# for each failure -> dependenciesMeta.<package>.built = true, then start again

Repeat until the build is green with the minimal list. That takes one hour of work, once, whereas a global measure breaks everything and ends up reverted.

Step 4: Pin CI actions by commit digest

This is the direct lesson of the entry point: a tag can be re-pointed, a SHA cannot.

- uses: actions/checkout@v4
+ uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683  # v4.2.2

Check (pass or fail)

# no sensitive CLI installed globally through npm
npm ls -g --depth=0 | grep -Ei 'bitwarden|vault|sops|secret|kubeseal|1password' && exit 1 || echo OK

# no action referenced by a mutable tag
grep -rEn 'uses: .+@(v[0-9]+|main|master)$' .github/workflows/ && exit 1 || echo OK

Prevention

  • In CI, make the two pass-or-fail checks above blocking. The second one holds longest, because mutable tags come back on their own with every new workflow.
  • Keep a written, named list of the tools installed from a verified binary, with their version and digest. It pays twice: at install time, and on the day of an incident, to know in ten minutes who is exposed.
  • In the repository instruction file, write the most important rule in the file: "Never install a tool that handles secrets through a language package manager. If you are missing the tool, stop and ask."
  • Limit the possible damage: no long-lived token in the environment of a development machine or a CI runner. It is the only measure that still protects you when the other four have failed.

Why this matters with agents

With agents running in parallel, the risk changes in nature, not just in frequency.

An agent installs tools with nobody watching, since that is what you ask it to do: "set up the deployment", "configure secret management". It searches, finds the most documented command (a global install), and runs it. From its point of view it did the right thing: it is the most common answer to the question it was asked. Six agents in parallel means six installs an hour that nobody reviews.

An agent's environment is the worst place for a postinstall. An agent runs with what it needs to work: platform token, registry access, deployment keys, sometimes cluster credentials. That is exactly what the payload is looking for. A developer installing a tool exposes their machine; an agent runner installing a tool exposes the production pipeline.

Finally, it becomes very hard to tell who installed what. After an incident, the question is "which machines installed what, and when?". On agent sessions running in ephemeral containers, often no install log survives the end of the session. That is why layer 2, the adoption delay, is the only one that really protects you here: it acts before the install, at the only moment you are still in control.

What this entry does not cover

A secret can also be compromised through its shape, rather than through its install channel:

The neighbouring case of a mutable reference on the image side makes it just as impossible to tell who did what:

Where this entry comes from

A review of the exposure surface of a personal workspace, after the public April 2026 incident. No secret, no token and no private digest appears here: the only SHA quoted is the public digest of a widely used action.


This entry is part of a notebook of 27 production failures hit between February and September 2026. Some are public and free: see the notebook.

The others are published as they are written, along with the modules and their exercises, as part of the paid product. In that product, the modules are in English; the exercises and the other entries are in French. Nothing on this page is a teaser for it.

Related notes

The method that handles this kind of failure