Skip to content
Engineering

npm Supply-Chain Attacks: What Happened in 2025-2026 and the Defenses That Work

AIDToolStack EditorialNovember 7, 20268 min read
npmsupply chainsecurityNode.jsCI/CD
Share:Twitter

On 2 April 2026, two days after the compromise, the axios maintainers published a postmortem with a one-liner every JavaScript team should have run that week:

grep -E "axios@(1\.14\.1|0\.30\.4)|plain-crypto-js" package-lock.json yarn.lock 2>/dev/null

According to Jason Saayman's postmortem, two malicious axios versions went out through his compromised account and stayed live for about three hours. Neither touched axios's own code. Each added a new dependency, [email protected], whose postinstall hook ran node setup.js and dropped a remote access trojan, as Datadog Security Labs documented. If your CI ran a fresh npm install in that window, the trojan ran with whatever secrets the job had.

That's the shape of most npm incidents now. Nobody needs a bug in your code. They need one publish.

Four incidents, four different doors

The useful thing about these incidents is that each one got in a different way, so each one tests a different defense. All four have primary write-ups.

IncidentWhenHow the attacker got publish rightsWhat ran on victimsSource
Nx "s1ngularity"Aug 2025A pull_request_target workflow ran untrusted PR inputInstall-time credential huntingNx postmortem
Shai-HuludSep 2025Compromised maintainer accounts, then self-propagation with stolen credentialsCredential scanner that republished the victim's own packagesCISA alert
axiosMar 2026Social engineering and a RAT on the lead maintainer's PCpostinstall in an injected dependencyaxios postmortem
TanStackMay 2026CI cache poisoning plus an OIDC token read from runner memory~2.3 MB obfuscated script run during installTanStack postmortem

