Supply-chain hygiene for npm and Bun projects in 2026
Worms in the npm registry are no longer rare events: Shai-Hulud, its second wave, the TanStack compromise, ChainDrop. Most of the defences are boring settings you can apply in an afternoon. This is a practical list for a small team, with what each step does and where it stops helping.
ავტორთა აზრი შეიძლება არ ემთხვეოდეს რედაქციის პოზიციას
☰ სარჩევი · 8
What actually happened
Four incidents shape the advice below:
- Shai-Hulud (September 2025). GitHub removed more than 500 packages and announced a plan for mandatory 2FA and short-lived tokens.
- Shai-Hulud 2.0 (November 2025). Check Point counted 621 packages and about 25,000 repositories. The payload ran from a
preinstallscript, so simply installing an infected version was enough. - TanStack (May 2026). According to Orca, the attackers combined a
pull_request_targetworkflow, a poisoned GitHub Actions cache and a stolen OIDC token. The malicious versions carried valid provenance. - ChainDrop (August 2026). Microsoft describes a self-propagating worm that hit keyv, flat-cache and more than 400 other packages.
The pattern is the same each time: a stolen publishing credential, code that runs at install time, and a CI pipeline that trusts more than it should.
Step 1: make installs reproducible
A lockfile only protects you if CI refuses to deviate from it.
# npm: fails if package-lock.json and package.json disagree, never rewrites the lockfile
npm ci
# Bun: same idea
bun install --frozen-lockfile
Commit package-lock.json or bun.lock, and review lockfile diffs in pull requests like code. A new transitive dependency appearing in a "bump typescript" PR is worth a question.
Pin exact versions for direct dependencies if your team updates deliberately anyway:
# .npmrc
save-exact=true
Step 2: stop install-time code
Install scripts are the main entry point of the worms above.
- npm 12 (July 2026) blocks lifecycle scripts of dependencies by default; packages that really need them are allowed explicitly (
allowScripts, see the npm 12 release notes). If you are still on npm 10 or 11, you can get most of the effect withignore-scripts:
npm ci --ignore-scripts
- Bun does not run lifecycle scripts of dependencies unless the package is in
trustedDependencies(Bun ships a default allowlist of popular packages). Keep the list short and explicit:
{
"trustedDependencies": ["sharp"]
}
bun pm untrusted shows which packages had their scripts skipped, and bun pm trust <name> adds one on purpose.
Step 3: publish without long-lived tokens
npm revoked classic tokens in December 2025; write tokens now live 90 days at most. The better option is trusted publishing: GitHub Actions gets a short-lived OIDC token, npm exchanges it for a publish right, and no secret lives in the repository.
name: publish
on:
release:
types: [published]
permissions:
contents: read
id-token: write # needed for OIDC
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@<full-commit-sha> # v4, see step 4
- uses: actions/setup-node@<full-commit-sha> # v4
with:
node-version: 24
registry-url: https://registry.npmjs.org
- run: npm ci
- run: npm test
- run: npm publish
Since 2 October 2026 a trusted publishing configuration that has not been validated expires after 48 hours, so set it up right before the first publish from CI.
The limits of provenance
Provenance (Sigstore attestation, checked with npm audit signatures) proves where and from which commit a package was built. It does not prove the code is benign. The npm documentation says so directly, and TanStack showed it in practice: the build ran in the real pipeline, so the attestation was valid. Treat provenance as a check against "someone published from a laptop with a stolen token", not as a malware scanner.
npm audit signatures
Step 4: pin GitHub Actions by SHA
A tag such as v4 can be moved. That is how tj-actions/changed-files leaked CI secrets in March 2025. A full commit SHA cannot be moved:
git ls-remote https://github.com/actions/checkout refs/tags/v4.2.2
Put that SHA in uses: and keep the tag as a comment so humans and Dependabot can read it. Since August 2025 an organisation policy can require full-SHA pinning.
Also:
- set
permissions:per workflow,contents: readby default; - avoid
pull_request_targettogether with a checkout of the PR code; - do not share Actions caches between untrusted PR workflows and release workflows.
Checklist
npm ci/bun install --frozen-lockfilein CI, lockfile reviewed in PRs.- Dependency install scripts off by default (npm 12,
ignore-scripts, BuntrustedDependencies). - Trusted publishing instead of tokens; no npm token in repository secrets.
npm audit signaturesin CI, understood as an origin check only.- Actions pinned by SHA, enforced by policy.
- Minimal
permissions:, nopull_request_targetwith PR checkout. - OpenSSF Scorecard run on your own repositories: Pinned-Dependencies, Token-Permissions and Dangerous-Workflow cover most of the above.
Sources
- GitHub, 22.09.2025 — Shai-Hulud, 500+ packages removed, plan for 2FA and short tokens
- Check Point, 25.11.2025 — Shai-Hulud 2.0, 621 packages, preinstall
- Orca, 12.05.2026 — TanStack: pull_request_target, cache poisoning, OIDC token, valid provenance
- Microsoft, 04.08.2026 — ChainDrop, 400+ packages
- GitHub, 09.12.2025 — classic npm tokens revoked, 90-day write tokens
- npm CLI releases, 08.07.2026 — npm 12, dependency lifecycle scripts blocked by default
- GitHub, 02.10.2026 — unvalidated trusted publishing configs expire after 48 hours
- npm docs: provenance — Sigstore,
npm audit signatures, what provenance does not guarantee - CISA, 18.03.2025 — tj-actions/changed-files, CVE-2025-30066
- GitHub, 15.08.2025 — policy to require SHA pinning
- OpenSSF Scorecard — repository checks
კომენტარები 7
Two questions please:
1. If a package has provenance, can I skip reading the changelog and just update?
2. We have a private registry proxy. Does
npm audit signaturesstill work through it?>>3
1. No. Provenance tells you the version was built in a specific CI run from a specific commit. In the TanStack case that was true and the code was still malicious. Read what changed, at least for direct dependencies.
2. It depends on whether the proxy passes through the signatures and attestations from the public registry. Run
npm audit signaturesonce against it: if it reports missing signatures for packages that have them on npmjs.com, the proxy strips them, and that is a question for its vendor docs.კიდევ 5 სხვა ენებზე
а если у меня bun, но в ci почему-то npm ci гоняют по старой памяти, оба lockfile держать норм или это зло
>>1
Держать два lockfile не стоит: они разъедутся, и в CI будет проверяться не то дерево зависимостей, что у вас локально. Выберите один менеджер, удалите второй lockfile и в CI ставьте тем же:
bun install --frozen-lockfile. Если npm нужен только дляnpm publishилиnpm audit signatures, это можно делать отдельным шагом, установка от этого не зависит.sha-ით რომ დავპინავ dependabot მერე აპდეიტს მომიტანს თუ ხელით უნდა ვცვალო ყოველ ჯერზე
>>5
Dependabot SHA-ით დაპინულ action-ებსაც ანახლებს: ახალ SHA-ს ჩასვამს და ვერსიის კომენტარსაც შეცვლის, თუ ის
# v4.2.2ფორმატშია. PR მაინც უნდა გადახედოთ, ავტომატურად ნუ დაამერჯავთ.Одно дополнение к пункту про
--ignore-scripts: в монорепо его удобнее положить в.npmrc(ignore-scripts=true), но тогда перестанут выполняться и ваши собственные скрипты вродеprepare. Если они нужны, запускайте их явно отдельным шагом (npm run prepare), а не возвращайте скрипты всем зависимостям.შედით, რომ დააკომენტაროთ