Skip to content

fix(install-scripts): preserve trusted source identities - #9794

Open
martinrrm wants to merge 6 commits into
latestfrom
fix/9738-remote-install-scripts
Open

martinrrm wants to merge 6 commits into
latestfrom
fix/9738-remote-install-scripts

Conversation

@martinrrm

@martinrrm martinrrm commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add npm approve-scripts, npm deny-scripts, and the npm install-scripts approve/deny/list/prune workflow for reviewing dependency lifecycle scripts.
  • Match and write policy entries from trusted resolver identities for registry, remote tarball, git, file, and linked-store dependencies instead of package-controlled manifest fields or internal .store paths.
  • Preserve deny-wins behavior across equivalent file paths and linked installs while retaining compatibility with existing file policy spellings.
  • Dereference and deduplicate linked targets, retain link names as selectors, and support exact source selectors for ambiguous dependencies.
  • Keep exact git selectors commit-aware, honor linked-store registry denies, and allow an explicitly selected identity to approve multi-link file targets.
  • Document source-specific approval, denial, listing, pruning, and pinning behavior.

Regression coverage

  • Registry identity and alias trust boundaries, remote URL exactness, hosted git commits, local path equivalence, and malformed sources.
  • Linked install/store identities, deny-wins behavior, exact selectors, ambiguous names, multiple link identities, and pruning.
  • Rebuild/reify lifecycle enforcement and command output for approve, deny, list, and JSON modes.

Validation

  • Full @npmcli/arborist tests pass locally with 100% statements, branches, functions, and lines; lint and postlint pass.
  • Full @npmcli/config and docs workspace tests, lint, and postlint pass locally.
  • Focused root approve/install/writer tests and root lint pass locally.
  • Refreshed cross-platform CI is running.

Fixes #9738.

Draft intentionally while the refreshed CI matrix completes.

martinrrm and others added 2 commits October 28, 2026 17:49
Use trusted resolver and lockfile identities for remote, git, file, and linked dependencies. Keep approval, denial, warnings, documentation, and policy matching consistent without treating canonical physical paths as equivalent identities.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 9a58801a-1dff-40d8-b74c-b21545984d73
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 3e53db77-0fe4-4320-8ada-f2962ddd303c
@martinrrm martinrrm closed this Oct 28, 2026
@martinrrm
martinrrm force-pushed the fix/9738-remote-install-scripts branch from e41c1d9 to 51c2bf8 Compare October 28, 2026 18:20
@martinrrm martinrrm reopened this Oct 28, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 3e53db77-0fe4-4320-8ada-f2962ddd303c
@martinrrm martinrrm changed the title Fix/9738 remote install scripts fix(install-scripts): preserve trusted source identities Oct 28, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3e53db77-0fe4-4320-8ada-f2962ddd303c
@martinrrm
martinrrm marked this pull request as ready for review October 28, 2026 21:33
@martinrrm
martinrrm requested a review from a team as a code owner October 28, 2026 21:33
jeffkl
jeffkl previously approved these changes Oct 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical source-identity matching and Git-pinning flaws can authorize scripts for unrelated paths, replacement tarballs, or unapproved commits.

5 open issues
What changed in this PR

This PR updates npm’s install-script approval workflow to use trusted dependency source identities, addressing remote-tarball approvals reported in #9738.

Changes:

  • Updates source matching and policy writing for remote, git, file, and linked dependencies.
  • Adds source-aware selectors, ambiguity checks, and clearer pending-script output.
  • Expands regression coverage and documents source-specific approval, denial, and pinning.
File Description
workspaces/​config/​lib/​definitions/​definitions.js Clarifies source-specific denial behavior.
workspaces/​arborist/​test/​unreviewed-scripts.js Tests linked-directory review status.
workspaces/​arborist/​test/​script-allowed.js Expands file identity and path-matching coverage.
workspaces/​arborist/​test/​arborist/​reify.js Updates the linked lifecycle approval identity.
workspaces/​arborist/​test/​arborist/​rebuild.js Tests linked-source lifecycle enforcement and compatibility.
workspaces/​arborist/​lib/​script-allowed.js Adds lockfile file identities and revises source matching.
test/​lib/​utils/​allow-scripts-writer.js Tests trusted policy keys and deny precedence.
test/​lib/​commands/​install-scripts.js Covers source selectors, ambiguity, and command output.
test/​lib/​commands/​approve-scripts.js Updates provenance fixtures and linked-source expectations.
tap-snapshots/​test/​lib/​docs.js.test.cjs Refreshes the denial configuration documentation snapshot.
lib/​utils/​allow-scripts-writer.js Writes source-aware approval and denial keys.
lib/​utils/​allow-scripts-cmd.js Adds source selection, link deduplication, and ambiguity handling.
docs/​lib/​content/​commands/​npm-install-scripts.md Documents source-aware workflow behavior.
docs/​lib/​content/​commands/​npm-deny-scripts.md Explains source-specific denial identities.
docs/​lib/​content/​commands/​npm-approve-scripts.md Explains trusted selectors and pinning behavior.

Review effort: Balanced

Comment thread lib/utils/allow-scripts-writer.js Resolved
Comment thread lib/utils/allow-scripts-cmd.js Resolved
Comment thread lib/utils/allow-scripts-writer.js Resolved
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 3e53db77-0fe4-4320-8ada-f2962ddd303c
jeffkl
jeffkl previously approved these changes Nov 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

File-source handling blocks approval and denial of linked-install tarball targets and hides the exact selectors needed for targets with multiple trusted file identities.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Expose multiple trusted file identities in listings and errors

lib/​utils/​allow-scripts-cmd.js:61

For a target with multiple trusted file identities, versionedKeyFor() returns null, so ls prints [untrusted source] and JSON exposes only the bare name. Approving that name then fails with ENOMATCH, leaving the supported exact selectors undiscoverable through the documented workflow. Show the choices from filePolicyIdentities(node) in listings and in the error when bare-name approval cannot choose one identity.

5 resolved since last review

Review effort: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3e53db77-0fe4-4320-8ada-f2962ddd303c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Blocked postinstall execution for remote installation - allowScripts not recognized (npm@12.0.0)

3 participants