Opened 10 months ago
Last modified 2 days ago
#64543 new task (blessed)
Implement `ignore-scripts` to harden npm usage
| Reported by: | johnbillion | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Build/Test Tools | Version: | |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: | javascript |
Description
Lifecycle scripts in npm packages -- in particular postInstall scripts -- are a significant security concern because by default they execute automatically for all dependencies.
Running npm install or npm ci not only installs packages but also runs the postInstall script in every direct and transitive dependency in the entire dependency tree. The recent "Shai-Hulud" supply chain attack on the npm ecosystem has been successful in part due to postInstall scripts that have allowed it to rapidly self-propagate.
We should strongly consider implementing ignore-scripts = true in the .npmrc file in order to disable the automatic execution of lifecycle scripts. This will primarily help protect contributors against malicious postInstall scripts that may be introduced by attacks on packages in the dependency tree.
Ironically WordPress core just introduced its own postInstall script in #64393. This is far from ideal.
Making this change will cause some short-term pain while we determine the best way to ensure that all dependencies continue to work and/or provide clear instructions for contributors if manual subsequent steps become necessary. As the ecosystem reels from "Shai-Hulud" supply chain attack I fully expect to see more packages remove their postInstall scripts in favour of documenting subsequent steps necessary to, for example, install dependent binaries.
There's some tooling available to assist with determining which dependencies include lifecycle scripts, but not a lot:
npm query ':attr(scripts, [postinstall])'npm query ':attr(scripts, [preinstall])'npm query ':attr(scripts, [install])'- https://www.npmjs.com/package/can-i-ignore-scripts
- https://www.npmjs.com/package/@lavamoat/allow-scripts
Related links:
Change History (7)
This ticket was mentioned in PR #14058 on WordPress/wordpress-develop by @manzoorwani.jk.
5 weeks ago
#5
- Keywords has-patch added
Opts in to the npm v12 supply chain defaults on npm 11 for Core and the bundled themes with a build process, mirroring https://github.com/WordPress/gutenberg/pull/82689. This replaces the npm v12 upgrade in #13536, which is on hold.
- `.npmrc` refuses git, remote URL and local tarball dependencies, and
strict-allow-scriptsfails the install on unreviewed install scripts. - `allowScripts` denies every dependency install script. Twenty Twenty-One, Twenty Twenty-Two and Twenty Twenty-Five get the same policy.
- The minimum npm moves to
>=11.18.0because npm 11.16 and 11.17 reject registry dependencies withEALLOWREMOTEunderallow-remote = none. .nvmrcmoves to Node.js 24.20, which bundles npm 11.19, matching https://github.com/WordPress/gutenberg/pull/84138.
Trac ticket: https://core.trac.wordpress.org/ticket/64543
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Implementation and this description, reviewed by me.
---
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.
@lancewillett commented on PR #14058:
9 days ago
#6
@desrosj could you give this an independent review? The npm install policy and version requirements have passed local install/build checks, but I am holding landing for a second opinion on the supply-chain policy and its effect on contributors.
<sub>AI review · <code>gpt-6</code></sub>
@lancewillett commented on PR #14058:
2 days ago
#7
@desrosj following up on my Oct 31 request: could you give this an independent review when you have time? It's approved and waiting only on your second opinion of the npm install policy.
<sub>AI review · <code>claude-opus-5-5</code></sub>
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
The proposed switch to pnpm is interesting in this regard. It can be configured to allow certain dependencies to be built.