Repository navigation
fix(git): GHSA-5pwg-5xfw-x322 - a concurrent alternates rewrite lets tools read objects outside --repository - #5677
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>
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 eb9c526b84e3a8d5f3e9a436c2e4d26d3ac25eb0.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: cliffhall <cliff@futurescale.com>
|
| Tools | Prompts | Resources | Resource templates | |
|---|---|---|---|---|
| Base | 9 | 0 | 1 | 0 |
| Head | 9 | 0 | 1 | 0 |
Updated by this run for eb9c526b84e3a8d5f3e9a436c2e4d26d3ac25eb0.
|
| Tools | Prompts | Resources | Resource templates | |
|---|---|---|---|---|
| Base | 1 | 1 | 0 | 0 |
| Head | 1 | 1 | 0 | 0 |
Updated by this run for eb9c526b84e3a8d5f3e9a436c2e4d26d3ac25eb0.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: cliffhall <cliff@futurescale.com>
cliffhall
left a comment
There was a problem hiding this comment.
Round 5: 1 nit, nothing blocking.
Path(repo.common_dir).resolve().validate_opened_repoalready resolves bothrev-parse --git-common-dirandrepo.common_dirand requires them inside the allowed repository (or equal to the root's own common dir). It also walks each resolved directory with_check_git_dir_contents. Resolving here therefore names the same directory that check approved, and fixes it for the whole call. On POSIX the links pointed through the same path before, so nothing new is followed.- Windows.
Test git (Windows)on 3a91430 rantests\test_alternates_race.pywith 16 passed and 1 skipped (the chmod test, skipped by design). Writing withnewline="\n"makes the planted entry one git honours on Windows.test_unrestricted_git_show_follows_alternatesshows that, since it passes only when git follows the entry. So the restricted route tests now pass on Windows because the private store is in place, not because the entry was ignored. - Checks. Locally on 3a91430: ruff, ruff format, pyright and the git suite are green.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: cliffhall <cliff@futurescale.com>
Closes #5669
Fix for GHSA-5pwg-5xfw-x322. 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
Under
--repository, every tool call and prompt now runs git on a private object directory of its own, so git reads only the repository's own objects. Before, an alternates file that was empty when_check_git_dir_contentsread it could be rewritten before git looked up an object, and git then followed it.Git has no setting that turns alternates off: it always reads
<object dir>/info/alternates, and an alternate's own alternates as well, so they cannot be switched off withGIT_ALTERNATE_OBJECT_DIRECTORIESeither. Instead:_own_object_store(repo)creates a temp directory holding links to the repository's 256 loose-object directories and itspackdirectory, and nothing else (symlinks on POSIX, junctions on Windows, which need no privilege). It pointsGIT_OBJECT_DIRECTORYthere (custom_environment), so git looks for alternates in<temp>/info/alternates, which does not exist. The repository's own alternates file is never read while the store is in place.cat-fileprocesses before and after (clear_cache), and removes the links as links (unlink/rmdir), so their targets are never touched.objects/xxthe repository lacks yet, so git finds nothing there, as in the store itself (_GIT_LOCKkeeps another call from creating one meanwhile). A read-only call therefore creates nothing in the repository, and works on a store it cannot write to (a read-only mount, another user's repository). On Windows this also avoids_winapi.CreateJunction, which refuses a missing target (review round 3).xxdirectory and renames it there, and a pack intopack. Objects git writes therefore land in the real store. Without an entry, git would createxxinside the private directory and the object would be lost at cleanup. So for the tools annotated as writes (git_commit,git_add,git_reset,git_create_branch,git_checkout,git_merge, each marked@writes_objectsat registration), every name has an entry. Each missingobjects/xxis created first, as git would on its first write to it. One that cannot be created (OSError) is held by an empty placeholder file, so a write into it fails as it would in the store, instead of landing in the private directory. GitPython's own object writes (index.add/index.commit) go to the real store directly, as before.open_repoenters the store into a per-call scope, aftervalidate_opened_repo, when--repositoryis set. The scope is_one_call(), aContextVarholding anExitStack.reports_failures(every tool) and the two promptwithstatements open the scope, and it is torn down when the call ends. Most tools never close the repository they open, so the repo's lifetime could not do this.open_reporefuses (RuntimeError) to open a restricted repository outside a scope.git_showand its registration are back to their v2/main form.Without
--repositorynothing changes, and alternates keep working (--shared/--referenceclones). The_check_git_dir_contentscheck when the repository is opened is unchanged, so a stable alternates entry is still refused with the same error.Composing with the other git fixes:
open_repogains two lines aftervalidate_opened_repo(...)and does not touch its constructor line. It works on whateverrepothat line builds, including D's_LiteralRepo(path, expand_vars=False), since it uses onlyrepo.common_dir,repo.git.custom_environmentandrepo.git.clear_cache. No tool body is edited.Server Details
mcp-server-git)_own_object_store,_CALL,_WRITES,_one_calland_read_own_objects_for_call(just below_ALTERNATES);reports_failuresand the newwrites_objectsafter it; one@writes_objectsline on each of the six write tools' registrations; the two promptwithstatements;open_repo(two lines). No change to any tool's schema, description or annotations, and no snapshot change.Motivation and Context
GHSA-5pwg-5xfw-x322: a check-then-use race between
_check_git_dir_contentsand git's object lookups. Checking the file again cannot close it, so git is made to not consult the repository's alternates at all for the call. Review round 1 showed the same window ongit_diff,git_log,git_checkout,git_create_branchand thegit_summarize_changesprompt. The store now covers every route.Left open: symlink or junction swaps inside
.gitafter the check (for exampleobjects/packreplaced with a link). A regular-filewrite_filecannot create them; the reviewer agreed this is out of scope. Under--repository, the first call of a write tool creates any missing emptyobjects/xxdirectories in the repository, which git would create on its first write anyway. Read-only tools create none.How Has This Been Tested?
Regression tests
src/git/tests/test_alternates_race.py, protocol-level through an in-memory client and deterministic, with no race and no retries._check_git_dir_contentsis wrapped so it writes a sibling-store entry intoobjects/info/alternatesright after it passes. Each route is driven that way and must fail without leaking anything:git_showon a blob, a commit andcommit:;git_diffagainst a sibling commit;git_logwith HEAD on a branch naming a sibling commit;git_checkoutof a sibling commit, asserting the sibling file is not written;git_create_branchwith a sibling base, asserting no branch is created;git_summarize_changesprompt.All 8 fail with the store removed and pass with it. The file also covers:
git_show,git_diff,git_logand the prompt;objects/xxdirectories yet:git_add,git_commit,git_create_branch,git_checkout, and agit_mergethat makes a merge commit through git, after whichgit fsckis clean;objects/xxdirectory (review round 2);pack, and a write has all 256 pluspack. On an unwritable store, a write has a placeholder for each directory it could not create;objects/made unwritable (skipped on Windows and as root),git_status,git_log,git_showand a write tool that adds no object (git_create_branch) all work. These two tests fail with an unconditionalmkdir;Original race repro (the triage's
t_alt.py, 300git_showcalls against a thread flapping the alternates file): 40/300 leaked before, 0/300 after.Inspector CLI 2.12.0,
mcp-server-git --repository <own>, both--protocol-era legacyandmodern, the same results in each:git_showown blob →OWN;HEAD→ commit and patch;SIBLING_ONLY;git_add+git_commitsucceed;git_diff HEAD~1shows the change;git_diff <sibling commit>→ error;git fsckclean afterwards; nomcp-git-objects-*left in$TMPDIR.npm run local:gate→ EXIT=0. git coverage:server.py100% lines/branches. The Windows junction branches are# pragma: no coverbecause the gate runs on Linux. They run in theTest git (Windows)CI leg; that path was not run locally (macOS only).No LLM-client run: this is a confinement fix with no change to what an LLM sees for in-repository objects, and the race isn't drivable through a chat client. The Inspector runs above are the client evidence.
Breaking Changes
None. Under
--repository, git does not read the commit-graph inobjects/infoduring a call, which affects only performance.Types of changes
Checklist
--repository, and every tool now holds to that.🤖 Generated with Claude Code