• Home
  • Tech News
  • Supply Chain Attacks on npm Packages: A Practical Install Checklist

Supply Chain Attacks on npm Packages: A Practical Install Checklist

Most npm supply chain advice stops at “run a scanner.” The incident that shaped recent thinking shows why that is not enough. According to GitHub, the Shai-Hulud worm spread through npm by compromising maintainer accounts and injecting malicious post-install scripts into popular JavaScript packages. GitHub says it was notified on September 14, 2025 and removed more than 500 compromised packages. This article walks the install path step by step, shows where you can put a control at each step, and gives you a checklist you can apply to a project today.

Follow one install from command to code execution

The npm documentation lists the lifecycle scripts that run when a package is installed: preinstall, install, postinstall, then the prepare family. Those scripts come from the installed package’s own package.json, so a dependency you never read can run code on your machine or CI runner during install. The npm docs add that npm ci runs the same set after modules are installed.

1. Resolve lockfile + npm ci pins versions 2. Verify npm audit signatures 3. Scripts pre/install/post ignore-scripts 4. Execution laptop or CI secrets in env Control at each step No silent upgrades Check build origin Skip install hooks Keep secrets out Provenance shows where a package was built. It does not prove it is safe.
The four points in an npm install where you can add a control, based on the npm CLI documentation.

The checklist, in order

1. Make installs reproducible

Use npm ci in CI. Per the docs, it requires an existing package-lock.json or npm-shrinkwrap.json, exits with an error if the lockfile and package.json disagree, and never writes to either file. A plain npm install can update the lockfile, whereas a committed lockfile plus npm ci installs exactly what was reviewed and never rewrites it. Review lockfile changes in pull requests the way you review code.

2. Decide whether install scripts should run

The ignore-scripts option defaults to false. Setting it to true makes npm skip scripts defined in package.json files such as install hooks. This blocks the post-install vector GitHub describes. The cost is that some packages legitimately need a build step: the npm docs note that a package with a binding.gyp file and no custom install script defaults to node-gyp rebuild. Try your build with scripts off, then run the few build steps you trust explicitly and document why each one is needed.

3. Verify where packages came from

npm provenance links a package to its source code and build instructions through signed attestations recorded in a public ledger. Run npm audit signatures. The output reports how many packages have verified registry signatures and how many have verified attestations. The docs are explicit about the limit: provenance does not guarantee a package is free of malicious code, and it only applies to packages built on a supported cloud CI/CD provider. Use it to prioritize which dependencies deserve a closer look, not as a pass.

4. Protect your own publishing, if you maintain packages

Trusted publishing lets you publish from CI using OpenID Connect instead of a stored long-lived write token. npm documents support for GitHub Actions, GitLab CI/CD and CircleCI cloud runners, and requires npm CLI 11.5.1 or later and Node 22.14.0 or higher. GitHub’s roadmap also describes deprecating classic tokens and moving publishing to local publishing with 2FA, short-lived granular tokens or trusted publishing, with a gradual rollout and no dates given. Check the current npm documentation for timelines.

5. Limit what an install can steal

Since the worm could steal several kinds of secrets beyond npm tokens, run installs in CI with only the secrets the install step needs, and keep deployment credentials out of the install job. This is general hygiene rather than an npm feature.

Why accounts, not code, are the weak point

GitHub’s post describes a wider surge in account takeovers on package registries, and the worm moved by compromising maintainer accounts. That changes how you think about trust. A dependency is not only its code today, it is the account that can publish its next version. When you evaluate a package, look at how many people can publish it, whether releases are built in public CI with provenance, and how recently it changed hands. A tiny package maintained by one person with no build record is a bigger bet than its download count suggests. You can make that bet consciously, for example by pinning it, or replace it with a few lines of your own code.

Common mistakes

  • Treating a scanner as the whole defense. Scanners work from known vulnerability data, so a brand new malicious release can appear clean. Controls at install time cover the gap.
  • Disabling scripts globally and never looking again. Builds silently lose native modules. Keep a short list of packages allowed to build.
  • Reading provenance as a safety label. The docs say it is not.
  • Using npm install in CI. That can rewrite the lockfile and install newer versions than you reviewed.
  • Not checking names. Before adding a dependency, confirm the exact package name, its publisher and its repository link on the registry page.

Test it yourself

  1. In a copy of your project, run npm ci –ignore-scripts and then your build and tests. Note what fails.
  2. Run npm audit signatures and record the counts. Pick two unverified dependencies and read their repository history.
  3. Change a version in package.json without updating the lockfile and confirm npm ci refuses to proceed.

Takeaway

Adopt three habits this week: install with npm ci from a reviewed lockfile, try your build with scripts disabled, and run npm audit signatures to see which dependencies lack verifiable build records. Those steps do not make the ecosystem safe, but they shrink the window in which a poisoned release can run on your machines.

Sources

Drafted with AI assistance and reviewed by Ash Ahmad, editor of AI Bloggers Hub. Last checked November 2026. Spot an error? Write to [email protected].

Share this post

Subscribe to our newsletter

Keep up with the latest blog posts by staying updated. No spamming: we promise.
By clicking Sign Up you’re confirming that you agree with our Terms and Conditions.

Related posts