On this page

TanStack npm Supply Chain Compromise (May 2026)

On 11 May 2026, between 19:20 and 19:26 UTC, an attacker published 84 malicious versions across 42 @tanstack/* npm packages, two versions per package, about six minutes apart. The affected packages were the Router and Start families: @tanstack/react-router, @tanstack/router-core, @tanstack/react-start, @tanstack/router-plugin and their siblings. No maintainer account was phished and no npm token was stolen. The attacker never touched the publish step of the release workflow.

Instead, they chained three weaknesses that are each well known on their own:

  1. A pull_request_target "Pwn Request": a workflow that ran with base-repository privileges built code from an untrusted fork.
  2. GitHub Actions cache poisoning: that build wrote a poisoned pnpm store into the cache scope shared with main.
  3. OIDC token extraction from runner memory: when the real release workflow later restored that cache, attacker code ran inside it and read the short-lived OIDC token the job had been granted for npm trusted publishing.

The result was a set of malicious packages that came out of TanStack's own release pipeline, under TanStack's own trusted-publisher identity, carrying valid SLSA Build Level 3 provenance. StepSecurity called it "the first documented npm worm that produces validly-attested malicious packages" (StepSecurity). The incident is tracked as CVE-2026-45321 / GHSA-g7cv-rxg3-hmpx, CVSS 9.6.

This page is the case study on why "we use OIDC trusted publishing and provenance" is necessary but not sufficient.

TL;DR

What84 malicious versions of 42 @tanstack/* packages published to npm
When2026-05-11, 19:20–19:26 UTC (publish window). Cache poisoned at 11:29 UTC the same day
Howpull_request_target workflow built fork code → poisoned the GitHub Actions cache under refs/heads/main → release workflow restored it → malware read the OIDC token from Runner.Worker memory and published directly to the npm registry
Payload~2.3 MB obfuscated router_init.js, run at install time via an optionalDependencies entry whose prepare script executes. Steals cloud, Kubernetes, Vault, npm, GitHub and SSH credentials, exfiltrates over Session/Oxen infrastructure, republishes the victim's own packages
DetectionExternal. StepSecurity opened TanStack/router issue #7383 at 19:46:46 UTC, ~26 minutes after the first publish
ContainmentAll 84 versions deprecated by 21:03 UTC. npm finished removing tarballs at 23:55:26 UTC
CampaignPart of the "Mini Shai-Hulud" worm wave that also reached Mistral AI, UiPath, OpenSearch, Guardrails AI and others. StepSecurity attributes it to TeamPCP
Core lessonProvenance proves which pipeline built an artifact, not that the pipeline was behaving. Anything that can put bytes into the release job (caches, actions, dependencies) is part of your trusted computing base

The Alert

At 19:46:46 UTC on 11 May, Ashish Kurmi of StepSecurity opened TanStack/router issue #7383, initially listing 14 of the 42 affected packages. StepSecurity's automated package analysis had flagged the new versions within minutes of publication (StepSecurity). The signals were mundane and loud:

  • the tarball was roughly 3.7x larger than the previous clean version (about 900 KB instead of about 190 KB);
  • a new file, router_init.js, sat at the package root;
  • package.json had gained an optionalDependencies entry pointing at a github: URL pinned to a commit hash;
  • every affected package had two releases a few minutes apart.

TanStack's postmortem is blunt about what this means: detection was external. There was "no internal alerting" (TanStack postmortem). Socket.dev also phoned Tanner Linsley shortly after the war room started.

What made this one different

In the axios compromise, the attacker had a stolen long-lived npm token. In LiteLLM, they had a stolen PyPI token. Here there was no token to steal in advance. TanStack already used OIDC trusted publishing, so the only credential was minted per run, inside the release job, and lived for minutes. The attacker got around that by getting their code to run inside the release job.

Impact

  • Packages: 42 @tanstack/* packages, 84 versions. All in the Router/Start monorepo. TanStack and Snyk confirmed that the query*, table*, form*, virtual* and store families, and the @tanstack/start meta-package, were not affected (TanStack, Snyk).
  • Severity: CVSS 3.1 9.6 Critical, CWE-506 Embedded Malicious Code (GHSA-g7cv-rxg3-hmpx).
  • Exposure window on npm: about 1h43m from first publish to full deprecation, about 4h35m until the last tarball was removed.
  • Downloads: unknown. TanStack lists the number of downloads as an open question in its postmortem. Treat any public figure you see as an estimate.
  • Who is affected: GitHub's advisory says any developer or CI machine that installed an affected version via npm, pnpm or yarn on 2026-05-11 "should be considered compromised" (GHSA).
  • Downstream spread: the payload is a worm. Socket and StepSecurity tracked the same injection in packages from Mistral AI (including PyPI mistralai 2.4.6), Guardrails AI (PyPI guardrails-ai 0.10.1), UiPath, OpenSearch, DraftLab and others, with StepSecurity reporting more than 170 packages by its later updates (The Register, StepSecurity, The Hacker News).
  • Second-order victims: the Nx team later said one of its developers' systems was compromised following the TanStack attack, which led to the malicious Nx Console 18.95.0 VS Code extension and, through it, the breach of about 3,800 GitHub-internal repositories (The Hacker News). Kodem reported that two OpenAI employee devices were also reached (Kodem). These links in the chain come from secondary reporting and vendor statements, not from TanStack's postmortem.

Timeline

All times UTC. Unless noted, from the TanStack postmortem (including its 2026-05-15 corrections).

sequenceDiagram
    participant A as Attacker fork
    participant PRT as bundle-size.yml PR-target job
    participant C as Actions cache main scope
    participant R as release.yml
    participant N as "npm registry"
    participant S as StepSecurity

    Note over A: 05-10 17:16 — fork zblgg/configuration created
    A->>PRT: 05-11 ~10:49 — PR #7378 opened
    PRT->>PRT: 11:11 — builds fork code, vite_setup.mjs runs
    PRT->>C: 11:29 — saves 1.1 GB pnpm-store entry
    A->>A: 11:31 — PR reset to no-op and closed
    Note over C: Poisoned entry stays in cache
    R->>C: 19:15 and 19:16 — two release runs restore the cache
    R->>R: Malware reads OIDC token from Runner.Worker memory
    R->>N: 19:20:39 — first batch of 42 versions
    R->>N: 19:26:14 — second batch of 42 versions
    S->>S: 19:46:46 — opens issue #7383
    N->>N: 21:03 — all 84 versions deprecated
    N->>N: 22:13 to 23:55 — tarballs removed
Time (UTC)EventSource
2026-03-19Attacker account voicproducoes (ID 269549300) createdStepSecurity
05-10 17:16Fork zblgg/configuration created: a fork of TanStack/router renamed so it would not show up when searching the fork listTanStack
05-10 23:29Malicious commit authored under a fake claude <claude@users.noreply.github.com> identity. It adds packages/history/vite_setup.mjs (about 30,000 lines) with a [skip ci] messageTanStack
05-11 ~10:49PR #7378 "WIP: simplify history build" opened. bundle-size.yml and labeler.yml (both pull_request_target) run without first-time-contributor approval. pr.yml (pull_request) stays blocked waiting for approvalTanStack
11:01–11:11Several force-pushes trigger more runs. At 11:11 the malicious commit is on the PR head and the benchmark-pr job checks out refs/pull/7378/merge, runs pnpm install and the bundle-size build, which executes vite_setup.mjsTanStack
11:29A 1.1 GB cache entry Linux-pnpm-store-6f9233a5… is saved under scope refs/heads/mainTanStack
11:31PR reset to main HEAD b1c061af (a zero-file no-op), closed, branch deleted. The poisoned cache staysTanStack
19:15:44Release run 25613093674 is re-run (attempt #4). Its original trigger was PR #7369, merged 05-09. It restores the poisoned cacheTanStack
19:16:18Merge of PR #7382 triggers release run 25691781302, which restores the same cache at 19:16:22TanStack
19:20:39First batch published (@tanstack/history@1.161.9 and 41 siblings), authenticated via OIDC trusted publishing. The "Publish Packages" step was skipped because tests failed. The malware minted a token and POSTed to registry.npmjs.org directlyTanStack
19:20:48That release run ends in failureTanStack
19:26:14Second batch published (e.g. history@1.161.12). Run fails at 19:26:22TanStack
19:46:46StepSecurity opens issue #7383TanStack, StepSecurity
~19:50npm security notified by the researcherTanStack
~20:10Other team members' push permissions removedTanStack
20:19history@1.161.9 and @1.161.12 deprecatedTanStack
20:41Initial 14 packages (28 versions) deprecatedTanStack
~21:00Scan of all 295 TanStack packages confirms scope, public disclosureTanStack
21:03All 84 versions deprecatedTanStack
21:30Attack vector identified. All TanStack caches purged via API. Hardening PR merged (bundle-size.yml restructured, repository_owner guards, third-party actions pinned to SHAs). GHSA published and CVE requestedTanStack, The Register
22:13:38–23:55:26npm removes the tarballs, query-core first and router-core last. TanStack's correction notes that these removals were triggered by StepSecurity's reportTanStack
05-12 05:02IOC email to npm and GitHub security, formal malware reports filedTanStack
05-12Advisory added to the GitHub Advisory Database and published to NVD as CVE-2026-45321GHSA
05-15Postmortem updated to "All clear". Only the Router/Start repo was affected and every version now on npm is described as safe to installTanStack

Response speed

MilestoneFrom first publishFrom public report
Public detection~26 min—
First deprecation~59 min~33 min
Full deprecation~1h43m~1h17m
Last npm tarball removal~4h35m~4h09m

From the TanStack postmortem. The gap between deprecation and removal matters. A deprecated version is still installable. TanStack notes that npm's policy on packages with dependents blocked unpublishing, so the registry security team had to remove tarballs.

Root Cause

TanStack's summary: "Three vulnerabilities chained together. Each is necessary for the attack; none alone is sufficient." Each one is worth understanding on its own, because each is common in open-source CI.

flowchart TD
    F["Attacker fork<br/>zblgg/configuration"] -->|"PR #7378"| PRT["bundle-size.yml<br/>on: pull_request_target"]
    PRT -->|"checks out refs/pull/N/merge<br/>runs pnpm install + build"| EXE["Fork code executes<br/>with base-repo context"]
    EXE -->|"writes into pnpm store"| SAVE["actions/cache post-step<br/>saves entry"]
    SAVE -->|"scope: refs/heads/main<br/>key: Linux-pnpm-store-hash"| CACHE[("Shared Actions cache")]
    PUSH["Legit push to main"] --> REL["release.yml<br/>permissions: id-token write"]
    CACHE -->|"cache hit on same key"| REL
    REL -->|"poisoned store used<br/>during install/test"| MAL["Malware inside release job"]
    MAL -->|"reads Runner.Worker memory"| TOK["OIDC token"]
    TOK -->|"exchanged for npm publish auth"| NPM["registry.npmjs.org<br/>84 versions + valid provenance"]

    style F fill:#ff6b6b,color:#fff
    style CACHE fill:#cc5500,color:#fff
    style MAL fill:#ff6b6b,color:#fff
    style NPM fill:#ff6b6b,color:#fff

GitHub has two triggers for pull requests:

TriggerRuns which workflow fileToken permissionsSecretsTypical use
pull_requestFrom the PR head (the fork)Read-only for forksNot available to forksBuild and test untrusted code
pull_request_targetFrom the base branchCan be writeAvailableLabel, comment, triage — things that must not run PR code

pull_request_target is safe as long as the job never executes code from the pull request. It becomes a "Pwn Request" (a term from GitHub Security Lab's 2021 research) the moment a job checks out the fork's code and runs something that executes it — pnpm install (lifecycle scripts), a build, a test, a bundler config.

TanStack's bundle-size.yml did exactly that: it checked out refs/pull/7378/merge and ran pnpm install plus a build in order to measure bundle size. The repository had tried to split trust (the benchmark-pr job had limited permissions:) but, as the postmortem puts it, that split missed two facts:

  • The actions/cache post-job save "is not gated by permissions:". Reducing the GITHUB_TOKEN scope does not stop the cache action from saving an entry at the end of the job. The cache service uses its own runtime token.
  • Cache scope is shared between pull_request_target runs and pushes to main, because pull_request_target runs in the context of the base branch.

Note also that the first-time-contributor approval gate only blocked pr.yml (the pull_request workflow). The pull_request_target workflows ran without approval — that is by design, because they are supposed to be safe.

GitHub Actions caches are scoped by branch. A run can read caches from its own ref and from the default branch. Because a pull_request_target run executes in the base branch's context, the entry it saved landed under refs/heads/main — the same scope a push to main reads from.

The cache key was deterministic and public:

# The shape of the key (from the postmortem). Anyone who can read the lockfile can compute it.
key: Linux-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}

The attacker's build wrote a modified pnpm store, and the cache action's post step saved it as a 1.1 GB entry under that exact key. When release.yml later ran on main, it looked up the same key, got a hit, and restored the attacker's store "entirely as designed."

Caches are inputs, not optimizations

Most teams think of the CI cache as a speed-up that can at worst be stale. In a release job it is an untrusted input that skips verification. A cache hit means "I already have these bytes, don't fetch them again". The lockfile integrity check never sees them. TanStack credits this attack class to Adnan Khan's 2024 research on GitHub Actions cache poisoning.

The attacker then made the PR disappear: at 11:31 the branch was reset to an empty diff, the PR closed and the branch deleted. Nothing in the repository's visible history pointed at what had just happened, and the poisoned entry sat in the cache for eight hours.

TanStack's release workflow used npm trusted publishing: the job has permissions: id-token: write, asks GitHub's OIDC provider for a short-lived token whose claims identify the repository and workflow, and npm exchanges that for publish rights. There is no long-lived NPM_TOKEN secret anywhere.

The weakness is that any process running in the job can obtain that token. According to the postmortem, the attacker's code located the Runner.Worker process via /proc/*/cmdline and read its memory to extract the token. The script was copied verbatim from the March 2025 tj-actions/changed-files compromise, attribution comment included. The Register notes the same reuse (The Register).

