Skip to content

fix(patch): exclude .git when copying tarballs into the rebase repo - #10143

Open
rootvector2 wants to merge 1 commit into
npm:latestfrom
rootvector2:patch-update-strip-dotgit
Open

rootvector2 wants to merge 1 commit into
npm:latestfrom
rootvector2:patch-update-strip-dotgit

Conversation

@rootvector2

Copy link
Copy Markdown
Contributor

npm patch update rebases the existing patch in a throwaway git repo. #rebasePatch extracts the base and target dependency versions with pacote and copies each tree into that repo with fs.cp. pacote keeps a tarball's own .git/ on extract, so a dependency can ship an executable .git/hooks/pre-commit (or a .git/config with core.fsmonitor) that the copy lays over the work repo, and the git add/git commit right after run it. A publisher of a package you patch then gets code execution the moment you run npm patch update on it, with no install-script prompt in the path.

The copy that goes the other way (repo into the edit dir) already filters .git with notGitDir; the two copies into the repo did not. Pass the same filter to both so a tarball's .git never reaches the rebase repo.

Added a regression test that serves a 2.0.0 tarball carrying an executable pre-commit hook; it runs on the current tree and does not after the fix.

@rootvector2
rootvector2 requested a review from a team as a code owner October 20, 2026 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant