Blog

npm Supply Chain Attacks 2026: How to Protect Your Project

Updated:

In 2026, npm supply chain attacks went industrial: hijacked maintainer accounts, worms that republish other people's packages on their own, and compromised CI pipelines publishing malware with valid signatures. This guide walks through the major incidents of the year, the ways malicious npm packages reach your project, and the settings that shut most of them down, with ready-to-use .npmrc, commands and GitHub Actions snippets.

What is an npm supply chain attack

A supply chain attack does not target your application directly. It targets what your application is built from: a library, the package manager, the build pipeline. You install a package you have used for years, and the new version ships a loader that steals npm and GitHub tokens, cloud keys, SSH keys and environment variables.

npm is an attractive target because a typical project pulls in hundreds of transitive dependencies, and an update to one small library reaches thousands of projects within hours. The attacker does not need a bug in your code. Publishing rights to one popular package are enough; you will run their code yourself, on developer laptops and in CI, exactly where the secrets live.

What changed in 2026 is self-propagation. Once a worm has a victim's npm token, it lists every package that token can publish, injects itself, bumps the patch version and republishes. One stolen token becomes dozens of infected packages, and each of them steals more tokens.

Major npm attacks in 2026

Summary based on researcher write-ups, as of November 23, 2026. Figures come from the linked sources; other vendors sometimes count differently.

WhenWhatScaleHow it spread
Apr 29 – May 19Mini Shai-Hulud: SAP, TanStack and @antv wavesTanStack: 373 versions across 169 packages in one day; @antv: 639 versions across 323 packages in about an hourpreinstall hook, token theft, self-propagation; TanStack via a CI pipeline compromise (Unit 42)
Jun 1@redhat-cloud-servicesat least 32 packagescompromised employee GitHub account, commits that bypassed review (Unit 42)
Jul 14@asyncapi5 versions across 4 packagespull_request_target workflow, payload runs on import, valid provenance (Microsoft)
August (analysis dated Aug 4)ChainDrop, a Mini Shai-Hulud variant400+ packages, including keyv, flat-cache and cache-managerstolen maintainer credentials, preinstall hook, self-propagation, abuse of trusted publishing (Microsoft)
Nov 3PolinRider12 releases across 10 hijacked packages, some dormant for yearsloader reads the second-stage server address from an Ethereum transaction (Sonatype)

The PolinRider trick matters: the operators change the server address with a new blockchain transaction instead of a new package version, so blocking one bad domain does not end it. Sonatype attributes the campaign to the Lazarus Group.

How malicious packages get into your project

  • Install scripts. preinstall, install and postinstall run during npm install, before you open a single file. This is how Mini Shai-Hulud and ChainDrop executed.
  • Maintainer account takeover. Phishing, a leaked token, a password without 2FA. The package name is real, the version is new, and it is malicious. The same pattern hit the WordPress plugin directory in November 2026: see the backdoor in 6 WordPress plugins.
  • Typosquatting. A lookalike name: a typo, an extra hyphen, an "official" scope that does not exist. Install commands copied from forums or AI-generated code are a common entry point.
  • Code that runs on import. The payload runs on require or import, not at install time. Disabling scripts does nothing here, as @asyncapi showed.
  • CI tokens and workflows. A compromised pipeline publishes a poisoned version on behalf of the project, properly signed. An untrusted pull request executed with access to secrets hands over the tokens.
  • Third-party scripts in the browser. The same trust problem exists outside npm: in November 2026 a hijacked marketing pixel and a cookie-banner setting injected a card skimmer into store checkouts. See the WebRTC card skimmer that hit 5 stores.

The lockfile and npm ci

Rule one: in CI, on servers and in Docker images, use npm ci, never npm install. According to the npm docs, npm ci requires an existing package-lock.json, fails if it disagrees with package.json, deletes any existing node_modules and never writes to the lockfile. What gets built is what was reviewed, not whatever the caret range resolves to today.

CI install and checksbash
# in CI and on servers, always
npm ci

# known vulnerabilities in production dependencies
npm audit --omit=dev

# registry signatures and provenance attestations of installed packages
npm audit signatures

Rule two: lockfile changes are part of code review. If a pull request bumps one dependency and dozens of transitive packages move in package-lock.json, stop and look at what actually arrived.

Disabling install scripts and keeping an allowlist

npm 12: install scripts are off by default

Since npm 12 became the latest release on July 8, 2026 (GitHub Changelog), npm install no longer runs dependency preinstall, install or postinstall scripts unless the project allows them. Implicit node-gyp builds are blocked too, and Git and remote-URL dependencies are not resolved by default. The allowlist lives in the allowScripts field of package.json, and the commands below maintain it:

Install-script allowlist in npm 12bash
# npm 12: which packages want to run install scripts
npm approve-scripts --allow-scripts-pending

# allow the ones you reviewed (pinned to the installed version by default)
npm approve-scripts esbuild sharp

# explicitly deny the rest
npm deny-scripts some-telemetry-pkg