On GitHub-hosted Linux runners the job runs as a user with passwordless sudo, so in-job code can read other in-job processes' memory. There is no in-job boundary between "the publish step" and "a test helper". The id-token: write permission is granted to the job, not to a step.

That explains the strangest detail in the timeline: the "Publish Packages" step was skipped, because the tests failed (the payload broke them). The malware did not need that step. It minted its own publish authorization during the test/cleanup phase and called the registry API directly.

Why provenance did not help

The malicious versions carried valid SLSA Build Level 3 provenance, signed through Sigstore and logged in Rekor (StepSecurity, Snyk). npm audit signatures would have reported them as verified.

That is correct behaviour. Provenance answers a narrow question:

"Was this artifact produced by workflow release.yml in repository TanStack/router, at commit X, on a GitHub-hosted runner?"

and for these versions the honest answer was yes. StepSecurity's summary is the line to remember: "SLSA provenance confirms which pipeline produced the artifact, not whether the pipeline was behaving as intended."

flowchart LR
    subgraph attested["What provenance attests"]
        P1["Source repo + commit"]
        P2["Workflow file + trigger"]
        P3["Builder identity<br/>GitHub-hosted runner"]
    end
    subgraph unattested["What it does NOT attest"]
        U1["Contents of restored caches"]
        U2["Third-party actions at run time"]
        U3["Code that ran in other steps"]
        U4["That the publish step was the one publishing"]
    end
    attested --> V["npm audit signatures: verified"]
    unattested --> M["Malicious tarball"]
    V --- M

