Software supply chain risk

npm Supply Chain Attacks

Updated 7 Nov 2026

An npm supply chain attack puts malicious code into a package that developers already trust.

Start the free 14-day trial Browse the Attack Library

What an npm supply chain attack is

An npm supply chain attack is a malicious change to a package that developers already trust. The attacker publishes a new version of the real package, and normal installs pull it in.

The attacker usually takes over a real package. Socket reports that a maintainer received a phishing email that spoofed npm and warned of outdated 2FA credentials. The attacker then published malicious versions of chalk, debug and other packages on 8 September 2025. Read our record of that attack.

The rest of the new version is the software that people asked for. The change is often one file or one line. That makes a list of changed files a weak signal. The question that matters is what the new file can do.

A power is something a file can do, such as reach the internet or run a program. A new power in an update is the signal to watch.

Recent npm attacks

The Vigilance attack library holds 31 npm records, from 2018 to October 2026. Each link opens a page with the package, the version change and the power that the update gained.

The full attack library also holds PyPI, crates.io, vendor installer and other records.

Five attacks that show the methods

axios, 31 March 2026

Huntress reports that an attacker used a long-lived access token to publish axios 1.14.1 and 0.30.4 directly. This skipped the normal GitHub Actions publishing workflow. The new versions added a package, plain-crypto-js, with a postinstall hook that deployed remote access trojans. See the axios page.

Shai-Hulud 2.0, 24 November 2025

Datadog reports that the worm hit 796 unique packages. A new preinstall script installed the Bun runtime and harvested credentials. The worm used stolen npm credentials to backdoor more packages. See the Shai-Hulud 2.0 page.

Nx s1ngularity, 26 August 2025

StepSecurity reports eight malicious versions that stayed live for about five hours. A postinstall script read GitHub tokens, npm credentials and SSH keys. See the Nx page.

TanStack, 11 May 2026

The TanStack postmortem reports 84 malicious versions across 42 packages. They went out in six minutes through a trusted publisher binding, which lets one workflow publish without a stored token. See the TanStack page.

event-stream, 2018

Snyk reports that an attacker earned the maintainer's trust and received publishing rights. The payload targeted the Copay bitcoin wallet build. See the event-stream page.

How malware gets into npm packages

Malware reaches an npm package in four main ways. The records above show each one.

A stolen maintainer account

Phishing took the chalk and debug maintainer account. A hijacked account published the ua-parser-js versions that the GitHub advisory lists as 0.7.29, 0.8.0 and 1.0.0.

A stolen publish token

The Nx attack used a token that a flawed GitHub workflow exposed. The axios attack used a long-lived token.

A weak build pipeline

The TanStack attack combined a flaw in a pull_request_target workflow (a GitHub trigger that runs with write access), a harmful build cache and a token pulled from runner memory.

A new package

The attacker adds a small package that holds the payload. The axios and event-stream cases both worked this way.

Install scripts carry these payloads. Three of the five attacks above, axios, Shai-Hulud 2.0 and Nx, used a postinstall or preinstall script. The script runs on the machine of whoever installs the package. That machine is often a developer laptop or a build server with many secrets.

A malicious version can also spread itself. The Shai-Hulud 2.0 worm used stolen npm credentials to backdoor more packages that its victims owned.

How to protect yourself

Limit what an install can run, limit who can publish, and check what each update can do.

A new power needs a look, and most are honest. Vigilance holds unsure findings and reports them to you. The nine prevention controls cover the rest of the pipeline.

  1. Step 1Ask your developers to turn off install scripts (the ignore-scripts setting) for packages that do not need them. This setting stops npm from running scripts that come with a package. The npm documentation says the default is false.
  2. Step 2Pin version numbers with a lockfile and read each update before you accept it.
  3. Step 3If you publish packages, move to trusted publishing. It replaces long-lived write tokens with short-lived credentials from your build workflow. It uses OIDC, a standard way to prove which workflow is asking.
  4. Step 4Run an SCA or malware detection tool on the packages your people pull. See software supply chain security tools.
  5. Step 5Start the free 14-day trial and install Vigilance on each computer where your team builds software with AI assistants. It checks each new package version from npm, pnpm, yarn and bun, and finds the update that gained a new power. On the free trial, Team and Managed, it swaps to the last good version.

npm and PyPI compared

Both registries have had the same kind of attack. A trusted package gets a malicious new version. The way the payload runs differs.

What differsnpmPyPI
How the payload runsAn npm payload more often rides on an install script.A PyPI payload can ride on a module import or a .pth file.
A real caseSee the recent attacks above.BleepingComputer reports that litellm 1.82.7 and 1.82.8 reached PyPI on 24 March 2026. Version 1.82.7 hid a base64 payload in a Python module that ran when the module loaded. Version 1.82.8 added a .pth file, which Python processes when the interpreter starts. The payload then ran even if no code imported litellm. See the litellm page.
Trusted publishingSupported. It is an OIDC exchange of short-lived tokens.Supported. PyPI documents it as an OIDC exchange of short-lived tokens.
The protectionPin versions, avoid long-lived publish tokens and read what each update changes. Vigilance checks installs made with npm, pnpm, yarn and bun.Pin versions, avoid long-lived publish tokens and read what each update changes. Vigilance checks installs made with pip and uv.

FAQ

What are npm vulnerabilities?

An npm vulnerability is a flaw in a package that an attacker can use, such as a known bug. A malicious version is a different problem. The package works as before and also carries code the attacker added. A CVE scanner finds the first kind. Vigilance finds the second kind by checking what an update can do. See how to detect an attack without a CVE.

Check your next update.

Vigilance checks the packages that AI assistants and your team adds to each computer. On the free trial, Team and Managed, it swaps a bad update for the last good version.

Start the free 14-day trial See pricing