Repository navigation
fix(git): GHSA-qf89-h82f-h5r5 - git_merge overwrites ignored local files on a merge commit - #5679
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: cliffhall <cliff@futurescale.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: cliffhall <cliff@futurescale.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: cliffhall <cliff@futurescale.com>
|
|
| Tools | Prompts | Resources | Resource templates | |
|---|---|---|---|---|
| Base | 14 | 2 | 0 | 0 |
| Head | 14 | 2 | 0 | 0 |
Updated by this run for 13816b7c9cad846bd07c6fdf1f436a374fa9ac6d.
Closes #5671
Fix for GHSA-qf89-h82f-h5r5. It was written and reviewed in the advisory's private fork, where a subagent reviewer stood in for Copilot (which cannot review a private fork) until a clean round. Per the advisory flow this PR gets no Copilot review. The private fork has no Actions, so this PR's CI is the first CI run on the change; the full
npm run local:gatepassed on this exact head and on a rollup of all eight advisory fixes.Description
git_mergepasses--no-overwrite-ignore, but git honors that flag only on a fast-forward. When the branches have diverged andfast_forward_only=false, git's merge-commit path (merge-ort, and-s recursivetoo, on git 2.39 and 2.54) writes the source's version of a path over an ignored, untracked local file (a.env, say) and reports success. The README promises the tool refuses such a merge.This adds a server-side pre-check,
_ignored_files_overwritten, run before a non-fast-forward merge:git diff-tree -r -z --no-renames --diff-filter=A HEAD <source>). The tree is required clean beforehand, so only such a path can land on an untracked file.git ls-files --others --ignored --exclude-standardover those paths (as:(top,literal)pathspecs) gives the ignored files among them. Any hit refuses the merge before git runs:Merge of '<source>' into '<target>' refused: it would overwrite ignored local files: <paths>. Nothing was changed. Move or remove them first.The fast-forward path is unchanged: git refuses there itself, and the existing test still covers it.
Server Details
mcp-server-git)git_mergeand a new private helper_ignored_files_overwritteninserver.py; thegit_mergeentry in README "### Tools" (the refusal now says it holds for merge commits too). No schema, description or annotation change.Motivation and Context
GHSA-qf89-h82f-h5r5.
How Has This Been Tested?
tests/test_merge.py, driven through an in-memory MCP client: an ignored.envon a diverged merge withfast_forward_only=false(failed on v2/main: merged and overwrote; now refused, bytes and HEAD unchanged); an ignored directory where the source tracks a file plus an ignored file where the source needs a directory (both refused, contents kept); and a new file inside an ignored directory (still merges, local ignored file kept). Existing fast-forward and non-ignored untracked tests pass unchanged.server.pycoverage 100% lines / 99.5% branches.@modelcontextprotocol/inspector@2.12.0, stdio,--repository <fixture>) callinggit_mergewithfast_forward_only=falseon a diverged fixture with an ignored local.env, in both eras:--protocol-era modernandlegacy:Merged 'source' into 'main' with merge commit …, exit 0,.envreplaced by the branch's bytes.isError: true,Merge of 'source' into 'main' refused: it would overwrite ignored local files: .env. Nothing was changed. Move or remove them first., exit 5,.envkept.npm run local:gate: EXIT=0.What this leaves open
ort'sunique_pathsuffix (<path>~HEAD_1, ...) is not predicted: git adds it only when<path>~HEADis itself a path in the merge, not because of a worktree file.-c merge.directoryRenames=false, so a path the source adds in a directory HEAD renamed lands where the source put it, not in the renamed directory (a merge-behavior change from git's defaultconflict, which would otherwise stop on a conflict there).Round 1 changes
merge.directoryRenames=false(through a new optionalconfigkeyword on_rewrite_tree;HARDENED_CONFIGuntouched), so it writes no path outside what the check predicts.os.path.samestat) before thels-fileslookup.<path>~HEAD,<path>~<source sha>) are checked too.Breaking Changes
None. A merge that would have overwritten ignored files is now refused; no configuration change.
Types of changes
Checklist
🤖 Generated with Claude Code