SLSA Build L3 requires that the build platform prevents runs from influencing each other and that signing material is not accessible to user-defined build steps. A shared cache that a lower-trust run can write and a higher-trust run reads is exactly the kind of cross-run influence the spec is trying to rule out, and the job-wide OIDC token, which is what gets exchanged for the signing certificate, was reachable from user-defined steps. The provenance was "valid" because the platform generated it, but the isolation it implied did not hold in this configuration.

StepSecurity also reports that the worm can generate provenance for packages it republishes elsewhere, by using stolen CI OIDC tokens to get Fulcio certificates. How that relates to the TanStack publishes is not clarified in their write-up.

Provenance is still worth having. It turned an investigation that could have taken days into minutes, because it pointed straight at run IDs 25613093674 and 25691781302. It is a forensics and policy tool. It is not a malware scanner.

The Payload

This section stays at the level needed for detection. The GHSA, TanStack postmortem and StepSecurity carry the full IOC lists.

Install-time execution

Each malicious version added an optionalDependencies entry:

"optionalDependencies": {
  "@tanstack/setup": "github:tanstack/router#79ac49eedf774dd4b0cfa308722bc463cfe5885c"
}

The commit is an orphan commit reachable through the fork network, so the github:tanstack/router#<sha> URL looks like it points at the official repository. npm, pnpm and yarn fetch git dependencies and run their prepare script when they pack them. That prepare script ran the ~2.3 MB obfuscated router_init.js (StepSecurity observed it running under Bun).