A few details matter more than the headlines. CISA counted over 500 packages hit by Shai-Hulud, which spread by using each victim's npm credentials to publish poisoned versions of their other packages. TanStack's attacker pushed 84 malicious versions across 42 @tanstack/* packages in six minutes, and the postmortem is blunt that "No npm tokens were stolen": the publish was authenticated through the project's own trusted-publisher binding. And in both axios and TanStack, detection came from outsiders. TanStack writes that it learned of the compromise "from a third party."

We've covered the Nx workflow mistake in depth in running AI coding agents in GitHub Actions, so I won't repeat it here.

Diagram of the three ways attackers got malicious versions onto npm in recent incidents (maintainer account, CI pipeline, worm reusing stolen tokens) and the consumer-side controls that sit between the registry and your machine
Diagram of the three ways attackers got malicious versions onto npm in recent incidents (maintainer account, CI pipeline, worm reusing stolen tokens) and the consumer-side controls that sit between the registry and your machine

The common thread: the malicious code executed at install time, before anyone imported anything. So the cheapest defenses are the ones that stop or delay install-time code.

If you consume packages: the npm 12 defaults help

npm 12.0.0 shipped on 8 July 2026, and its release notes contain the line that matters most for this post: "Dependency lifecycle scripts are now blocked by default unless allowed by the root package's allowScripts policy." As of November 2026 the current release is 12.2.2. If you're on an npm 11 that came bundled with Node, none of this applies until you upgrade npm itself.

Here's how the new install flow decides whether a dependency's preinstall, install or postinstall runs:

Flowchart of how npm 12 decides whether a dependency's install script runs: ignore-scripts wins, then explicit denials, then allowScripts approvals, otherwise the script is skipped with a warning or fails the install under strict-allow-scripts
Flowchart of how npm 12 decides whether a dependency's install script runs: ignore-scripts wins, then explicit denials, then allowScripts approvals, otherwise the script is skipped with a warning or fails the install under strict-allow-scripts

After an install, npm lists the packages whose scripts it skipped. You review them and record decisions with the install-scripts command:

npm install-scripts ls                 # what still needs a decision (read-only)
npm install-scripts approve canvas sharp    # pinned to the installed versions
npm install-scripts deny telemetry-pkg      # explicit false, survives "approve --all"
npm rebuild                            # run the scripts you just approved

Approvals are written to allowScripts in package.json and pinned to the exact version you reviewed by default, so a new release of an approved package has to be reviewed again. Commit that field. npm approve-scripts and npm deny-scripts are aliases, which is why GitHub's pre-release changelog uses those names.

For CI I'd also turn warnings into failures, so a new unreviewed script breaks the build instead of being silently skipped:

# .npmrc (committed)
strict-allow-scripts=true
min-release-age=7
min-release-age-exclude[]=@myorg/*

strict-allow-scripts makes any unreviewed install script fail the install. min-release-age only installs versions published more than the given number of days ago, and the exclude list lets your own scoped packages update immediately (the example is straight from npm's config definitions). A seven-day cooldown would have skipped both the axios and TanStack versions: axios's were gone in about three hours and TanStack's tarballs were removed the same evening. The trade-off is that urgent security fixes also wait, and npm warns and exits non-zero when the window blocks an npm audit fix.

Two other npm 12 defaults close side doors. allow-git and allow-remote now default to none, so a transitive dependency can't pull from a git repo or an arbitrary tarball URL unless you opt in. And --ignore-scripts still exists and still overrides everything, which is the right setting for jobs that only lint or test pure-JS code.

The parts that haven't changed

  • Commit the lockfile and use npm ci in CI. npm ci errors if the lockfile and package.json disagree and never writes to either, so CI installs exactly what you reviewed. npm 12 also dropped npm-shrinkwrap.json entirely; rename it to package-lock.json if you still have one.
  • Verify signatures. npm audit signatures checks registry signatures and provenance attestations for everything installed. The npm docs note this "often means updating npm beyond the version that ships with Node.js."
  • Keep the blast radius small. Install-time malware steals what the process can read. Don't give the install step deploy keys or cloud credentials it doesn't need; split install and deploy into separate jobs.

pnpm users

pnpm got there earlier. Its dependency-resolution settings default minimumReleaseAge to 1440 minutes (one day) and blockExoticSubdeps to true, so only your direct dependencies may come from git or tarball URLs. The setting I'd add is trustPolicy: no-downgrade, which fails the install when a package's trust level drops compared with earlier releases. That is exactly the axios signal: Datadog notes that axios 1.14.0 was published through trusted publishing and for 1.14.1 "the trustedPublisher field is absent." Our pnpm vs npm and Yarn comparison covers the rest of the differences.

If you publish packages: no long-lived tokens

npm's account side changed a lot after Shai-Hulud. GitHub announced the plan on 22 September 2025, and the 9 December 2025 changelog made it real: all classic tokens were permanently revoked, npm login now gives a two-hour session, and granular write tokens are capped at 90 days.

The better answer is to have no token at all. Trusted publishing lets GitHub Actions, GitLab CI/CD or CircleCI publish with a short-lived OIDC credential. It needs npm 11.5.1+ and Node 22.14.0+, and only works on cloud-hosted runners:

name: Publish
on:
  push:
    tags: ['v*']
permissions:
  id-token: write   # required for OIDC
  contents: read
jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@<full-commit-sha>
      - uses: actions/setup-node@<full-commit-sha>
        with:
          node-version: 24
          registry-url: https://registry.npmjs.org
      - run: npm install -g [email protected]   # stage publish needs 11.15.0+
      - run: npm ci
      - run: npm test
      - run: npm stage publish

Publishing this way from GitHub Actions or GitLab also generates a provenance attestation automatically for public packages from public repos. Be clear about what that proves. Provenance links a version to the repo and build that produced it. npm's docs say it does not guarantee the package is free of malicious code. TanStack's malicious versions came out of the real pipeline.

That's why the last line says npm stage publish rather than npm publish. Staged publishing went generally available in May 2026 for npm 11.15.0 and later: CI uploads to a queue, and nothing is installable until a maintainer approves it with a 2FA challenge. Since October 2026 it works for a package's first version too. It directly answers the gap TanStack's postmortem calls out, the lack of per-publish review in OIDC publishing. Once trusted publishing works, npm's docs recommend setting the package to "Require two-factor authentication and disallow tokens."

Also pin third-party actions to commit SHAs and audit any pull_request_target workflow: both the Nx and TanStack compromises started with one. Our GitHub Actions CI/CD patterns post has the permission and pinning basics.

If a bad version already ran

Assume the machine is compromised, not just the project. Combining the axios postmortem with CISA's Shai-Hulud alert:

  1. Find it: grep lockfiles (including nested ones) and any artifact caches for the affected versions.
  2. Pin back to the last known-good version and delete the malicious package from node_modules.
  3. Rotate every credential that machine or CI job could read: npm, GitHub, cloud keys, and secrets injected into the build.
  4. Check outbound network logs for the indicators in the advisory.
  5. Audit GitHub: unexpected public repos (Shai-Hulud pushed stolen secrets to one), webhooks, GitHub Apps and OAuth apps.

A short checklist

  • [ ] Lockfile committed; CI uses npm ci.
  • [ ] npm 12 or later everywhere, with allowScripts reviewed and committed and strict-allow-scripts=true in CI.
  • [ ] A release-age cooldown (min-release-age or pnpm's minimumReleaseAge) with an exclude list for your own scope.
  • [ ] npm audit signatures in CI.
  • [ ] Install jobs don't hold deploy credentials.
  • [ ] Publishing via trusted publishing plus npm stage publish, tokens disallowed on the package.
  • [ ] Dependency update PRs reviewed, not auto-merged: our post on Dependabot and Renovate covers cooldowns there, and the Dependabot config generator writes the YAML.
AE

Written by AIDToolStack Editorial

Researched from official documentation, specifications and vendor pages, listed under Sources below. Last checked November 2026.

Sources

  1. github.com/axios/axios/issues/10636
  2. securitylabs.datadoghq.com/articles/axios-npm-supply-chain-compromise/
  3. nx.dev/blog/s1ngularity-postmortem
  4. www.cisa.gov/news-events/alerts/2025/09/23/widespread-supply-chain-compromise-impacting-npm-ecosystem
  5. tanstack.com/blog/npm-supply-chain-compromise-postmortem
  6. github.com/npm/cli/releases/tag/v12.0.0
  7. github.com/npm/cli/blob/v12.2.2/docs/lib/content/commands/npm-install-scripts.md
  8. github.blog/changelog/2026-06-24-upcoming-breaking-changes-for-npm-v12/
  9. github.com/npm/cli/blob/v12.2.2/workspaces/config/lib/definitions/definitions.js
  10. github.com/npm/cli/blob/v12.2.2/docs/lib/content/commands/npm-ci.md
  11. github.com/npm/cli/blob/v12.2.2/docs/lib/content/commands/npm-audit.md
  12. pnpm.io/settings/dependency-resolution
  13. github.blog/security/supply-chain-security/our-plan-for-a-more-secure-npm-supply-chain/
  14. github.blog/changelog/2025-12-09-npm-classic-tokens-revoked-session-based-auth-and-cli-token-management-now-available/
  15. docs.npmjs.com/trusted-publishers
  16. docs.npmjs.com/generating-provenance-statements
  17. github.blog/changelog/2026-05-29-staged-publishing-and-new-install-time-controls-for-npm/
  18. github.blog/changelog/2026-10-02-npm-staged-publishing-now-supports-creating-new-packages
  19. github.com/npm/cli/releases
  20. github.com/npm/cli/blob/v12.2.2/docs/lib/content/commands/npm-approve-scripts.md

Related Posts

Explore on AIDToolStack

Discover tools and servers featured in our directory.

MCP Servers

Trigger.dev Jobs MCP ServerManage Trigger.dev background jobs from your AI coding assistant. Monitor job runs, trigger tasks manually, inspect execution logs, manage schedules, and debug failed runs. The server provides operational visibility into your background job infrastructure — see which tasks are running, queued, or failed, and take action. Your AI can help diagnose job failures from execution logs, retry failed tasks, and optimize concurrency configurations for better throughput.Tailscale Network MCP ServerManage your Tailscale mesh VPN network from your AI coding assistant. View connected devices, manage ACLs, configure exit nodes, check device status, and manage DNS settings. The server provides visibility into your Tailscale network — see which machines are online, troubleshoot connectivity issues, manage network access policies, and configure routes. Useful for developers managing distributed infrastructure where Tailscale provides secure networking between services.Portainer Docker MCP ServerManage Docker environments through Portainer's API from your AI coding assistant. Control containers, images, networks, and volumes across multiple Docker hosts and Kubernetes clusters. The server provides tools for container lifecycle management, image pulling and building, stack deployment, and resource monitoring. Portainer's multi-environment management makes this server particularly valuable for teams managing containers across development, staging, and production environments.

Reviews

Sign in to leave a review.

No reviews yet. Be the first!

Comments

Sign in to leave a comment.

No comments yet. Be the first!

Sponsor Our Newsletter

Reach thousands of developers who are actively evaluating AI tools, MCP servers, and dev infrastructure. Our weekly newsletter goes to engaged technical decision-makers.

Growing subscriber baseHigh open rates

All sponsored content is clearly labeled per our editorial policy.