fix(arborist): preserve bin links when allowScripts denies a node (backport release/v11) (#9681)#9682
Open
Sanjays2402 wants to merge 1 commit into
Open
fix(arborist): preserve bin links when allowScripts denies a node (backport release/v11) (#9681)#9682Sanjays2402 wants to merge 1 commit into
Sanjays2402 wants to merge 1 commit into
Conversation
…m#9681) A node denied via `allowScripts: { "<pkg>": false }` was dropped from the build set entirely, so its `node_modules/.bin/<bin>` symlinks were never created. This stranded any package that declared both an install script and a bin (e.g. esbuild, nx): the binary lived under `node_modules/<pkg>` but nothing put it on PATH, breaking downstream build steps with `command not found`. Move the deny check out of the early-return in `#addToBuildSet` and into the per-queue dispatch, mirroring the v12 fix. Lifecycle scripts (preinstall/install/postinstall/prepare) for denied nodes are still skipped; only bin linking continues, matching the semantics of `--ignore-scripts`. Regression test added in test/arborist/rebuild.js: with `allowScripts: { 'denied-with-bin': false }` the postinstall does not run but `.bin/denied-with-bin` is still created.
|
Not sure if this was intentional. I could see it potentially as a defense in depth action. I could be wrong but if bin\blaa doesn't exist, then it adds extra protection. There is the case of other approved script providing the bin. Thinking of esbuild for example. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Backport of the bin-link half of the v12 allowScripts gate change to
release/v11.On npm 11 (released and
release/v11HEAD), a package denied viaallowScripts: { "<pkg>": false }is installed intonode_modules/<pkg>but itsnode_modules/.bin/<bin>symlinks are never created. The package directory exists and the bin file is on disk and executable, but nothing puts it onPATH, so downstream build steps that shell out to the bin fail withcommand not found. Only denied packages that declare abinare affected (esbuild, nx, etc.).The cause is in
workspaces/arborist/lib/arborist/rebuild.js. The deny gate was an early return at the top of#addToBuildSet, which dropped the node out of the build set entirely. The build set is also whatbuild:queuereads to populate thebinqueue used bybinLinks, so denied nodes lose their bin links along with their scripts. That mismatches--ignore-scripts, which skips lifecycle scripts but still links bins.The fix moves the deny check out of the early return and into the per-key dispatch loop, gating only
preinstall/install/postinstall/preparewhile leavingbinto be queued normally. Same shape as the v12 fix in #9480 / #9424, scoped down to the bin issue so v11 keeps its current opt-in semantics (onlyfalsedenies,null/unreviewed still falls through).--ignore-scriptsand--dangerously-allow-all-scriptsprecedence is unchanged.Existing Issue
Fixes #9681
Screenshots / repro
Repro from the issue (npm 11.17.0, before this PR):
After this PR the bin link is created and
esbuild --versionruns; theinstallscript is still skipped.AI disclosure
This change was written with the assistance of Claude. I have reviewed the diff and the test and take responsibility for the code.
Test Coverage
New regression test in
workspaces/arborist/test/arborist/rebuild.js:with a dedicated fixture at
workspaces/arborist/test/fixtures/reify-cases/testing-allow-scripts-deny-bin.js(one depdenied-with-binthat has both apostinstalland abin). The test asserts:postinstalldid NOT run (sentinel file absent).node_modules/.bin/denied-with-binIS a symlink (bin linking happened).Verified both directions against
release/v11:ENOENTon.bin/denied-with-bin(bug reproduced).Full
workspaces/arboristrebuild suite is green (30/30), including the existingallowScripts deny entry skips the build set entry for that nodeanddangerouslyAllowAllScripts bypasses the deny gatecases. Lint clean on changed files. Diff is contained to:No
.github/, tooling, or dependency changes.