Two details make this worse than a plain postinstall:

  • Git dependencies run prepare as part of being fetched. Many people who know about postinstall do not think of prepare.
  • optionalDependencies failures are swallowed. If the payload's environment check failed, the install still succeeded.

What it took and where it went

CategoryTargets (from GHSA / TanStack / StepSecurity)
CloudAWS IMDS and Secrets Manager, ECS task credentials, GCP metadata
ClusterKubernetes service-account tokens, Vault tokens
Code hostingGitHub tokens (env, gh CLI, .git-credentials), ~/.npmrc
HostsSSH keys, shell history, more than 100 hard-coded file paths
CIRunner.Worker memory via /proc/<pid>/mem

Exfiltration went to Session/Oxen messenger file infrastructure (filev2.getsession.org, seed1–seed3.getsession.org). StepSecurity also documents GitHub GraphQL "dead-drop" commits with the message chore: update dependencies on branches named like Dependabot branches. The GHSA calls blocking the Session domains "the only network mitigation".

Worm behaviour

With an npm token or a CI OIDC token in hand, the payload lists other packages the same maintainer can publish and republishes them with the same injection. That is how it jumped from TanStack to unrelated organizations within hours.

Persistence and the "dead-man's switch"

StepSecurity documents persistence that targets developer tooling directly:

  • a .claude/settings.json SessionStart hook and a .vscode/tasks.json task with runOn: folderOpen, each launching a dropped setup.mjs;
  • a user-level gh-token-monitor service (~/Library/LaunchAgents/com.user.gh-token-monitor.plist on macOS, ~/.config/systemd/user/gh-token-monitor.service on Linux);
  • injected .github/workflows/codeql_analysis.yml workflows that dump toJSON(secrets).

Security researcher Nicholas Carlini described the payload as installing "a dead-man's switch… as a system user service" that watches whether a stolen GitHub token has been revoked and wipes the local disk if it has (The Register). StepSecurity found an npm token with the description IfYouRevokeThisTokenItWillWipeTheComputerOfTheOwner and advises isolating and imaging machines before revoking tokens.

Disputed / unverified

StepSecurity asserts the wipe-on-revoke behaviour but its write-up does not show the wipe code. Treat it as plausible and plan your response order around it (isolate, image, then rotate), but do not quote it as confirmed.

Detection

What actually detected it

External registry monitoring: StepSecurity's automated analysis, then Socket. Nothing inside TanStack fired. The postmortem lists "No internal alerting" as the first gap.

What could have detected it earlier

