fix(arborist): skip extraneous orphans in strict-allow-scripts gate#9683
Open
Sanjays2402 wants to merge 1 commit into
Open
fix(arborist): skip extraneous orphans in strict-allow-scripts gate#9683Sanjays2402 wants to merge 1 commit into
Sanjays2402 wants to merge 1 commit into
Conversation
An extraneous registry node has no incoming dependency edge and is slated for pruning before reify can run any install script. buildIdealTree drops top-level orphans, but it can retain an orphan nested inside a workspace, in which case the strict-allow-scripts preflight false- positives on it (ESTRICTALLOWSCRIPTS) even though the install script will never execute. Skip extraneous nodes in collectUnreviewedScripts so the strict gate and the on-disk npm install-scripts ls listing agree. Fixes npm#9680
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
strict-allow-scriptsabortsnpm installwithESTRICTALLOWSCRIPTSon an extraneous (edgeless) registry node that lives only as a nestedpackage-lock.jsonentry inside a workspace'snode_modules. The reporter's table makes the asymmetry obvious: a realesbuildcopy with 10 incoming edges is correctly denied by name, while the orphanesbuildcopy (0 incoming edges,extraneous: true) trips the preflight as unreviewed.npm install-scripts ls, which walks the actual on-disk tree, reports the same project as fully covered — so the strict gate and the advisory listing disagree on the same node.An extraneous node has no incoming dependency edge and is slated for pruning before
reifyruns any install script:buildIdealTreedrops extraneous nodes from the ideal tree (#idealTreePruneclearsparent).rebuildschedules install scripts only for nodes fromloadActual()(the on-disk tree), and an extraneous orphan that exists only in the lockfile is not on disk.In the workspace case the reporter hit, the orphan can survive the ideal-tree prune (top-level orphans are dropped, nested-in-workspace orphans are retained), but it still never executes a script because it is not present in the actual tree. The strict-allow-scripts gate therefore must not surface it.
The fix is a one-arm continue in
collectUnreviewedScripts, alongside the existinginBundleandinertskips that protect the same property ("this node's install script is never going to run"). With that, the strict preflight andnpm install-scripts lsagree on the same tree.The repro from the issue (
core-jsstanding in foresbuild) now installs cleanly understrict-allow-scripts=true+{ "allowScripts": { "core-js": false } }. The matcher logic inscript-allowed.jsis unchanged — the orphan still has no resolved registry URL the matcher can verify, so the right place to short-circuit is the upstream filter, not the matcher.Existing Issue
Fixes #9680
Screenshots / Test Coverage
Two regression tests added to
workspaces/arborist/test/unreviewed-scripts.js:skips extraneous (orphan) registry nodes— basic case, no policy.skips extraneous nodes even when policy denies by name— covers the reporter's scenario where the orphan has no resolved URL the registry matcher can verify, so the deny falls through and the node would otherwise be reported as unreviewed.Both fail on
latestand pass with the fix:Adjacent suites stay green:
AI disclosure
This change was written with the assistance of Claude (drafting the diff, the regression test, and this PR description). I reviewed the diff and the test and take responsibility for the code.