# the result lands in "allowScripts" in package.json: commit it

Allow only packages that genuinely compile native code or download a binary: esbuild, sharp, database drivers. A version-pinned entry beats a name-only one: if the package is hijacked later, the new version is not covered by your old approval.

pnpm

pnpm has blocked dependency build scripts by default since version 10. In the current docs the allowlist is the allowBuilds map in pnpm-workspace.yaml (the older onlyBuiltDependencies was removed in pnpm 11, and a codemod handles the migration), and strictDepBuilds fails the install by default when an unreviewed build script shows up. Yarn has its own settings; check the docs for your version.

pnpm-workspace.yamltext
# pnpm-workspace.yaml
# skip versions younger than 3 days (value in minutes)
minimumReleaseAge: 4320
minimumReleaseAgeExclude:
  - '@myorg/*'

# dependency build scripts: true = allowed, false = denied
allowBuilds:
  esbuild: true
  core-js: false

Delay updates: minimum release age

The 2026 attacks moved in hours. Unit 42 counted 84 malicious artifacts published within six minutes in the TanStack wave. They are usually spotted and pulled quickly, so the cheapest defense is to refuse versions younger than a few days. Teams that update in the first hour get caught; teams that wait three to five days rarely do.

ToolSettingUnit
npm 11.10+min-release-age in .npmrcdays, off by default
pnpmminimumReleaseAge in pnpm-workspace.yamlminutes, default 1440 (one day)
Dependabotcooldown in dependabot.ymldays; does not apply to security updates
.npmrctext
# .npmrc in the project root
# only install versions published more than 3 days ago (npm 11.10+)
min-release-age=3
# save exact versions instead of ^1.2.3
save-exact=true
# npm 11 and older: never run install scripts
# ignore-scripts=true
.github/dependabot.ymltext
# .github/dependabot.yml
version: 2
updates:
  - package-ecosystem: "npm"
    directory: "/"
    schedule:
      interval: "weekly"
    cooldown:
      default-days: 5
      semver-major-days: 30

Dependabot does not delay security updates, and npm and pnpm let you bypass the delay for a single install (--min-release-age=0 in npm, an exclude list in pnpm). For rolling out urgent runtime patches, see our guide on Node.js security updates.

npm audit, provenance and vetting a package

npm audit checks your dependency tree against a database of known vulnerabilities. Useful, but blind to a fresh attack: in the first hours there is no advisory yet. npm audit signatures verifies registry signatures and provenance attestations of what you installed.

Provenance is a signed record of which repository, commit and workflow built a package. Look at it, but do not lean on it: the poisoned @asyncapi versions went out through the project's real release workflow with valid provenance, and Microsoft reports that ChainDrop could publish through trusted publishing. The real warning sign is a package that always shipped with provenance suddenly releasing a version without it.

Before adding a new dependency, spend two minutes on this:

Vet a package without installing itbash
# release dates and maintainers
npm view left-pad time --json
npm view left-pad maintainers

# does the manifest declare install scripts?
npm view left-pad scripts

# download the tarball and list its files without installing
npm pack left-pad
tar -tzf left-pad-*.tgz
  • a fresh release of a package that has not changed in years, as in PolinRider;
  • a new maintainer or ownership change shortly before the release;
  • install scripts that were not there before;
  • minified or obfuscated code in a package that used to be readable;
  • a name one character away from a popular package.

CI secrets: short-lived tokens, OIDC, least privilege

The 2026 worms hunt for CI tokens first, because that is where publish and cloud credentials live. Three rules:

  1. Minimal permissions. Set contents: read at the workflow level and widen it only for the job that needs more. persist-credentials: false keeps the token out of .git/config for later steps.
  2. Publish with OIDC instead of an npm token. Trusted publishing issues short-lived credentials for a single run, so there is nothing long-lived to steal. It needs npm CLI 11.5.1+ and Node 22.14+, and supports GitHub Actions, GitLab CI/CD and CircleCI on cloud runners.
  3. Granular tokens with short expiry. If you cannot avoid a token, restrict packages, expiry, IP range and permissions. Classic npm tokens were removed in November 2025, and the npm docs say direct publishing with granular tokens goes away in January 2027, leaving stage-only tokens and trusted publishing.
A locked-down CI workflowtext
# .github/workflows/ci.yml
name: ci
on:
  pull_request:
  push:
    branches: [main]

# read-only token by default
permissions:
  contents: read

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          persist-credentials: false
      - uses: actions/setup-node@v7
        with:
          node-version: 24
      - run: npm ci
      - run: npm test

Why pull_request_target is dangerous

pull_request_target runs in the context of the base branch, with secrets and a write token. If such a workflow checks out code from a fork's pull request and runs it, you have handed your secrets to the PR author. According to Microsoft, this is how the @asyncapi bot token was obtained.

Never do thistext
# DANGEROUS: the pattern behind the @asyncapi compromise
on: pull_request_target
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          ref: ${{ github.event.pull_request.head.sha }}
      - run: npm install && npm test   # untrusted code with access to secrets

