fix(arborist): match allowScripts keys for local paths - #9914
Merged
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
reggi
approved these changes
Aug 25, 2026
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.
Summary
Fixes
allowScriptsmatching for local file and tarball dependencies, particularly on Windows.Arborist stores a resolved Windows file source in this form:
However,
npm-package-argparses an equivalent policy key into:saveSpec: file:C:/project/vendor/pkg.tgzfetchSpec: C:\project\vendor\pkg.tgzThe existing matcher compared
node.resolvedonly withsaveSpecandfetchSpec. Neither comparison could match because one uses different separators and the other lacks thefile:prefix.Changes
• Match local file and directory sources against
file:${parsed.fetchSpec}, which is the same representation produced by Arborist'sconsistentResolve().• Resolve relative
allowScriptsfile keys from the Arborist project root rather than the process working directory.• Reuse the Arborist file/directory matcher in
allow-scripts-writer, keeping runtime enforcement and policy updates consistent.• Preserve the existing exact matching behavior for remote URLs.
• Preserve deny-wins behavior when an existing local-file policy entry is
false.The implementation intentionally does not globally normalize path separators. On POSIX systems, a backslash can be a literal filename character, so replacing every
\with/could cause two different sources to share an approval.The change also does not modify dependency resolution, lockfile generation, fetching, linking, or
consistentResolve().Security considerations
Local file and tarball dependencies continue to require an exact source identity.
This change does not:
• Match local packages by their self-reported name or version.
• Case-fold paths.
• Match by basename.
• Resolve paths through
realpath().• Treat remote URLs as local file sources.
• Change registry or Git identity matching.
This preserves the manifest-confusion protections in
allowScriptswhile recognizing the exact Windows representation npm already generates.Testing
Added regression coverage for:
• Backslash and forward-slash absolute Windows keys matching the same local tarball.
• Relative keys resolving from the project root.
•
versionedKeyFor()producing a key accepted byisScriptAllowed().• Different local paths remaining unmatched.
• Existing
falsefile entries continuing to block approval.• Windows UNC paths matching through the same
file:${fetchSpec}representation.• POSIX filenames containing literal backslashes remaining distinct.
• Remote URL policies not matching
file: sources.•
npm install-scripts pruneretaining valid local-file entries.The focused Arborist matcher, policy-writer, and prune tests pass locally. Native Windows path and UNC behavior is covered by platform-specific tests and will run in the repository's Windows CI matrix.
Fixes #9900