Detecting Shai-Hulud npm supply-chain worms offline

Updated 2026-06-01 · supply-chain security

You can catch most opportunistic npm supply-chain worms without a network or account by statically parsing every package's install script, checking package names against a bundled corpus of known-malicious entries, and flagging any trusted package whose lifecycle script suddenly drifts from its known-good fingerprint. Static analysis will not run or sandbox the code, so treat it as defense-in-depth, not a guarantee.

The threat

Most supply-chain compromises do their damage in a package's lifecycle scripts (preinstall, install, postinstall) — code that runs automatically the moment you npm install, before you import anything. The Shai-Hulud class of worm is the hard case: it doesn't ship as an obviously-bad new package, it injects itself into the install script of a package you already trust, so a blocklist of bad names never sees it.

What offline static auditing can catch

What it does not do

It is not a sandbox and does not block npm install — pair it with npm's ignore-scripts or an allow-list tool to actually prevent execution. It is not a CVE scanner — use osv-scanner or npm audit for known vulnerable versions. And it cannot deobfuscate arbitrary JavaScript. Its value is being small, auditable, deterministic, and runnable anywhere.

wormguard implements this approach as an offline, zero-dependency CLI for npm, pnpm, yarn, and bun. Source and docs: github.com/ArisRhiannon/wormguard.