StageSignalWhere to look
PR openedpull_request_target workflow checking out refs/pull/*/merge or head.shaStatic workflow linting (zizmor, actionlint, GitHub code scanning for Actions)
11:29A 1.1 GB cache entry created from a pull_request_target runGET /repos/{owner}/{repo}/actions/caches — size and creating ref
19:16Release job opening /proc/<pid>/memRuntime monitoring on the runner (StepSecurity Harden-Runner, Falco-style rules)
19:20Publish from a run whose "Publish Packages" step was skippedCompare npm publish events with workflow step outcomes
19:20Egress from the release job to anything but GitHub and npmEgress allow-list on the runner
19:20New optionalDependencies with github: URL; tarball 3.7x biggerPre-publish diff of the packed tarball against the previous version
19:26Two versions of the same package minutes apartRegistry-side anomaly detection

A cheap internal control for maintainers: watch your own packages.

#!/usr/bin/env bash
# Alert if any package in a scope published a version in the last N minutes
# that was not produced by the expected workflow step. Run from a cron job.
# Simplification: polls the registry, a webhook from npm hooks would be lower latency.
set -euo pipefail
SCOPE="@tanstack"
SINCE=$(date -u -d '-15 minutes' +%s)

npm search "$SCOPE/" --json --searchlimit 300 | jq -r '.[].name' | while read -r pkg; do
  npm view "$pkg" time --json | jq -r --arg s "$SINCE" '
    to_entries[] | select(.key != "created" and .key != "modified")
    | select((.value | sub("\\.[0-9]+Z$"; "Z") | fromdateiso8601) > ($s|tonumber))
    | .key' | while read -r ver; do
      # Compare with your release log: which run published this, and did its publish step succeed?
      echo "NEW: $pkg@$ver"
  done
done

Checking whether you installed it

# Lockfiles: any of the 84 versions? (GHSA lists them all — this checks the signature instead)
grep -rn '"@tanstack/setup"' node_modules/*/package.json node_modules/@*/*/package.json 2>/dev/null
find node_modules -name router_init.js -maxdepth 4 2>/dev/null

# Persistence artifacts (macOS / Linux)
ls ~/Library/LaunchAgents/com.user.gh-token-monitor.plist 2>/dev/null
ls ~/.config/systemd/user/gh-token-monitor.service ~/.local/bin/gh-token-monitor.sh 2>/dev/null
grep -l 'setup.mjs' .claude/settings.json .vscode/tasks.json 2>/dev/null

# npm tokens you did not create
npm token list

The GHSA also recommends using npm pack to inspect a package version without running its scripts:

npm pack @tanstack/react-router@1.169.9 --dry-run --json | jq '.[0].files[].path' | grep -c router_init.js

Response and Remediation

What TanStack did

From the postmortem, in order:

  1. Stopped further publishing: removed other maintainers' push permissions (about 20:10).
  2. Deprecated the affected versions in three phases, all 84 by 21:03.
  3. Scanned all 295 packages to establish scope, then disclosed publicly.
  4. Purged every Actions cache via the API — the poisoned entry was the persistence mechanism inside their CI.
  5. Hardened the workflows the same evening: restructured bundle-size.yml, added github.repository_owner guards, pinned third-party actions to commit SHAs.
  6. Published GHSA-g7cv-rxg3-hmpx and requested a CVE.
  7. Worked with npm security to remove tarballs that could not be unpublished.
  8. Sent a full IOC list to npm and GitHub security.

Purging the cache is the step most teams would miss. Rotating credentials does nothing if the next release run restores the same poisoned entry.

# List and purge all Actions caches in a repo (requires gh CLI and admin rights)
gh cache list --repo TanStack/router --limit 1000
gh cache delete --all --repo TanStack/router

What consumers should do

From the GHSA, TanStack and StepSecurity:

  1. Isolate and image any machine or runner that installed an affected version on 2026-05-11, before revoking tokens (dead-man's switch concern).
  2. Remove persistence: the .claude/ and .vscode/ hooks, the gh-token-monitor service, any injected workflow files.
  3. Rotate everything the install could reach: AWS, GCP, Kubernetes, Vault, GitHub, npm and SSH credentials. In CI, rotate masked secrets too.
  4. Review cloud audit logs for activity from affected hosts.
  5. Upgrade to the patched versions in the GHSA table (for example @tanstack/react-router 1.169.9), delete node_modules and reinstall from a clean lockfile.
  6. Check your own packages: if your CI installed an affected version and holds publish rights, the worm may have republished your packages.
  7. Block *.getsession.org egress from build and developer networks.

What Would Have Prevented It

Every link in the chain had a known fix. Breaking any one of them would have stopped the publish.

1. Never run fork code under pull_request_target

The safe default is to build and test untrusted code under pull_request, which has no secrets and a read-only token, and to do any privileged follow-up (posting a bundle-size comment) in a separate workflow_run workflow that only consumes data, never code.

# .github/workflows/bundle-size.yml — UNPRIVILEGED: runs fork code, no secrets
name: bundle-size
on: pull_request
permissions:
  contents: read
jobs:
  measure:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@<full-commit-sha>   # pin by SHA
        with:
          persist-credentials: false
      - uses: pnpm/action-setup@<full-commit-sha>
      - run: pnpm install --frozen-lockfile --ignore-scripts
      - run: pnpm build && node scripts/bundle-size.mjs > size.json
      - uses: actions/upload-artifact@<full-commit-sha>
        with:
          name: bundle-size
          path: size.json
# .github/workflows/bundle-size-comment.yml — PRIVILEGED: never checks out PR code
name: bundle-size-comment
on:
  workflow_run:
    workflows: [bundle-size]
    types: [completed]
permissions:
  pull-requests: write
jobs:
  comment:
    if: github.event.workflow_run.conclusion == 'success'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/download-artifact@<full-commit-sha>
        with:
          name: bundle-size
          run-id: ${{ github.event.workflow_run.id }}
          github-token: ${{ secrets.GITHUB_TOKEN }}
      # Treat size.json as untrusted DATA: parse, validate numbers, never eval or exec it.
      - run: node -e 'const s=require("./size.json"); if (typeof s.bytes!=="number") process.exit(1)'

If you genuinely need pull_request_target (for labelling, for example), make it mechanically impossible to run PR code:

on: pull_request_target
permissions:
  pull-requests: write
jobs:
  label:
    # Guard against running in forks of your repo, as TanStack added
    if: github.repository_owner == 'TanStack'
    runs-on: ubuntu-latest
    steps:
      # No actions/checkout of the PR. No install. No build. No cache.
      - uses: actions/labeler@<full-commit-sha>

Then enforce it with a linter in CI, so the next person cannot reintroduce it:

# zizmor flags dangerous-triggers, cache-poisoning, unpinned-uses and more
pipx run zizmor .github/workflows/

Also turn on "Require approval for all outside collaborators" for fork PR workflows in repository settings. It would not have stopped pull_request_target here, but it closes the pull_request path that attackers try next.

2. Treat caches as untrusted in release jobs

Three independent controls, any of which breaks Link 2:

a. Do not restore caches in the release workflow. A release is rare. Spending two extra minutes downloading packages with lockfile integrity checks is cheap.

# release.yml
- uses: actions/setup-node@<full-commit-sha>
  with:
    node-version: 22
    registry-url: https://registry.npmjs.org
    # deliberately no `cache:` here
- run: npm ci --ignore-scripts

b. Never let low-trust workflows save caches. Use the split restore/save actions and only save from trusted events.

- uses: actions/cache/restore@<full-commit-sha>
  with:
    path: ~/.local/share/pnpm/store
    key: pnpm-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}
# ...build...
- if: github.event_name == 'push' && github.ref == 'refs/heads/main'
  uses: actions/cache/save@<full-commit-sha>
  with:
    path: ~/.local/share/pnpm/store
    key: pnpm-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}

Watch out for setup actions with built-in caching (actions/setup-node with cache:, pnpm/action-setup + setup-node cache, setup-python with cache:): they save in a post-step too.

c. Namespace release caches so nothing else can produce a matching key.

key: release-${{ github.workflow }}-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}

This is weaker than (a) or (b), since any job that can write a cache can write any key, but it defeats an attacker who only computes the obvious key.

There are reports that GitHub has since made cache writes read-only by default for low-trust triggers (Hive Security). We have not confirmed this against GitHub's own changelog. Do not rely on a platform default you have not checked.

3. Put the OIDC token in a job that runs nothing but publish

id-token: write is granted per job. So make the publishing job tiny: no install, no tests, no cache, no third-party actions beyond checkout and setup. It only downloads the tarballs a previous job built, checks them and publishes.

# release.yml
on:
  push:
    branches: [main]
permissions: {}            # nothing by default

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@<full-commit-sha>
        with: { persist-credentials: false }
      - uses: actions/setup-node@<full-commit-sha>
        with: { node-version: 22 }
      - run: npm ci --ignore-scripts
      - run: npm test
      - run: npm pack --pack-destination dist/
      - uses: actions/upload-artifact@<full-commit-sha>
        with: { name: tarballs, path: dist/*.tgz }

  publish:
    needs: build
    runs-on: ubuntu-latest
    environment: npm-release            # protected environment, see below
    permissions:
      id-token: write                   # ONLY this job can mint the OIDC token
      contents: read
    steps:
      - uses: actions/setup-node@<full-commit-sha>
        with:
          node-version: 22
          registry-url: https://registry.npmjs.org
      - uses: actions/download-artifact@<full-commit-sha>
        with: { name: tarballs, path: dist }
      - name: Refuse tarballs with git/URL deps or unexpected files
        run: |
          for t in dist/*.tgz; do
            tar -xOzf "$t" package/package.json \
              | jq -e '[.dependencies, .optionalDependencies, .peerDependencies]
                       | map(values // {} | to_entries[] | .value)
                       | all(test("^(github:|git\\+|https?:)") | not)' >/dev/null \
              || { echo "URL/git dependency in $t"; exit 1; }
          done
      - run: for t in dist/*.tgz; do npm publish "$t" --provenance --access public; done

Be honest about what this buys. If the build job is poisoned, it can still produce a malicious tarball, and the publish job will sign it. What it removes is the attacker's ability to mint tokens and publish arbitrary things directly from a test step, and it gives you one small, reviewable place to put content checks.

4. Harden the trusted-publisher binding

npm trusted publishing binds a package to a repository and a workflow file, and optionally to a GitHub environment. TanStack's postmortem lists the gap: "OIDC trusted-publisher binding has no per-publish review."

  • Bind the environment, not just the workflow. Then configure the npm-release environment in GitHub with required reviewers and deployment branch = main only. A token minted outside that environment will not match the trust policy, and a human must approve each publishing run.
  • Disallow token publishing in the npm package settings ("Require two-factor authentication and disallow tokens") once trusted publishing works, so a stolen classic or granular token cannot publish either.
  • Snyk recommends that the trusted-publisher record pins both the workflow (.github/workflows/release.yml) and branch refs/heads/main (Snyk).

A required reviewer would not have stopped this attack by itself if the reviewer approved a normal-looking release run. It does stop the re-run of an old release run (the 19:15:44 attempt #4) from silently publishing.

5. Pin third-party actions to commit SHAs

The token-scraping code came from the tj-actions compromise. TanStack pinned all third-party actions to SHAs as part of its fix. Tags are mutable, SHAs are not.

# BAD
- uses: some-org/some-action@v4
# GOOD (keep the tag as a comment so Dependabot/Renovate can still update it)
- uses: some-org/some-action@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v4.1.2

6. Contain what runs: egress allow-listing on runners

The release job needed to talk to github.com, api.github.com, the Actions services and registry.npmjs.org. It had no business talking to getsession.org. An egress allow-list would have blocked both the exfiltration and, depending on rules, the second-stage downloads.

# StepSecurity Harden-Runner in block mode (one option; self-hosted runners can use a proxy or firewall)
- uses: step-security/harden-runner@<full-commit-sha>
  with:
    egress-policy: block
    allowed-endpoints: >
      github.com:443
      api.github.com:443
      registry.npmjs.org:443
      objects.githubusercontent.com:443

7. On the consumer side: lockfiles, no scripts, and a cooldown

Most consumers were protected or exposed by three settings.

Use the lockfile, and do not run install scripts by default.

npm ci --ignore-scripts          # exact lockfile, integrity checked, no lifecycle scripts
pnpm install --frozen-lockfile   # pnpm 10 does not run dependency build scripts unless allow-listed
// package.json (pnpm 10+): explicit allow-list for packages that really need build scripts
{
  "pnpm": {
    "onlyBuiltDependencies": ["esbuild", "sharp"]
  }
}

Whether --ignore-scripts would have blocked this specific payload depends on the package manager and version, because the payload ran via a git dependency's prepare script, which package managers execute while preparing the git dependency. Do not assume; also block git and URL dependencies (below).

Refuse git/URL dependencies in third-party packages. A popular library suddenly depending on github:owner/repo#sha is a strong signal.

# Fail CI if the lockfile resolves anything from git or a tarball URL
if grep -nE '"resolved": "(git\+|https://codeload\.github\.com|github:)' package-lock.json; then
  echo "git/URL dependency found in lockfile"; exit 1
fi

Add a release-age cooldown. Every malicious version here was removed within about five hours. A one-day cooldown would have meant nobody using it ever resolved them.

# pnpm-workspace.yaml (pnpm 10.16+): ignore versions younger than 1440 minutes
minimumReleaseAge: 1440
# .yarnrc.yml (Yarn 4.10+)
npmMinimalAgeGate: "1d"
# npm: resolve as if it were yesterday (works with any npm version that supports --before)
npm install --before="$(date -u -d '-1 day' +%Y-%m-%dT%H:%M:%SZ)"

Dependabot and Renovate have equivalent settings (cooldown in Dependabot, minimumReleaseAge in Renovate). Pair the cooldown with an exception path for urgent security fixes.

Verify signatures, but don't stop there.

npm audit signatures   # catches tampering in transit and missing attestations
                       # does NOT catch a malicious build from the right pipeline

Control coverage

ControlLink 1 (Pwn Request)Link 2 (cache)Link 3 (OIDC theft)Consumer exposure
No PR code under pull_request_targetBlocks———
No cache in release job / no save from PR runs—Blocks——
id-token: write only in a minimal publish job——Reduces—
Environment with required reviewers——Reduces—
Actions pinned to SHAsReduces———
Runner egress allow-list——Blocks exfil—
Lockfile + npm ci———Protects existing pins
Release-age cooldown———Blocks (5h window)
Block git/URL dependencies———Blocks this payload's delivery
Provenance verification———Does not block

Lessons for System Design

Your trusted computing base is bigger than your code

The release pipeline's trust boundary included: the workflow file, every action it uses, every package it installs, every cache it restores, and every other workflow that can write into that cache. TanStack's split between "untrusted PR job" and "trusted release job" was real at the token level and imaginary at the cache level. When you draw a trust boundary, list the shared state that crosses it, not just the credentials.

Shared mutable state between trust levels is the bug

This is the same shape as a cache-poisoning attack on a web CDN or a shared Redis between tenants: a low-privilege writer and a high-privilege reader share a keyspace, and the key is predictable. The system design answer is the same too: partition by trust level (separate namespaces, separate stores, or no sharing at all on the high-trust path). In the language of cell architecture: releases should be their own cell.

Short-lived credentials limit replay, not use

OIDC trusted publishing removed the long-lived token, and that is why the attacker needed this elaborate chain at all. But a token that lives 10 minutes is enough if the attacker's code is running during those 10 minutes. Short-lived credentials must be paired with least privilege about who in the job can obtain them — which on today's runners means "put them in a job that runs nothing else".

Attestations are evidence, not verdicts

Provenance, SBOMs and signatures are excellent for answering "where did this come from?" after the fact. They are not a statement that the artifact is safe. Build policy on top of them (only accept artifacts from workflow X, on branch Y, from environment Z, with required review), and keep behavioural checks (tarball diff, new dependency types, egress) alongside.

Fail-loud saved everyone

The postmortem says the payload broke the tests, which made the attack loud. A careful attacker "could have published silently for hours longer." Detection relied on luck and on outside researchers. Build alerting that does not depend on the attacker making a mistake: publish events that do not match a successful publish step should page someone.

What Would You Do?

Scenario 1: You maintain a popular monorepo. A contributor-friendly workflow posts bundle-size diffs on PRs. It uses `pull_request_target` because it needs to comment, and it builds the PR to measure it. The job has `permissions: contents: read`. A colleague says this is safe because the token is read-only. Is it?

No. Read-only GITHUB_TOKEN does not stop the PR code from running, does not stop actions/cache from saving an entry at the end of the job (the cache save is not gated by permissions:), and the entry lands in the base branch's cache scope. That is exactly TanStack's Link 1 and Link 2. Split it: build under pull_request with no secrets, upload the numbers as an artifact, and comment from a workflow_run workflow that never checks out PR code.

Scenario 2: Your security tool reports a new version of a dependency with valid SLSA provenance from the project's official repo and workflow. A teammate wants to whitelist anything with valid provenance from the cooldown policy, so security fixes arrive faster. Do you agree?

No. The TanStack versions had valid SLSA Build L3 provenance from the official workflow. Provenance tells you which pipeline built the artifact. It does not tell you the pipeline was not compromised. Keep the cooldown. Use a separate, explicit fast path for known security releases (an advisory ID you have reviewed), not "has provenance".

Scenario 3: It is 20:00 UTC on 11 May. You learn your CI installed `@tanstack/react-router@1.169.5` an hour ago on a runner that also has an npm publish token for your own packages. What do you do first?

Isolate and preserve, then rotate, then check your own packages. Stop the affected runners and image them if self-hosted. Then rotate the npm token and every cloud credential the job could reach (the worm republishes the victim's packages, and StepSecurity reports a possible wipe-on-revoke behaviour on developer machines, which is why isolation comes before revocation there). Then check npm for any versions of your packages published since the install, deprecate them, and purge your own Actions caches in case anything was written there.

Scenario 4: After the incident your team proposes: "Remove `id-token: write` from the release job and go back to an `NPM_TOKEN` secret, since OIDC was what got stolen." Good idea?

No. The OIDC token was stolen because attacker code ran inside the job; an NPM_TOKEN secret in the same job would have been stolen just as easily (and would still be valid afterwards, as in the axios case). Keep OIDC, and fix the real problem: no untrusted inputs (caches, unpinned actions, scripts) in the job that holds the credential, environment protection with required reviewers, and egress controls.

Key Lessons

  • pull_request_target + checkout of PR code = Pwn Request. Build untrusted code under pull_request, and do privileged follow-up from workflow_run with data only.
  • Caches cross trust boundaries. A cache written by a PR-triggered run can be restored by a push to main. Do not restore caches in release jobs, and never save caches from low-trust events.
  • Restricting GITHUB_TOKEN permissions does not restrict the cache. The cache post-step saves regardless.
  • Any code in a job with id-token: write can mint the token. Give that permission only to a minimal publish job behind a protected environment.
  • Valid provenance ≠ safe package. It attests the pipeline, not the pipeline's behaviour.
  • Purge caches during incident response. Otherwise the next release re-infects you.
  • Consumers: cooldowns work. Every malicious version was gone within about five hours.
Quiz

Q1: Name the three techniques that were chained and explain why each was necessary. (1) A pull_request_target Pwn Request let fork code execute in the base repository's context. (2) Cache poisoning let that code persist into the refs/heads/main cache scope under the key the release workflow would look up. (3) OIDC token extraction from Runner.Worker memory let attacker code inside the release job obtain npm publish authorization. Without (1) the attacker's code never runs in a privileged context; without (2) it cannot reach the release job; without (3) it cannot publish.

Q2: The "Publish Packages" step was skipped because tests failed. How were the packages still published? The OIDC token permission (id-token: write) belongs to the whole job. Malware running during the install/test phase extracted the token from the runner process memory, exchanged it for npm publish authorization and called the registry API directly, independent of the publish step.

Q3: Why did npm audit signatures report the malicious versions as verified? Because they really were built and published by TanStack/router's release.yml on a GitHub-hosted runner with a valid OIDC identity. Sigstore signed the provenance and Rekor logged it. Provenance verifies origin, not intent or integrity of the build's inputs.

Q4: Why was purging the GitHub Actions cache a critical response step? The poisoned cache entry was the attacker's foothold inside CI. Any future release run with the same lockfile hash would have restored it and re-run the malware, even after every credential was rotated.

Q5: Which single consumer-side setting would have prevented installation of the malicious versions for teams that adopted it, and why? A release-age cooldown (for example pnpm minimumReleaseAge: 1440). All 84 versions were deprecated within about 1h43m and removed within about 4h35m, so a one-day cooldown would never have resolved them.

One-Liner Summary

A fork PR poisoned a GitHub Actions cache that TanStack's release job trusted, malware in that job lifted its OIDC token from memory, and 84 malicious packages shipped with perfectly valid provenance — proof that attestations tell you where a package came from, not whether it is safe.

Sources

Open questions (from TanStack's postmortem)

TanStack lists several questions it had not answered at the time of its last update, including how many times the malicious versions were downloaded, how the payload commit entered the fork, whether other forks host it, and whether any maintainer machine was separately compromised. This page will not guess at them.