Get the free coreGet core

npm supply chain attacks: how they work and how to protect yourself

Updated 5 min readSection 05 / Threats
SHORT ANSWER

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.

  1. Install only versions that have been public for a while. The npm option min-release-age installs only versions that were available more than a given number of days ago.
  2. Turn off install scripts where you can. An install script is a command a package asks npm to run, such as postinstall. Setting ignore-scripts to true stops npm from running the scripts in package.json files. 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.
  3. Keep a lockfile and audit against it. A lockfile is the file where npm records the exact version of every package. npm audit needs it by default and reports known vulnerabilities.
  4. Verify what you install. npm audit signatures checks registry signatures. Provenance, a public link from a package to its source code and build instructions, is a second check.
  5. Check a package before you add it. Commands and a short list are on how to check an npm package for malware.
  6. 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.

03Timeline of the big npm incidents

WhenIncidentWhat happened
Feb 2021Dependency confusion researchA researcher breached over 35 companies' internal systems with same-named public packages
Apr 2025Wallet stealersnpm and PyPI packages posing as developer tools stole seed phrases and private keys
Aug 2025nodejs-smtpA fake nodemailer rewrote Atomic Wallet's app code to swap recipient addresses
Aug 2025Nx, "s1ngularity"Malicious Nx versions searched for wallets, keystores, .env files and SSH keys on Linux and macOS. See Nx
Sep 2025Maintainer phishingCrypto-stealing code in 18 or more packages with over 2 billion weekly downloads
15 Sep 2025Shai-HuludPoisoned versions with a post-install script, the first successful self-propagating attack on npm. See Shai-Hulud
Mid-Sep 2025postmark-mcpAn MCP server package reportedly copied email contents to an outside address
Oct 2025GlassWormEditor extensions that harvested npm tokens, GitHub credentials and OpenVSX tokens
4 Aug 2026ChainDrop444 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.

  1. Check for the trap file first. Run ls ~/Library/LaunchAgents/com.user.gh-token-monitor.plist in Terminal. The Mini Shai-Hulud variant installs a background program there. That program tries to run rm -rf ~/, which deletes your home folder, when the GitHub token it checks is revoked. That program stops by itself after 24 hours without triggering.
  2. 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 launchctl command.
   launchctl bootout gui/$(id -u) ~/Library/LaunchAgents/com.user.gh-token-monitor.plist
   rm ~/Library/LaunchAgents/com.user.gh-token-monitor.plist

The 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.

  1. 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 .env files, 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.

Sources

  1. Wiz, Shai-Hulud npm supply chain attack
  2. Wiz, s1ngularity supply chain attack
  3. Wiz, Mini Shai-Hulud
  4. Check Point, the great npm heist
  5. Socket, wallet-stealing npm and PyPI packages
  6. Socket, nodejs-smtp impersonating nodemailer
  7. Snyk, malicious postmark-mcp on npm
  8. Veracode, GlassWorm
  9. Eclipse Foundation, Open VSX security update
  10. BleepingComputer, dependency confusion research
  11. npm docs, scripts
  12. npm docs, config
  13. npm docs, npm audit
  14. Claude Code docs, permission modes
  15. Artificial Immunity
Installing packages with an agent on your Mac? Artificial Immunity watches the Mac where your agents work.Get the free core