Жизнь Пользовательская статья

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.

Мнение авторов может не совпадать с позицией редакции

YS 5 мин чтения

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 preinstall script, so simply installing an infected version was enough.
  • TanStack (May 2026). According to Orca, the attackers combined a pull_request_target workflow, 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 with ignore-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: read by default;
  • avoid pull_request_target together with a checkout of the PR code;
  • do not share Actions caches between untrusted PR workflows and release workflows.

Checklist

  1. npm ci / bun install --frozen-lockfile in CI, lockfile reviewed in PRs.
  2. Dependency install scripts off by default (npm 12, ignore-scripts, Bun trustedDependencies).
  3. Trusted publishing instead of tokens; no npm token in repository secrets.
  4. npm audit signatures in CI, understood as an origin check only.
  5. Actions pinned by SHA, enforced by policy.
  6. Minimal permissions:, no pull_request_target with PR checkout.
  7. OpenSSF Scorecard run on your own repositories: Pinned-Dependencies, Token-Permissions and Dangerous-Workflow cover most of the above.

Sources

Комментарии 7

TP Tomasz P. #3

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 signatures still work through it?

YS Yury Slinkin #4

>>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 signatures once 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 на других языках
I ilya #1

а если у меня bun, но в ci почему-то npm ci гоняют по старой памяти, оба lockfile держать норм или это зло

YS Yury Slinkin #2

>>1
Держать два lockfile не стоит: они разъедутся, и в CI будет проверяться не то дерево зависимостей, что у вас локально. Выберите один менеджер, удалите второй lockfile и в CI ставьте тем же: bun install --frozen-lockfile. Если npm нужен только для npm publish или npm audit signatures, это можно делать отдельным шагом, установка от этого не зависит.

Გ გიგა #5

sha-ით რომ დავპინავ dependabot მერე აპდეიტს მომიტანს თუ ხელით უნდა ვცვალო ყოველ ჯერზე

IS Irakli S. #6

>>5
Dependabot SHA-ით დაპინულ action-ებსაც ანახლებს: ახალ SHA-ს ჩასვამს და ვერსიის კომენტარსაც შეცვლის, თუ ის # v4.2.2 ფორმატშია. PR მაინც უნდა გადახედოთ, ავტომატურად ნუ დაამერჯავთ.

ER Evgeny Rudenko #7

Одно дополнение к пункту про --ignore-scripts: в монорепо его удобнее положить в .npmrc (ignore-scripts=true), но тогда перестанут выполняться и ваши собственные скрипты вроде prepare. Если они нужны, запускайте их явно отдельным шагом (npm run prepare), а не возвращайте скрипты всем зависимостям.

Войдите, чтобы комментировать