Build and test external PRs with plain pull_request, which has no secrets. If you need pull_request_target for labels or comments, do not check out or execute the PR head.

Publishing without a token

Trusted publishing from GitHub Actionstext
# .github/workflows/publish.yml: publishing without an npm token (trusted publishing)
name: publish
on:
  push:
    tags: ['v*']

permissions:
  contents: read
  id-token: write

jobs:
  publish:
    runs-on: ubuntu-latest
    environment: npm-release
    steps:
      - uses: actions/checkout@v7
        with:
          persist-credentials: false
      - uses: actions/setup-node@v7
        with:
          node-version: 24
          registry-url: 'https://registry.npmjs.org'
      - run: npm ci
      - run: npm test
      - run: npm publish

Once the trusted publisher is configured on npmjs.com, enable "Require two-factor authentication and disallow tokens" in the package settings, so a stolen token cannot publish. A dedicated environment with required reviewers stops a single push from shipping a release.

What to do if you installed a compromised package

Assume that everything the machine and CI could reach at install time is now in the attacker's hands. Order matters:

  1. Isolate. Take the machine off the network or at least stop working on it; halt CI runs that installed dependencies.
  2. Confirm what was installed. Find the version in the lockfile and in CI caches, including transitive references, and compare it with the version list from the researchers' write-up.
  3. Revoke and reissue every credential from a clean machine. npm, GitHub (personal access tokens, SSH keys, deploy keys), cloud, databases, API keys in .env. New tokens created on an infected machine get stolen the same way.
  4. Audit GitHub. New or modified files in .github/, unknown branches and commits, new repositories, added keys and apps. Microsoft reports that ChainDrop planted editor configs and setup scripts in repositories to persist. Settings that keep one stolen GitHub account from reaching production are in our breakdown of the 1Password breach.
  5. Check your releases. Did new versions of your packages appear during the window (npm view pkg time)? If so, deprecate or unpublish them and tell your users.
  6. Rebuild from scratch. Clear node_modules, npm/yarn/pnpm caches, CI caches and base images, then install a known-good version.
First commandsbash
# 1. is a compromised version anywhere in the tree (transitive included)?
npm ls keyv flat-cache --all
grep -n '"node_modules/keyv"' -A 3 package-lock.json

# 2. wipe dependencies and the cache, locally and in CI
rm -rf node_modules
npm cache clean --force

# 3. list and revoke npm tokens (from a clean machine)
npm token list
npm token revoke <id>

Quick checklist

  • npm ci in CI and on servers, lockfile diffs reviewed;
  • npm 12 or ignore-scripts, with an allowlist for native packages only;
  • min-release-age / minimumReleaseAge / cooldown set to 3–7 days;
  • permissions: contents: read, and no checkout of untrusted code in pull_request_target;
  • trusted publishing, with tokens disallowed in package settings;
  • an incident plan written down before you need it.

Fewer dependencies mean a smaller attack surface. The Sitecog widget, for example, loads as a single script from the Sitecog domain and adds no npm dependencies to your site's project.

Frequently asked questions

Does package-lock.json protect against malicious packages?

Partly. The lockfile pins exact versions and integrity hashes, and npm ci installs exactly those, so a freshly published malicious version will not slip in on its own. But if the bad version is already recorded in the lockfile because someone updated at the wrong moment, it will be reinstalled faithfully every time. Combine the lockfile with a release-age delay and review lockfile diffs.

Is pnpm or Yarn safer than npm?

Not by default in every respect. pnpm blocked dependency build scripts earlier than npm and can refuse versions that are too new (minimumReleaseAge). Since npm 12 shipped in July 2026, npm also blocks dependency install scripts by default and supports min-release-age. No package manager protects you from code that runs on import, or from long-lived tokens sitting in CI.

Does --ignore-scripts stop every npm attack?

No. It disables preinstall, install and postinstall, which is how ChainDrop and Mini Shai-Hulud executed. In the July 2026 @asyncapi compromise, though, the payload ran when the module was imported, and Microsoft notes that ignoring scripts did not help. Treat it as the first layer, not the only one.

What is npm provenance and does it prove a package is safe?

Provenance is a signed statement of which repository, commit and workflow built the package. It proves origin, not intent: the malicious @asyncapi versions were published by the project's real release workflow and carried valid provenance. A package that always had provenance suddenly publishing without it is a red flag; having it is not a reason to trust blindly.

How do I check an npm package before installing it?

Look at when the version was published (npm view pkg time), who published it and whether maintainers changed, whether it declares install scripts (npm view pkg scripts), and what is inside the tarball (npm pack, no install). Be suspicious of a new release of a long-dormant package, a new maintainer, obfuscated code and network calls during install.

Should I upgrade to npm 12?

If your project and CI are ready, yes: the headline change is that dependency install scripts no longer run without explicit approval. Before switching, run npm approve-scripts --allow-scripts-pending on npm 11.16 or later to see which packages would stop building, and approve only the ones you need.