fix(arborist): match allowScripts keys for local paths - #9901
Open
lazerg wants to merge 2 commits into
Open
Conversation
Contributor
Author
|
The Test - Windows - 24.15.0 job fails in Reset Deps, where node crashes with exit code 3221226505 before any test runs, and the other five Windows jobs pass, so it is unrelated to this change. I cannot re-run it from the fork. |
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.
What / Why
An
allowScriptsentry for a local dependency never matches it, so the install scripts stay blocked whichever form of the path is used as the key. On Windows that includes the absolute path from the error message, which is what this issue reports; on every platform it also includes the relative form the lockfile stores.matchFileOrDirinworkspaces/arborist/lib/script-allowed.jscomparednode.resolvedagainst npa'ssaveSpecandfetchSpec. The loaded tree gets itsresolvedfromconsistentResolve, which returnsfile:glued onto the absolutefetchSpecand therefore keeps backslashes on Windows. npa'ssaveSpecis always forward-slashed and stays relative when the key is relative, andfetchSpecnever carries thefile:prefix, so neither side lines up. The matcher now also compares againstfile:${parsed.fetchSpec}, the same stringconsistentResolvebuilds.keyTargetsNodeinlib/utils/allow-scripts-writer.jscarried its own copy of that comparison and drifted the same way, which leftnpm install-scripts approvewriting a key it could not then recognise. Both call sites now share one exported helper, so they cannot disagree again.Matching a local tarball by bare package name is deliberately still unsupported: a local tarball's name comes from its own manifest, so
matchRegistryrejects it, andnameKeyForrefuses to write one for the same reason.Testing
New case in
workspaces/arborist/test/script-allowed.js, next to the existing local-tarball one: a node resolved to an absolutefile:path matches both the relative and the absolute key. It fails without the change. Also checked by hand, installing a local tgz with an install script and"allowScripts": { "file:scripty-1.0.0.tgz": true }: blocked before, script runs after.References
Fixes #9900