GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(arborist): match allowScripts keys for local paths by martinrrm · Pull Request #9914 · npm/cli

Conversation

@martinrrm

@martinrrm martinrrm commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes allowScripts matching for local file and tarball dependencies, particularly on Windows.

Arborist stores a resolved Windows file source in this form:

file:C:\project\vendor\pkg.tgz

However,  npm-package-arg parses an equivalent policy key into:

saveSpec: file:C:/project/vendor/pkg.tgz
fetchSpec: C:\project\vendor\pkg.tgz

The existing matcher compared node.resolved only with saveSpec and fetchSpec. Neither comparison could match because one uses different separators and the other lacks the file:  prefix.

Changes

• Match local file and directory sources against file:${parsed.fetchSpec}, which is the same representation produced by Arborist's consistentResolve().
• Resolve relative allowScripts file 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 allowScripts while 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 by isScriptAllowed().
• Different local paths remaining unmatched.
• Existing false file 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 prune retaining 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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@martinrrm
fix(arborist): match allowScripts keys for local paths
7eab680
Co-authored-by: Copilot <[email protected]>
@martinrrm
martinrrm requested review from a team as code owners August 24, 2026 19:22
@martinrrm
test: fix allowScripts path coverage
4e5890a
Co-authored-by: Copilot <[email protected]>
reggi
reggi approved these changes Aug 25, 2026
View reviewed changes
@martinrrm
martinrrm merged commit d6c6122 into latest Aug 25, 2026
45 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@martinrrm
martinrrm deleted the fix/9900-allow-scripts-windows branch August 25, 2026 20:24
@github-actions github-actions Bot mentioned this pull request Aug 25, 2026
chore: release 12.1.0 #9839
Merged
This was referenced Aug 26, 2026
fix(arborist): match allowScripts keys for local paths #9901
Closed
fix(arborist): normalize file and directory paths in allowScripts matcher #9906
Open
@reggi reggi added the backport:v11 label Aug 27, 2026
@github-actions github-actions Bot mentioned this pull request Aug 27, 2026
fix(arborist): match allowScripts keys for local paths #9929
Merged
@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🎉 Backport to release/v11 created: #9929

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

reggi pushed a commit that referenced this pull request Aug 28, 2026
@github-actions @martinrrm
fix(arborist): match allowScripts keys for local paths (#9929)
55ae484
Backport of #9914 to `release/v11`.

Co-authored-by: martin <[email protected]>
Co-authored-by: Copilot <[email protected]>
@npm-cli-bot npm-cli-bot mentioned this pull request Sep 22, 2026
deps: upgrade npm to 12.1.0 nodejs/node#66212
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@reggi reggi reggi approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

backport:v11

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[BUG] allowScripts does not work for local tarball on Windows

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@martinrrm @reggi
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.