Repository navigation
Conversation
…side --repository The walk of a git directory judged only symbolic links by where they resolve. A Windows directory junction is not a symbolic link to Python (DirEntry.is_symlink() is false, is_dir() true), so the walk entered its target as an ordinary directory without checking where that was, and git follows a junction as it follows a link. Every directory entry is now resolved and held to the same boundary as a link. An ordinary directory resolves to itself and passes, so no junction detection is needed, which keeps one code path for Python 3.10 through 3.12+ (is_junction() exists only from 3.12). A dangling junction is no longer walked. Closes #5520 Co-Authored-By: Claude Fable 5.2 <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 7660d0061605489e6b637d6adfd3e4a811218f68.
There was a problem hiding this comment.
🔵 Needs a closer look
This Windows filesystem security-boundary change needs maintainer confirmation that native real- and dangling-junction tests pass, since Windows CI was still running and POSIX substitutes cannot validate native reparse-point behavior.
No open issues 🎉
What changed in this PR
This PR closes #5520 by extending the Git server’s --repository confinement check to reject Windows directory junctions that lead outside the permitted boundary.
Changes:
- Checks the resolved destination of every directory entry and walks permitted targets while avoiding cycles and missing targets.
- Adds real Windows junction tests and cross-platform junction-like regression tests.
- Documents junction restrictions and the existing hooks exception.
| File | Description |
|---|---|
src/git/tests/test_junction.py |
Adds coverage for escaping, permitted, cyclic, and dangling junctions. |
src/git/src/mcp_server_git/server.py |
Applies repository boundary checks to resolved directory entries. |
src/git/README.md |
Documents Windows junction handling under --repository. |
Review effort: Balanced
|
Copilot round 1: clean, no findings and no suppressed comments, so the review loop ends here. Its one note asked for confirmation that the native junction tests pass on Windows, which was still running at the time. They do: on this branch |
Closes #5520
Description
Under
--repository, the server walks each Git directory it opens and refuses a symbolic link that resolves outside the allowed repository (#5514). A Windows directory junction slipped past that: to Python a junction is not a symbolic link (os.DirEntry.is_symlink()is false for one andis_dir()is true), so the walk took its "ordinary directory" arm, resolved the junction and walked its target without ever asking where that target was. Git follows a junction the way it follows a link._check_git_dir_contentsnow resolves every directory entry, not only symbolic links, and holds the result to the same boundary: inside the allowed repository or inside the Git directory being walked, otherwise the repository is refused with the existing "uses '…', which is outside the allowed repository" error. An ordinary directory resolves to itself and passes. A junction that stays inside is walked where it resolves, so what it leads to is checked too; one whose target is gone is not walked (before, the scan of the missing target failed the call).The issue suggested detecting junctions with
is_junction()on Python 3.12+ and a reparse-point attribute check on 3.10 and 3.11. Judging every directory by where it resolves needs no detection, so there is one code path for every supported Python and platform, no Windows-only branch for the Linux coverage gate to excuse, and a non-junction reparse point that redirects a directory (a volume mount point, say) is held to the boundary as well.Server Details
--repositoryconfinement check (_check_git_dir_contentsinsrc/git/src/mcp_server_git/server.py); README; tests. No tool, schema or description changes.Motivation and Context
#5520, the follow-up left open by GHSA-q74p-4wrc-q7w6 under "Not covered by this fix". Windows only; POSIX hosts were not affected.
How Has This Been Tested?
Tests (
src/git/tests/test_junction.py, new, all through the real server and an in-memory client):mklink /J, Windows only, so they run on the Test git (Windows) CI leg: a junction at.git/objectsor.git/refsleading outside is refused; a junction that stays inside is followed and a second junction behind it leading outside is refused; junctions that stay inside (and ahooksjunction, and a cycle) are accepted; a dangling junction inside is not walked; a dangling junction outside is refused.os.scandiris wrapped so a directory symlink answers as a junction does (is_symlink()false,is_dir()true). These are what the Linux coverage gate sees.Failing without the fix: on POSIX, with
server.pyrestored fromv2/main, the three junction-like tests fail (the two "leading outside" cases and "followed and checked") and pass with the fix.On Windows, from CI (Python 3.10, the version the leg pins):
tests\test_junction.py .........., all 10 pass, none skipped, the real-junction tests included.server.pyrestored fromv2/main, on a throwaway branch where the tests expected to fail were markedxfail(strict for the refusal tests, so the job would have failed had any passed), Test git (Windows):tests\test_junction.py xxxxxx..xx, 8 xfailed. Every real-junction refusal test and both dangling-junction tests fail without the fix; only the two "stay inside" acceptance tests pass, as they should. That branch had no PR and is deleted.Not exercised on Windows: Python 3.12 and later, since the leg runs only the pinned 3.10. The change does not branch on the Python version.
Clients (macOS, where a junction cannot exist, so these show the unchanged behavior of the rewritten walk, not the Windows case): a server started with
--repository <allowed>, where<allowed>/.git/extrais a directory link that stays inside and<allowed>/nested/.git/refsis a directory link to another repository'srefs.--protocol-era legacyand--protocol-era modern,tools/call git_status:repo_path=<allowed>→"isError":false,Repository status:\nOn branch main …in both eras (the modern result carries_metaio.modelcontextprotocol/serverInfo).repo_path=<allowed>/nested→"isError":true,Repository path '<allowed>/nested' uses '<other>/.git/refs', which is outside the allowed repository '<allowed>'in both eras.claude -p --mcp-config … --strict-mcp-config); the era cannot be selected or read from this client. Prompt: "Call the git_status tool of the git server twice: once with repo_path<allowed>and once with repo_path<allowed>/nested…". It reported the first call succeeded (Repository status:) and the second failed with the same "outside the allowed repository" error.npm run local:gateexits 0;src/mcp_server_git/server.pystays at 100% lines and branches.Breaking Changes
None for client configuration. On Windows, a repository whose Git directory holds a junction leading outside the
--repositoryit is served under is now refused; that is the fix.Types of changes
Checklist
npm run changeset) if this changes what a TypeScript server publishes (not applicable: a Python server)Additional context
@SalyyS1 prototyped a fix for this on the issue (an
_is_junctionhelper usingis_junction()with a reparse-point fallback, withmklink /Jtests). This PR takes a different route in the walk, but the idea of exercising real junctions withmklink /Jon the Windows leg is theirs. Thank you.🤖 Generated with Claude Code