{"slug": "a-submodule-s-git-config-could-make-mcp-server-git-run-a-program", "title": "A submodule's .git/config could make mcp-server-git run a program", "summary": "The Model Context Protocol's reference Git server, mcp-server-git, was patched in version 2026.11.18 after security advisory GHSA-8wv7-r664-7594 showed that a submodule's own .git/config could make the server execute a program named in settings such as diff.external, textconv or filter.<name>.clean during git_diff, git_checkout or git_add. The flaw bypassed the harden_repo function added in 2026.11.11 for earlier advisory GHSA-6hqx-gqrx-c5r2, which only read the top-level repo's config; in the advisory's reproduction the payload wrote its marker 3 times out of 3 with the config in place and 0 out of 3 in control repos. Only repos that arrive with their .git folders intact — a zipped project, shared dev volume or CI artifact, not a plain git clone or GitHub source ZIP — can trigger it, and the server had about 460K PyPI downloads in the last 30 days; 2026.11.27 is the latest release.", "body_md": "# A submodule's .git/config could make mcp-server-git run a program\n\nYusef Syed. .\n\nIf an AI agent used `mcp-server-git` on a repo someone else prepared, a diff, a checkout or a `git add .` could run a program named in a submodule's own `.git/config`. It's fixed in 2026.11.18, so update (2026.11.27 is the latest right now). A plain `git clone` doesn't trigger it, because the repo has to arrive with its `.git` folders still inside, like a zipped project or a shared dev volume.\n\n`mcp-server-git` is the Model Context Protocol project's reference Git server. An agent uses it to run tools like `git_status`, `git_diff`, `git_checkout` and `git_add` on a repo you point it at, and it had about 460K PyPI downloads in the last 30 days (pypistats). Its README says it never runs a program a repo's configuration names. A submodule got around that. The diff case also needs one setting in the parent repo, covered below. The advisory is [GHSA-8wv7-r664-7594](https://github.com/modelcontextprotocol/servers/security/advisories/GHSA-8wv7-r664-7594).\n\n## What happened\n\nGit config can name programs. `diff.external` runs a diff tool, a textconv driver converts files before a diff, and a `filter.<name>.clean` command runs when Git hashes a working-tree file, for `git add` or to check whether the file changed. That's fine in your own repos. In a repo someone else hands you, `git diff` can run their program, which is what the server promises to prevent.\n\nThe README puts it this way: \"A repository's configuration and hooks travel with it (an unpacked archive, a shared folder, a vendored tree), so the server never runs a program they name, with or without `--repository`.\"\n\nTo keep that promise, the server runs a function called `harden_repo` on every repo it opens. It pins a list of safe settings through `GIT_CONFIG_COUNT` overrides, which outrank every config file. It also reads which filter and merge drivers the repo's config defines and overrides each one with an empty command. The diff tools pass `--no-ext-diff --no-textconv` on top of that. All of this landed in 2026.11.11 as the fix for an earlier advisory, [GHSA-6hqx-gqrx-c5r2](https://github.com/modelcontextprotocol/servers/security/advisories/GHSA-6hqx-gqrx-c5r2).\n\nBut `harden_repo` only reads the config of the top-level repo. A submodule is its own repo with its own `.git/config`, and the server never read that file. For the diff tools, the chain looks like this:\n\n``` php\ngit_diff -> git diff in the parent (parent config has diff.submodule=diff)\n         -> nested git diff inside the submodule (no --no-ext-diff)\n         -> the submodule's diff.external runs\n```\n\nThe advisory's reproduction used a payload that only appends a word to a file in a temporary directory. Each affected call wrote that marker 3 times out of 3 with the config in place, and 0 out of 3 in the control repos.\n\n## Am I affected?\n\nOnly if the server was pointed at a repo that arrived with its `.git` folders inside. A plain `git clone` doesn't copy `.git/config`, and GitHub's source ZIP leaves out `.git` completely, so cloning a repo off GitHub doesn't trigger this. A zipped project, a shared dev volume, a CI artifact or a workspace where something else already wrote the config can. When it happens, the program runs as whatever user is running the server.\n\nRunning plain `git diff` in a folder like that yourself would do the same thing. The difference is that this server says it never does, and an agent will call it on a repo you haven't looked at. I haven't seen this happen. The case I have in mind is an agent handed a zipped repo and asked what changed, which would call `git_diff` first.\n\nTo check, look at the version your MCP client actually runs. From a Python environment:\n\n```\npip show mcp-server-git\n```\n\nAnything before 2026.11.18 is affected. Also run `git --version`: on Git older than 2.33, the fixed server refuses repos with a checked-out submodule. If you can't update yet, don't point the server at repos that arrived with their `.git` folders.\n\nIt's rated High, CVSS 7.8. The vector has `AV:L/UI:R`: the config has to already be on disk, and someone has to point the server at the repo. My report suggested the same vector as the earlier advisory, and the maintainers kept it.\n\n## Why the hardening missed it\n\nA comment in the 2026.11.11 code says that when Git compares the working tree, it looks inside each submodule using that submodule's own config, which `harden_repo` never sees. So `git_status`, `git_diff` and `git_diff_unstaged` got a flag:\n\n```\n_NO_SUBMODULE_STATUS = \"--ignore-submodules=dirty\"\n```\n\nThat covered the case in the comment. Two other paths were still open.\n\nAdd and checkout were one. In 2026.11.11 they come down to:\n\n```\nrepo.git.add(\".\")\nrepo.git.checkout(branch_name)\n```\n\nNeither passes a submodule flag, and `git add` and `git checkout` don't accept `--ignore-submodules` anyway. Git checks the submodule's working tree and can run the `filter.<name>.clean` command from the submodule's config. The repo doesn't need a `.gitmodules` entry for this. A gitlink (the submodule's entry in the index) is enough.\n\nThe diff tools were the other, and this one needs `diff.submodule=diff` in the parent's config. Then `git diff` runs a nested `git diff` inside each submodule that changed. The nested one doesn't inherit `--no-ext-diff --no-textconv`, so the submodule's `diff.external` or textconv driver runs. That reaches `git_diff`, `git_diff_staged` and `git_diff_unstaged`, the tools that are supposed to be read-only.\n\n`git_status`, `git_show`, `git_reset` and `git_create_branch` were not affected. `git_show` builds its diff through GitPython rather than running `git show`, which would have been. The advisory has the full reproduction, which was run against the published 2026.11.11 package with Git 2.53.0 on macOS.\n\n## The fix\n\nThe fix is in [PR #5587](https://github.com/modelcontextprotocol/servers/pull/5587). The diff path needs one new line in the list of pinned settings:\n\n```\n+    (\"diff.submodule\", \"short\"),\n```\n\nWith `short`, Git prints only the two `Subproject commit` IDs, so the nested diff never starts. For add and checkout, a new function, `_submodule_drivers()`, walks the gitlinks in the index, including nested ones, and empties the filter and merge drivers that each checked-out submodule defines. Skipping submodule paths would have been simpler, but then `git add .` would stop staging a moved submodule commit.\n\nCheckout now runs with `--quiet`. The server also refuses a repo with a checked-out submodule when Git is older than 2.33, because, per the maintainers' code comment, Git 2.31 and 2.32 drop `GIT_CONFIG_COUNT` for the Git that runs inside a submodule.\n\nThe maintainers wrote the merged fix themselves. My report suggested the first two changes, and the `--quiet` checkout and the 2.33 minimum were their additions.\n\n## Status\n\nI reported this privately on November 13. The fix, the 2026.11.18 release and the advisory all went out on November 18. Thanks to the maintainers for turning it around in five days.\n\nI'm one of the two credited reporters. I found it with AI-assisted code analysis and an automated test harness, and the report says so.\n\n## What I took from it\n\nThe hardening was careful. It checked that Git actually applied its overrides, and the code even had a comment about this risk. But a list of overrides only covers the configs the server reads, and Git reads one more for every submodule.", "url": "https://wpnews.pro/news/a-submodule-s-git-config-could-make-mcp-server-git-run-a-program", "canonical_source": "https://yusefsyed.github.io/writing/mcp-server-git-submodule-config/", "published_at": "2026-12-03 19:30:58+00:00", "updated_at": "2026-12-03 19:47:55.155556+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "ai-safety", "agent-protocols", "developer-tools"], "entities": ["mcp-server-git", "Model Context Protocol", "Yusef Syed", "GitHub", "PyPI", "GHSA-8wv7-r664-7594", "GHSA-6hqx-gqrx-c5r2"], "also_reported_by": [], "takeaway": "mcp-server-git versions before 2026.11.18 let a submodule's .git/config run diff.external, textconv or filter.<name>.clean commands because harden_repo only sanitized the top-level repo; update to 2026.11.18 or later, and on Git older than 2.33 the fixed server refuses repos with a checked-out submo", "recommendation": {"advice": "Update mcp-server-git to 2026.11.18 or later and avoid pointing it at repos that arrive with .git folders intact, such as zipped projects or shared volumes, since submodule config can execute programs.", "playbook": "agent-security", "playbook_url": "https://wpnews.pro/playbooks/agent-security"}, "alternates": {"html": "https://wpnews.pro/news/a-submodule-s-git-config-could-make-mcp-server-git-run-a-program", "markdown": "https://wpnews.pro/news/a-submodule-s-git-config-could-make-mcp-server-git-run-a-program.md", "text": "https://wpnews.pro/news/a-submodule-s-git-config-could-make-mcp-server-git-run-a-program.txt", "jsonld": "https://wpnews.pro/news/a-submodule-s-git-config-could-make-mcp-server-git-run-a-program.jsonld"}}