npm supply chain attacks: how they work and how to protect yourself
An npm supply chain attack puts hostile code into a package that developers already trust, so your own install command lets it in. npm can run scripts right after a package is installed. In September 2025 poisoned versions of several popular packages used exactly that to harvest data. Two habits help most: install only versions that have been public for some days, and turn off install scripts where you can. If a bad version already ran, replace secrets from a clean device, after one check described below.
npm is the package manager and public registry for JavaScript. It is also how several coding agents are installed. A supply chain attack does not break into your Mac directly. It breaks into software you rely on, and your install does the rest. This page starts with what protects you from an npm supply chain attack, then gives the routes and the dated history. The pattern repeats: someone gets publisher access, publishes a poisoned version, and the code goes after tokens, keys and wallets.
01Protecting yourself from an npm supply chain attack
Each step covers a different route.
- Install only versions that have been public for a while. The npm option
min-release-ageinstalls only versions that were available more than a given number of days ago. - Turn off install scripts where you can. An install script is a command a package asks npm to run, such as
postinstall. Settingignore-scriptsto true stops npm from running the scripts inpackage.jsonfiles. npm 12 already blocks dependency install scripts by default until you approve them; npm 11 still runs them by default. Some packages need their scripts, so test your build. Both settings are described in npm's config docs. - Keep a lockfile and audit against it. A lockfile is the file where npm records the exact version of every package.
npm auditneeds it by default and reports known vulnerabilities. - Verify what you install.
npm audit signatureschecks registry signatures. Provenance, a public link from a package to its source code and build instructions, is a second check. - Check a package before you add it. Commands and a short list are on how to check an npm package for malware.
- Review what your agent adds. Auto mode in Claude Code allows installing dependencies declared in lock files or manifests by default. A new dependency in a diff is worth reading as closely as new code.
To see what a package script starts on your Mac, the free, open-source core of Artificial Immunity watches program starts and reports what it finds.
02How an npm supply chain attack reaches your Mac
One line per route. The details, and the signs to look for, are on npm malware. Read the list once and you will recognize most of the incidents in the timeline below.
- An install script. npm 11 runs
preinstall,installandpostinstallafter it places a package innode_modules. - A hijacked publisher. Phishing one npm maintainer was enough to put crypto-stealing code into 18 or more foundational packages.
- A lookalike or invented name. Typosquatting is the same trick as lookalike web addresses: a name one typo from the real one. Slopsquatting is registering a package name that an AI model made up.
- A public package that replaces a private one. This is dependency confusion. The 2021 research that made it known published same-named public packages to npm, PyPI and RubyGems, so npm is affected too.
03Timeline of the big npm incidents
| When | Incident | What happened |
|---|---|---|
| Feb 2021 | Dependency confusion research | A researcher breached over 35 companies' internal systems with same-named public packages |
| Apr 2025 | Wallet stealers | npm and PyPI packages posing as developer tools stole seed phrases and private keys |
| Aug 2025 | nodejs-smtp | A fake nodemailer rewrote Atomic Wallet's app code to swap recipient addresses |
| Aug 2025 | Nx, "s1ngularity" | Malicious Nx versions searched for wallets, keystores, .env files and SSH keys on Linux and macOS. See Nx |
| Sep 2025 | Maintainer phishing | Crypto-stealing code in 18 or more packages with over 2 billion weekly downloads |
| 15 Sep 2025 | Shai-Hulud | Poisoned versions with a post-install script, the first successful self-propagating attack on npm. See Shai-Hulud |
| Mid-Sep 2025 | postmark-mcp | An MCP server package reportedly copied email contents to an outside address |
| Oct 2025 | GlassWorm | Editor extensions that harvested npm tokens, GitHub credentials and OpenVSX tokens |
| 4 Aug 2026 | ChainDrop | 444 npm packages poisoned in under four hours |
04Why coding agents raise the stakes
An agent installs packages without you typing the command. That moves the check from the moment you type to the moment you read the diff. One 2025 campaign even prompted the AI command-line tools installed on the victim's machine; that story is on the --dangerously-skip-permissions page.
05What the poisoned code goes after
The payloads in these cases are built to find secrets. The Nx payload took the GitHub CLI token and npm config contents as well as wallets and keys. The Shai-Hulud payload ran TruffleHog, a secret scanner, and harvested environment variables. GlassWorm took npm tokens and GitHub credentials. A token is a secret string that lets a program act as you, which is why replacing them comes first after an incident.
06If a bad version already ran
After an npm supply chain attack, do not wait for proof. Use this order.
- Check for the trap file first. Run
ls ~/Library/LaunchAgents/com.user.gh-token-monitor.plistin Terminal. The Mini Shai-Hulud variant installs a background program there. That program tries to runrm -rf ~/, which deletes your home folder, when the GitHub token it checks is revoked. That program stops by itself after 24 hours without triggering. - If the file is there, do not revoke GitHub tokens yet, from this Mac or any other device. The program fires when the token it checks is revoked. Stop it first: macOS loads and unloads background agents with the
launchctlcommand.
launchctl bootout gui/$(id -u) ~/Library/LaunchAgents/com.user.gh-token-monitor.plist
rm ~/Library/LaunchAgents/com.user.gh-token-monitor.plistThe first line removes the background program from your login session, the second deletes its file, as Wiz advises before any token is revoked. Or wait until it exits after 24 hours. Then revoke. The steps are on the Shai-Hulud page.
- Replace credentials and sessions from a clean device, a computer or phone that never installed the package, right away if the file is not there, after step 2 if it is. Start with GitHub and npm tokens and any keys in
.envfiles, because those are what the payloads above searched for.
The ordered steps for replacing keys are in leaked API key and the infostealer check. The same attack pattern exists on the Python side: see PyPI malware.
FAQ
Is npm a security risk?
Yes, in a specific way: npm packages can run scripts on your machine right after they are installed, and a poisoned version of a popular package reaches everyone who installs it. In September 2025 malicious versions of several popular packages carried a script that harvested data.
How to avoid npm supply chain attacks?
You cannot remove the risk, but you can shrink it. Skip install scripts where you can, install only versions that have been public for some days, keep a lockfile and audit against it, and check provenance and signatures. The checklist is on the check an npm package page.
What is npm?
npm is the package manager and public registry for JavaScript. It is how tools such as Gemini CLI and Codex CLI are installed.
What is the most famous supply chain attack?
For npm, Shai-Hulud in September 2025 is the one to know: the first successful self-propagating attack in the npm ecosystem. ChainDrop reached 444 packages in under four hours in August 2026. The full story of the first is on the Shai-Hulud page.
Can an AI coding agent install a bad package for me?
Yes. Auto mode in Claude Code allows installing dependencies declared in your lock files or manifests by default, and an assistant can suggest a package name that does not exist, which an attacker can register.
What should I do if a bad version already ran?
First look for the file ~/Library/LaunchAgents/com.user.gh-token-monitor.plist. If it is there, don't revoke GitHub tokens yet, from any device: stop that program first or wait until it exits after 24 hours; the Shai-Hulud page has the order. Otherwise replace credentials and sessions from a clean device. The first hour is laid out in leaked API key.
Related guides
Sources
- Wiz, Shai-Hulud npm supply chain attack
- Wiz, s1ngularity supply chain attack
- Wiz, Mini Shai-Hulud
- Check Point, the great npm heist
- Socket, wallet-stealing npm and PyPI packages
- Socket, nodejs-smtp impersonating nodemailer
- Snyk, malicious postmark-mcp on npm
- Veracode, GlassWorm
- Eclipse Foundation, Open VSX security update
- BleepingComputer, dependency confusion research
- npm docs, scripts
- npm docs, config
- npm docs, npm audit
- Claude Code docs, permission modes
- Artificial Immunity