npm & Open-Source Package Hijack Defense Checklist (2026)
A practical checklist for defending against hijacked npm and open-source packages: lockfile integrity, trusted publishing and provenance, isolating postinstall scripts, keeping secrets out of public repos, and containing dependency blast radius within hours.
// key takeaways
- Most npm hijacks start with a phished maintainer, not a code bug. The chalk/debug compromise came from a fake 2FA-reset email; eslint-config-prettier came from the typosquat domain npnjs.com.
- A committed lockfile with npm ci or a frozen install is the line between 'a bad version existed for two hours' and 'a bad version reached production'.
- Install scripts are the main execution path. Disable them by default and allow the few packages that need them.
- Prefer packages published through trusted publishing with provenance, and publish your own that way so a stolen npm token cannot push a release.
- Containment speed depends on knowing which lockfiles, images and machines resolved a bad version. Keep that queryable before you need it.
How package hijacks actually happen
On September 8, 2025, maintainer Josh Junon (qix) was phished by a fake npm 2FA-reset email from npmjs.help. The attacker published malicious versions of 18 packages, including chalk 5.6.1, debug 4.4.2, ansi-styles 6.2.2 and strip-ansi 7.1.1, with code that hijacked crypto wallet transactions in browsers. The packages have more than 2 billion weekly downloads combined. The malicious versions were live for about two hours before npm took them down, which was long enough for any unpinned install or fresh lockfile in that window to pick them up.
Two months earlier, on July 18, 2025, a maintainer was phished through the typosquat domain npnjs.com. The attacker published eslint-config-prettier 8.10.1, 9.1.1, 10.1.6 and 10.1.7 with an install script that ran node-gyp.dll on Windows and dropped the Scavenger infostealer. eslint-plugin-prettier, synckit, @pkgr/core, napi-postinstall and later the 'is' package were hit in the same campaign. A linting config is a dev dependency, but its install script ran on every developer laptop and CI runner that installed it.
Worms automate the same path. The Shai-Hulud worm in September 2025 stole maintainers' npm and GitHub tokens with TruffleHog and republished their packages with a malicious bundle.js postinstall; CISA counted more than 500 affected packages. Every stolen token became the next hijacked package.
Lockfile integrity and controlled upgrades
A committed lockfile pins exact versions and records an integrity hash for each tarball. npm ci, pnpm install --frozen-lockfile and bun install --frozen-lockfile refuse to change it, so CI installs exactly what was reviewed. Teams whose builds ran npm install against caret ranges during the chalk window were the ones that pulled 5.6.1.
Upgrades are where new versions enter, so make them deliberate. Batch dependency updates through Dependabot or Renovate pull requests, add a cooldown so brand-new releases wait a few days before they are proposed, and review lockfile diffs for unexpected new packages, changed tarball URLs, and packages that suddenly gained install scripts.
- Commit lockfiles for every app and service, and fail CI if the lockfile is missing or out of sync.
- Use npm ci, pnpm install --frozen-lockfile or bun install --frozen-lockfile in CI and Docker builds.
- Delay adoption of new releases with a minimum release age or update cooldown so hijacked versions are usually pulled before you see them.
- Review lockfile diffs for new transitive packages, registry URL changes and integrity hash changes on unchanged versions.
- Route installs through a registry proxy so you can block a version for every team at once.
# CI: install exactly what the lockfile says, with no lifecycle scripts
npm ci --ignore-scripts
# Fail fast if a known-bad version is anywhere in the tree
npm ls chalk debug ansi-styles strip-ansi eslint-config-prettier --all 2>/dev/null \
| grep -E 'chalk@5\.6\.1|debug@4\.4\.2|ansi-styles@6\.2\.2|strip-ansi@7\.1\.1|eslint-config-prettier@(8\.10\.1|9\.1\.1|10\.1\.6|10\.1\.7)' \
&& { echo 'known-malicious version resolved'; exit 1; } || true
# Review what changed in a dependency PR
git diff origin/main -- package-lock.json | grep -E '^\+\s+"(resolved|integrity)"' | head -50Trusted publishers and provenance
Both 2025 phishing campaigns ended with an attacker holding a credential that could publish. Trusted publishing removes that credential: the registry accepts a release only from a specific CI workflow that proves its identity with a short-lived OIDC token, so there is no long-lived npm token to phish or steal. Publishing with provenance also attaches a signed statement linking the tarball to the source commit and workflow that built it.
As a consumer, provenance is a signal, not a guarantee. A release that suddenly lacks provenance when previous ones had it, or that was published from a laptop instead of the usual workflow, deserves a hold. As a publisher, combine trusted publishing with phishing-resistant 2FA on the npm account, and remove old automation tokens once the workflow is in place.
- Publish your packages through trusted publishing from a protected CI workflow, with provenance enabled.
- Revoke classic and automation npm tokens that trusted publishing replaces, and never store publish tokens on developer machines.
- Protect maintainer npm and GitHub accounts with security keys; both 2025 campaigns relied on phishing pages that captured codes.
- Check registry signatures and provenance attestations in CI with npm audit signatures.
- Treat a missing or changed provenance on a package that previously had it as a reason to block the update.
# .github/workflows/release.yml (publisher side)
permissions:
contents: read
id-token: write # OIDC for trusted publishing + provenance
jobs:
publish:
runs-on: ubuntu-latest
environment: npm-release
steps:
- uses: actions/checkout@<pinned-sha>
- uses: actions/setup-node@<pinned-sha>
with:
node-version: 22
registry-url: https://registry.npmjs.org
- run: npm ci --ignore-scripts
- run: npm publish --provenance --access public
# Consumer side, in CI after install:
# npm audit signaturesIsolate postinstall and other lifecycle scripts
The eslint-config-prettier payload, the Shai-Hulud worm and the s1ngularity Nx compromise all executed through install-time scripts. Disabling lifecycle scripts by default removes that path for the vast majority of packages, which do not need them. Keep an explicit allowlist for the few that do, such as native modules, and review additions to it.
Where scripts must run, run them somewhere with nothing to steal. Build in containers or VMs without cloud credentials, npm tokens or SSH keys, and do not mount writable host repositories into untrusted environments. Sandboxes are code too: Docker Sandboxes 0.31.0 before 0.50.0 let a sandbox with a read-write repository mount poison the host repository's Git config, for example core.fsmonitor, so a later host-side Git operation ran a program on the host. Docker fixed it in 0.50.0 on October 26, 2026. Keep sandbox tooling patched and prefer read-only mounts for untrusted code.
- Set ignore-scripts=true in project .npmrc and use npm ci --ignore-scripts in CI.
- On pnpm, allow build scripts only for listed packages (onlyBuiltDependencies); on Bun, keep trustedDependencies short.
- Run installs and builds in containers or VMs without registry publish tokens, cloud keys or SSH agents.
- Mount untrusted repositories read-only and patch sandbox tools such as Docker Sandboxes to 0.50.0 or later.
- Alert when a dependency update adds a preinstall, install or postinstall script.
# .npmrc (committed)
echo 'ignore-scripts=true' >> .npmrc
# pnpm: only these packages may run build scripts (package.json)
# "pnpm": { "onlyBuiltDependencies": ["esbuild", "sharp"] }
# List installed packages that declare lifecycle scripts
find node_modules -name package.json -not -path '*/node_modules/*/node_modules/*' \
-exec grep -lE '"(preinstall|install|postinstall)"\s*:' {} + | sed 's|/package.json||'Fast blast-radius containment
When a hijack is announced, the questions are which repositories resolved the bad version, which CI runs and images built with it, which developer machines installed it, and what credentials those environments held. Answering from lockfiles and SBOMs takes minutes; answering by asking every team takes days.
Secrets are the long tail. A researcher who scanned 7.25 million public Gitee repositories in 2026 found 26,400 unique credentials that still worked, nearly half of them from 2025 commits, and no revocations were confirmed at publication. The same applies after a package hijack: any token an infected install could read must be revoked at the provider. Deleting it from a file or rewriting history does not revoke it.
- Generate an SBOM for every build and keep it searchable by package name and version.
- Block the bad versions at the registry proxy first, then roll forward to fixed versions with fresh lockfiles.
- Rebuild and redeploy images built during the exposure window instead of patching them in place.
- Rotate every credential reachable from affected machines and runners: npm, GitHub, cloud, and API keys in env files.
- Scan full git history for committed secrets and revoke anything ever pushed to a public repository.
- Check developer machines that ran the install for infostealer artifacts when the payload targeted them, as with Scavenger on Windows.
# Across all checked-out repos
for lock in $(find ~/code -name package-lock.json -not -path '*/node_modules/*'); do
jq -r '.packages | to_entries[] | select(.key|endswith("node_modules/chalk")) | .value.version' "$lock" \
| grep -qx '5.6.1' && echo "chalk@5.6.1 in $lock"
done
# Scan history for secrets that need revoking
gitleaks git --redact --no-banner .// actionable engineering checklist
Commit lockfiles and freeze CI installs
npm ci, pnpm --frozen-lockfile or bun --frozen-lockfile everywhere; CI fails on lockfile drift.
Add an update cooldown
New releases wait before Dependabot or Renovate proposes them, so short-lived hijacked versions rarely reach you.
Disable lifecycle scripts by default
ignore-scripts in .npmrc with a reviewed allowlist for packages that genuinely need build scripts.
Publish with trusted publishing and provenance
No long-lived npm publish tokens; releases only from a protected CI workflow with OIDC.
Protect maintainer accounts
Security-key 2FA on npm and GitHub, and training to recognize lookalike domains such as npmjs.help and npnjs.com.
Verify signatures in CI
Run npm audit signatures and flag packages whose provenance disappears or changes.
Isolate installs from credentials
Build in containers or VMs without publish tokens, cloud keys or SSH agents, with sandbox tooling kept patched.
Keep blast radius queryable
Searchable SBOMs per build, a registry proxy that can block versions, and a rotation runbook for reachable secrets.
// connected pwn.watch tools & live trackers
SBOM Viewer (CycloneDX & SPDX) →
Search a build's SBOM for a hijacked package version in seconds.
Hash Generator (SHA-256) →
Compare a downloaded tarball against the integrity hash recorded in your lockfile.
chmod Calculator →
Restrict .npmrc and other token files to the owning user.
Stack & Tag CVE Trackers
Security Hubs & Feeds
Related Incidents
- chalk, debug and 16 other npm packages hijacked via fake 2FA email →
- eslint-config-prettier hijacked via npnjs.com phishing →
- Shai-Hulud: self-replicating npm worm hits 500+ packages →
- s1ngularity: malicious Nx releases via postinstall →
- 26,400 live cloud and AI keys found in public Gitee repos →
- Docker Sandboxes escape via poisoned Git config →
Frequently Asked Questions
- Would a lockfile have protected me from the chalk and debug hijack?
- Yes, if CI and Docker builds installed with npm ci or a frozen-lockfile install and nobody regenerated the lockfile during the roughly two hours the malicious versions were live. Lockfiles pin exact versions and integrity hashes, so an existing lockfile would not pick up chalk 5.6.1 on its own.
- Is it safe to disable npm install scripts?
- For most projects, yes. Only a small number of packages, usually native modules or tools that download binaries, need lifecycle scripts. Set ignore-scripts=true and allow those specific packages, then test the build.
- Does npm provenance prove a package is safe?
- No. It proves which repository and CI workflow built the tarball. That stops a stolen token from publishing a release that looks like it came from CI, but malicious code merged into the source repository would still carry valid provenance.
- What should I rotate after installing a hijacked package?
- Every credential the install could read on that machine or runner: npm and GitHub tokens, cloud keys, SSH keys, and API keys in env files. Revoke them at the provider, then rebuild affected images and runners from clean sources.
Get an email when a new major security incident drops. No spam, unsubscribe any time.