The mechanism
A package worm needs two things from you: a resolver that will pick up a version published minutes ago, and a step that runs the package's code with your credentials in reach. Pinning, cooldowns and script controls each remove one of those. Provenance removes neither.
What a version range lets in
When you add a dependency, npm writes a range, not a version. The save-prefix default is ^, so a package at 1.2.3 is saved as ^1.2.3, "which allows minor upgrades for that package". Every dependency of that package carries its own ranges, so most of the tree your project installs is chosen by ranges you never wrote. Exact pins in your own package.json (save-exact) fix only the top layer. When the maintainer's phished account published debug@4.4.2 and chalk@5.6.1 on 8 September 2025, any ^4 range on debug or ^5 range on chalk, in your manifest or deep in someone else's, would accept them.
The lockfile is what fixes the whole tree. package-lock.json "describes the exact tree that was generated", and each entry records resolved (the tarball URL) and integrity, "a sha512 or sha1 Standard Subresource Integrity string for the artifact that was unpacked". npm's docs say the file "is intended to be committed into source repositories". Commit it, and a reinstall fetches the same bytes, checked by hash.
npm ci vs npm install
The two commands treat that lockfile differently:
npm installuses the lockfile "if the lockfile's resolved versions satisfy thepackage.jsonranges". If they don't, "npm resolves new versions that satisfy thepackage.jsonranges and updatespackage-lock.jsonaccordingly". When they conflict, "package.jsonwins and the lockfile is updated."npm ci"must have an existingpackage-lock.json". If the lockfile andpackage.jsondisagree, it "will exit with an error, instead of updating the package lock". It removes any existingnode_modulesfirst and "will never write topackage.jsonorpackage-lock.json: installs are essentially frozen."- pnpm's equivalent is
--frozen-lockfile, which "fails to install if the lockfile is out of sync with the manifest". It is on by default in CI when a lockfile is present.
So the lockfile protects only installs that read it. It does not cover the moments when you write it: the dependency-update pull request, a npm install some-package, a deleted and regenerated lockfile, or a one-off npx or npm install -g, which have no project lockfile at all. Those writes are when a worm gets in, which is why the next control exists.
Release-age cooldowns
A cooldown refuses any version younger than a set age, including transitive ones. The malicious TanStack and agent-framework versions below were pulled within hours, so even a one-day wait would have skipped them.
- pnpm
minimumReleaseAge, in minutes, added in 10.16.0 (12 September 2025). Since pnpm 11 (28 April 2026) it defaults to1440, one day: "Newly published packages will not be resolved until they are at least 1 day old." Two defaults weaken it. Unless you setminimumReleaseAgeyourself (on pnpm 11.0.4 or later, or 12.3.0 or later),minimumReleaseAgeStrictis off, and then pnpm "falls back to a version that doesn't meet the minimumReleaseAge constraint so installation can still succeed" when no older version fits the range. AndminimumReleaseAgeIgnoreMissingTimeistrue, so a private mirror that omits the registry'stimefield turns the check off for its packages.minimumReleaseAgeExcludeexempts named packages. - npm
min-release-age, in days, added in npm 11.10.0 (11 February 2026), defaultnull. npm installs "only versions that were available more than the given number of days ago", and errors if none fit. The olderbeforesetting takes an exact date. - Renovate
minimumReleaseAge(previouslystabilityDays) holds the update back and adds a pendingrenovate/stability-daysstatus check. Its docs give14 daysas an example, which "allows plenty of time to allow security researchers and automated security tools to catch malicious intent in packages", and suggest3 daysfor npm because packages under 72 hours old can still be unpublished. Renovate recommends setting a cooldown in both Renovate and the package manager, because a lockfile update "can lead to a transitive dependency being introduced" that Renovate's own check never saw. For npm, Renovate passes--beforewhen it regenerates the lockfile, unless.npmrcsetsmin-release-age, in which case npm applies its own window. - Yarn
npmMinimalAgeGate, from 4.10.0, per Renovate's docs. - Python: uv's
exclude-newertakes a date or a duration such as1 weekorP7D, compared against "the upload time of each individual distribution artifact". For Poetry, Renovate's docs listsolver.min-release-age(from 2.4.0).
The cost is that every fix waits too, security fixes included. The tools handle that differently. Renovate's security updates use the release age set under vulnerabilityAlerts, null by default, so they don't wait. pnpm audit --fix adds the patched version to minimumReleaseAgeExclude. With npm, when the window blocks a fix, npm audit fix "keeps the package at its vulnerable version, warns that the fix was blocked, and exits with a non-zero code"; you exempt the package with min-release-age-exclude.
Install scripts and git dependencies
Most worms run at install, through preinstall, install, postinstall or prepare. The defaults changed in the last two years:
- pnpm 10 (7 January 2025): "Lifecycle scripts of dependencies are not executed during installation by default!" pnpm 11 replaced the old settings with
allowBuilds, a map of packages totrueorfalse, and madestrictDepBuildsdefault totrue, so an install with unreviewed build scripts exits non-zero. pnpm 11 also defaultsblockExoticSubdepstotrue: only direct dependencies may come from git repositories or tarball URLs. - npm 12 (8 July 2026): "Dependency lifecycle scripts are now blocked by default unless allowed by the root package's
allowScriptspolicy."npm install-scripts approverecords approvals inpackage.json, pinned to the installed version by default (pkg@1.2.3). The same release madeallow-gitandallow-remotedefault tonone. npm 11 still runs dependency scripts by default. From 11.16.0 it reads the sameallowScriptsfield, but it only skips packages you have denied withfalse; an unreviewed script runs with a warning unless you setstrict-allow-scripts=true, which fails the install instead. Before 11.16.0, onlyignore-scripts(defaultfalse) stops them. --ignore-scripts(npm and pnpm) turns off every script, your own included; npm still runs a script you name withnpm test, but not its pre- or post-script. Use it where nothing needs to build.
Script controls only cover install time. The chalk and debug payload ran in the browser when an app used the code; Aikido says it "would be executed on the client of a website". Microsoft's poisoned agent-framework wheels used a .pth file, which Python runs every time it starts in that environment, so no install script was involved. A cooldown or a pin would have kept both out. A script policy wouldn't have.
Provenance and trusted publishing
npm provenance (npm publish --provenance, npm 9.5.0 or later, from a cloud-hosted CI runner) publishes a Sigstore-signed statement that links the package to its source repository and build. Trusted publishing goes further. From npm 11.5.1 (11.11.0 for CircleCI) it lets GitHub Actions, GitLab CI/CD or CircleCI publish with a short-lived OIDC credential instead of a stored token, and npm generates provenance automatically (except from CircleCI or a private repository). On PyPI, the token minted through a Trusted Publisher expires "no more than 15 minutes after the OIDC flow that authorizes them".
What this removes is the long-lived token that can be stolen, which is how Shai-Hulud republished packages in 2025. What it does not do, in the registries' own words:
- npm: "When a package in the npm registry has established provenance, it does not guarantee the package has no malicious code."
- PyPI: Trusted Publishing "does not assert the safety of the code or the trustworthiness of its authors", and "weaknesses in those workflows can be equivalent to credential compromise". The advice: "treat your Trusted Publishers *as if* they are API tokens."
Provenance answers "which workflow built this?" It cannot tell you whether that workflow was hijacked. The TanStack attack in May 2026 did exactly that:
Steps as text
- Fork pull request: pull_request_target ran the fork's code
- Cache poisoned: pnpm store saved under the release cache key
- Release restores it: the release workflow, hours later
- OIDC token read: from the runner process memory (where it breaks)
- Trusted publish: 84 versions, attested as TanStack's
- Victim installs: a git dependency's prepare script runs
The package-side checks are npm audit signatures, which reports how many installed packages have verified registry signatures and attestations, and pnpm's trustPolicy: no-downgrade (10.21.0, November 2025). It fails an install "if a package's trust level has decreased compared to previous releases — for example, if it was previously published by a trusted publisher but now only has provenance or no trust evidence." That catches a release made with a stolen token for a package that normally uses trusted publishing. By its own definition it cannot catch TanStack, whose malicious versions came from the same trusted publisher as the real ones.
For your own packages, npm recommends the setting "Require two-factor authentication and disallow tokens", and PyPI recommends a dedicated GitHub environment with required reviewers for the publishing job; npm's trusted publisher settings accept an environment name too. npm is also retiring direct publishing with tokens: "The ability to publish new package versions directly with a granular access token will be removed in January 2027."
Worked numbers
How long the bad versions were live, against common cooldowns. These are published figures. TanStack's last tarball was removed about 4 hours 35 minutes after the first malicious publish. Microsoft's agent-framework 1.26.1 went up at 20:35:20 UTC on 17 November 2026, and 1.26.2 was quarantined at 21:16:44, 41 minutes later. event-stream is the exception: flatmap-stream was added to it on 9 September 2018, and npm heard about the malware on 26 November, 78 days later.
Data as text
| Duration (hours) | |
|---|---|
| agent-framework, PyPI | 0.69 |
| TanStack, npm | 4.6 |
| event-stream, to report | 1,872 |
| Cooldown: pnpm 11 | 24 |
| Cooldown: Renovate npm | 72 |
| Cooldown: uv, 1 week | 168 |
A one-day cooldown outlasts both 2026 windows several times over. Against event-stream, a 7-day cooldown covers 7 of the 78 days, about 9%. Slow attacks are caught by reading what a lockfile diff adds, not by waiting.
Builds exposed in one window (illustrative). Inputs: 40 CI pipelines a day that depend on an affected @tanstack package through a ^ range and resolve dependencies fresh with npm (no committed lockfile), spread evenly. npm's resolver passes over a deprecated version when another version satisfies the range, so for these pipelines the window closed when TanStack had deprecated all 84 versions, 1 hour 43 minutes (1.72 hours) after the first publish. That's 40 × 1.72 / 24 ≈ 2.9, so about 3 pipelines install a credential stealer on runners that hold cloud and registry secrets. A pin to the exact bad version, or a pnpm release older than 11.28.0 and 12.6.0, which didn't skip deprecated versions, stayed exposed until npm removed the last tarball: 40 × 4.6 / 24 ≈ 7.7, about 8. With a committed lockfile and npm ci, the number is 0 unless someone merges a dependency update in those 4.6 hours. With a one-day cooldown as well, even that update would have resolved to the previous version.
What each control would have done (our reading of the published details).
| Incident | Where the code ran | Lockfile, frozen install | One-day cooldown | Script blocking | Provenance |
|---|---|---|---|---|---|
| event-stream, 2018 | At runtime, inside the Copay wallet app | Only if you didn't update for 78 days | No | No | Didn't exist yet |
| chalk and debug, Sept 2025 | At runtime, in browsers | Yes, unless you updated that day | Yes | No | No: no earlier provenance to compare |
| Shai-Hulud, Sept 2025 | postinstall | Yes, until you updated | Only for versions removed within a day | Yes | No: none of the packages we checked had provenance before |
| TanStack, May 2026 | prepare in a git dependency | Yes, until you updated | Yes, pulled within 4.6 hours | Yes; npm 12 also blocks git dependencies | Valid, so no help |
| agent-framework, Nov 2026 | Every Python start, via .pth | Yes, with a hash-pinned 1.26.0 | Yes, 41 minutes | No | None on the clean or the bad versions |
Script blocking misses the three rows whose code ran after install, and only a lockfile review catches event-stream; no single control covers every row.
How it fails
- A new maintainer (event-stream, September to November 2018). "The attacker, posing as a maintainer, took over maintainership of the
event-streammodule" and, on 9 September 2018, addedflatmap-streamas a direct dependency in event-stream 3.3.6. The malicious code wasflatmap-stream0.1.1. It targeted the Copay wallet, and was "designed to harvest account details and private keys" from accounts "having a balance of more than 100 Bitcoin or 1000 Bitcoin Cash". npm's security team was notified on 26 November and removed the packages. Nothing technical failed: a new maintainer added a new dependency, and no downstream review looked at it for 78 days. - A hijacked account (ua-parser-js, 22 October 2021). The maintainer wrote, "I believe someone was hijacking my npm account and published some compromised packages", and noticed when his email "was suddenly flooded by spams from hundreds of websites". Versions 0.7.29, 0.8.0 and 1.0.0 were malicious, fixed in 0.7.30, 0.8.1 and 1.0.1. GitHub's advisory: "Any computer that has this package installed or running should be considered fully compromised."
- A phished 2FA reset (chalk, debug and 16 more, 8 September 2025). "It was a 2FA reset email that looked shockingly authentic," the maintainer, Qix-, wrote; it came from
npmjs.help. Aikido's feed flagged the packages from 13:16 UTC; together they have "more than 2 billion downloads per week". The code hookedfetch,XMLHttpRequestand wallet interfaces to swap crypto addresses in browsers. At 21:59 CEST that day he relayed npm's message: "All impacted package versions have been taken down." - The first worm (Shai-Hulud, September 2025). GitHub was notified on 14 September. The worm got in through compromised maintainer accounts and injected "malicious post-install scripts". CISA says it authenticated "to the npm registry as the compromised developer" to republish other packages, and stole GitHub tokens and AWS, GCP and Azure keys. GitHub removed "500+ compromised packages". Among CISA's recommendations: "Pin npm package dependency versions to known safe releases produced prior to Sept. 16, 2025." A second wave in November 2025 ran "only during the preinstall phase"; Wiz counted over 25,000 affected repositories.
- A worm with valid provenance (TanStack, 11 May 2026). Between 19:20 and 19:26 UTC, 84 malicious versions of 42
@tanstack/*packages were published. GitHub's advisory says the publishes "were authenticated via the legitimate GitHub Actions OIDC trusted-publisher binding forTanStack/router", and Snyk calls it "the first npm supply chain attack with valid SLSA Build Level 3 attestations". TanStack says "No npm tokens were stolen". The chain is the one in the diagram: apull_request_targetworkflow, a poisoned cache, an OIDC token read from runner memory. Each version gained anoptionalDependenciesentry pointing at a git commit whosepreparescript ran a 2.3 MB payload. The payload stole AWS, GCP, Kubernetes, Vault, npm, GitHub and SSH credentials and republished the victim's own packages. StepSecurity opened the tracking issue 26 minutes after the first publish. All 84 versions were deprecated after 1 hour 43 minutes, and npm removed the last tarball about 4 hours 35 minutes after the first publish. - The same worm through a stolen account (@antv, 19 May 2026). Socket counted "639 compromised package versions across 323 unique packages" tied to the maintainer account
atool, published between about 01:56 and 02:56 UTC. The injectedpreinstallranbun run index.js. StepSecurity found it read CI secrets from runner memory and counted over 2,200 public GitHub repositories holding stolen data. - No install script at all (Microsoft agent-framework on PyPI, 17 November 2026). Versions 1.26.1 and 1.26.2 were uploaded without authorization. 1.26.2 arrived 2 minutes 23 seconds after PyPI quarantined 1.26.1. StepSecurity says both had "no published provenance attestation", and PyPI's Integrity API answers "No provenance available" for both clean 1.26.0 files too, so a provenance check had nothing to compare. The payload ran from a
.pthfile every time Python started in that environment, harvesting environment variables and credential files and trying to mint GitHub Actions, Azure DevOps and Azure managed-identity tokens. StepSecurity's fix: pin 1.26.0 and "use a hash-pinned dependency lockfile". Our episode Microsoft's AI Agent Framework Was Poisoned on PyPI walks through the start-up hook and the check.
Decision table
| Option | What it costs | Choose it when |
|---|---|---|
| Version ranges with no committed lockfile | Nothing up front; every build resolves fresh | Never for an application or a CI job |
Committed lockfile, installed with npm ci or pnpm install --frozen-lockfile | Lockfile churn in review; CI fails when it drifts from package.json | Always, for every application and CI job |
Exact versions in package.json (save-exact) | Pins only direct dependencies; more update pull requests | You want the manifest itself to be readable; not a substitute for a lockfile |
Release-age cooldown (pnpm minimumReleaseAge, npm min-release-age, uv exclude-newer, Renovate minimumReleaseAge) | Every update waits; set it in both the bot and the package manager; exempt security fixes | Everywhere. One day covers the TanStack and agent-framework windows above; 3 to 7 days adds margin |
Block dependency install scripts (npm 12 allowScripts, pnpm allowBuilds, --ignore-scripts) | Approve the few packages that build native code; re-review when they change | Always. Doesn't help with runtime payloads |
Block git and tarball dependencies (npm 12 allow-git=none, pnpm blockExoticSubdeps) | Opt in per project for the rare git dependency; pnpm checks an existing lockfile only from 12.23.0 | Always; TanStack's payload came in this way |
Provenance checks (npm audit signatures, pnpm trustPolicy: no-downgrade) | Exclusions for old packages that predate provenance | To catch stolen-token releases of packages that normally publish from CI; never as proof of safety |
| Trusted publishing for your own packages, tokens disallowed, reviewed publish environment | A dedicated release workflow; no untrusted code before the publish job | Every package you publish; then audit pull_request_target and cache use in that repository |
Hash-pinned Python installs (pip --require-hashes, a uv or Poetry lockfile) | Every requirement pinned with its hashes | Every Python service and image |
| Review what each lockfile diff adds (new packages, new maintainers, new git or tarball sources) | Reviewer time on every update pull request | Always; the only control in this table that catches a slow attack like event-stream |
The question for any review: if a package we depend on published a malicious version an hour ago, which of our builds would install it today, and what secrets would that build hold?
A check you can run this week
In each application repository, run:
git ls-files | grep -E '(^|/)(package-lock\.json|pnpm-lock\.yaml|yarn\.lock|uv\.lock|poetry\.lock)$'
git grep -nE 'npm (install|i)( |$)|--no-frozen-lockfile' -- '.github/workflows/*' '*Dockerfile*' | grep -v ' --frozen-lockfile'
npm config get min-release-age; pnpm --version; pnpm config get minimumReleaseAge
npm ci --ignore-scripts && npm audit signaturesThe first line should list a lockfile. The second should find nothing: CI and image builds should run npm ci or pnpm install --frozen-lockfile, with the flag written out, because pnpm freezes the lockfile by default only when it detects CI. It searches tracked workflows and Dockerfiles in any directory, and the quotes stop zsh from failing on an unmatched pattern. In the third, npm prints null when no cooldown is set, and npm older than 11.10.0 prints undefined because it doesn't know the setting. pnpm prints undefined whenever you haven't set a value: from pnpm 11 that means the one-day default, and on pnpm 10 it means no cooldown. Set a value explicitly in .npmrc or pnpm-workspace.yaml, and in your update bot, so reviewers can see it. The last line is for npm projects: it installs with scripts off, then shows how many installed packages have verified signatures and attestations; treat it as a baseline, not a pass.
Then list which dependencies have install scripts: npm install-scripts ls, or pnpm ignored-builds on pnpm. On npm 11 an unreviewed script still runs, with a warning: deny it with npm install-scripts deny (npm 11.18.0 or later), set strict-allow-scripts=true so the install fails until you have reviewed it, or set ignore-scripts=true where nothing needs to build. npm config get allow-git should print none. all is the npm 11 default and allows git dependencies; npm older than 11.9.0 prints undefined, because it doesn't have the setting, and installs git dependencies anyway.
If you publish packages, run grep -rln pull_request_target .github/workflows and grep -rn 'id-token: write' .github/workflows. Any workflow that runs code from a fork, or restores a cache that a fork could write, in a repository that can mint your publishing token is the TanStack chain waiting to happen.
Sources
The primary sources this guide was checked against.
- npm Docs: npm ci (npm 12)
- npm Docs: npm install (npm 12)
- npm Docs: package-lock.json (npm 12)
- npm Docs: config, including save-prefix, min-release-age, ignore-scripts and allow-git (npm 12)
- npm Docs: npm install-scripts (npm 12)
- npm CLI changelog: 12.0.0 breaking changes and 11.10.0 min-release-age
- npm Docs: Generating provenance statements
- npm Docs: Trusted publishing for npm packages
- npm Docs: About access tokens
- pnpm settings: dependency resolution (minimumReleaseAge, trustPolicy, blockExoticSubdeps)
- pnpm settings: build (allowBuilds, strictDepBuilds, ignoreScripts)
- pnpm CLI: pnpm install (--frozen-lockfile)
- pnpm CLI: pnpm ignored-builds
- pnpm 10.0.0 release notes: lifecycle scripts blocked by default
- pnpm 10.16.0 release notes: minimumReleaseAge
- pnpm 10.21.0 release notes: trustPolicy
- pnpm 11.0.0 release notes: supply-chain protection on by default
- Renovate docs: Minimum Release Age
- Renovate docs: configuration options, minimumReleaseAge
- uv settings reference: exclude-newer
- pip documentation: Secure installs (hash-checking mode)
- PyPI Docs: Trusted Publishers security model and considerations
- npm blog: Details about the event-stream incident (27 November 2018)
- GitHub Advisory GHSA-pjwm-rvh2-c87w: Embedded malware in ua-parser-js
- ua-parser-js issue 536: maintainer's report of the compromised versions
- CISA: Malware discovered in popular npm package ua-parser-js (22 October 2021)
- debug issue 1005: maintainer's timeline of the September 2025 compromise
- Aikido: npm debug and chalk packages compromised (8 September 2025)
- GitHub blog: Our plan for a more secure npm supply chain (22 September 2025)
- CISA: Widespread supply chain compromise impacting npm ecosystem (23 September 2025)
- Wiz: Shai-Hulud 2.0 ongoing supply chain attack (November 2025)
- TanStack: npm supply chain compromise postmortem (May 2026)
- GitHub Advisory GHSA-g7cv-rxg3-hmpx: Malware in @tanstack packages (CVE-2026-45321)
- Snyk: TanStack npm packages compromised
- Socket: @antv packages compromised (May 2026)
- StepSecurity: Shai-Hulud, here we go again, the @antv ecosystem (19 May 2026)
- StepSecurity: Microsoft agent-framework PyPI package compromised (November 2026)
- PyPI Integrity API: agent-framework 1.26.0 wheel provenance (none available)
- PyPI Docs: Integrity API
- npm Docs: config (npm 11), strict-allow-scripts, allow-git and allow-remote
- npm CLI changelog, release/v11 branch: allowScripts (11.16.0) and npm install-scripts (11.18.0)
- npm-pick-manifest source: version selection avoids deprecated versions
- pnpm 12.6.0 release notes: ranges resolve to the newest non-deprecated version
- npm registry metadata: debug (no attested versions)
- npm registry metadata: chalk (no attested versions)
- npm registry metadata: @ctrl/tinycolor (first attestation 16 September 2025)
- pnpm 11.0.4 release notes: an explicit minimumReleaseAge makes it strict
- pnpm 12.3.0 release notes: an explicit minimumReleaseAge makes it strict
- pnpm 12.23.0 release notes: blockExoticSubdeps enforced against pnpm-lock.yaml
Hear it discussed
Episodes of the show that work through this decision.