BREW-OTTERDOG-CVE-2026-87817 (PYSEC-2026-3982)
Vulnerability from osv_homebrew – Published: 2026-09-20 11:09 – Updated: 2026-10-01 09:31 – Source websiteSummary
Repo.__init__ decides which directory is the git directory by testing candidate paths in an order that
considers the real .git last. Two earlier tests can be satisfied by ordinary tracked files. Git
reserves only the literal name .git, so HEAD, objects/, refs/, config, gitdir, commondir
and hooks/ at a repository root are all legal tracked content.
Consequently, after a victim opens or clones an attacker's repository, GitPython resolves git_dir to
the working-tree root while real git correctly resolves <root>/.git. Everything GitPython then
treats as "inside the git directory" is attacker-authored content — including hooks/, which it
executes.
CVE-2026-87817
Affected code (3.1.59)
The discovery loop in git/repo/base.py tests, in order:
git/repo/base.py:299—isfile(curpath/gitdir)andisfile(curpath/commondir)andisfile(curpath/HEAD)git/repo/base.py:320—is_git_dir(curpath)git/repo/base.py:341—dotgit = osp.join(curpath, ".git")← the real git dir, considered last
is_git_dir (git/repo/fun.py:60) requires only that objects/ and refs/ are directories and that
HEAD is a file; HEAD's contents are never parsed. The hook path is resolved from
index.repo.git_dir (git/index/fun.py:73), i.e. the mis-resolved directory.
Proof of concept
Requires only pip install GitPython==3.1.59. Full script attached as poc1_rce.py; it runs entirely
in a temp directory and the payload only writes a marker file.
Attacker repository — four ordinary tracked files at the root:
| path | mode | content |
|---|---|---|
gitdir |
100644 | .git\n |
commondir |
100644 | .git\n |
HEAD |
100644 | ref: refs/heads/master\n |
hooks/pre-commit |
100755 | #!/bin/sh + payload |
Victim — two ordinary calls:
repo = git.Repo.clone_from(url, dst) # or git.Repo(dst)
repo.index.commit("automated commit") # code execution happens here
Observed on the PyPI release 3.1.59 (Linux and Windows):
real git says the git dir is : /tmp/.../victim/.git
GitPython says it is : /tmp/.../victim <- shadowed
attacker's hook executed : True
git fsck : (clean)
The pre-commit hook runs at git/index/base.py:1201, before write_tree(), so it fires even though
the commit later fails.
Impact
A service that opens or clones an untrusted repository with GitPython — a CI runner building a fork pull request, a code-scanning/SBOM service, a mirror, a dependency bot, an AI code-review/agent tool — can be made to:
- Execute arbitrary commands via the tracked
<root>/hooks/pre-commitwhen the victim callsindex.commit(). - Read files outside the repository: the tracked
<root>/configbecomes the repository config and is parsed withmerge_includes=True(git/repo/base.py:765), so[include] path = ~/.aws/credentialsdiscloses the file. (Repo._config_readerstill defaultsmerge_includes=True, so the hardening added in 3.1.59 for.gitmodules/GHSA-7833 does not cover this path.) - Write a config file to an attacker-chosen directory via an absolute tracked
commondir.
Delivery is silent: git clone exits 0, git fsck (including --strict, and with
transfer.fsckObjects/fetch.fsckObjects=true) reports nothing, and the clone passes every read-only
probe (head.commit, branches, is_dirty(), untracked_files, iter_commits) because a tracked
commondir of .git pins common_dir to the real .git.
Threat model / preconditions
- Attacker controls the content of a repository the victim opens or clones with GitPython (public repo, fork PR, mirrored dependency).
- For code execution, the victim performs a commit via GitPython's native
index.commit(). For the file-read impact, opening the repo and reading config is enough. GIT_WORK_TREEis not a mitigation —git_diris assigned and the discovery loop breaks before the environment is consulted.- Real git is unaffected; only GitPython mis-resolves the directory.
Remediation
- Test
curpath/.gitbefore thegitdir/commondir/HEADtriple and beforeis_git_dir(curpath). - Resolve
hook_path/_commit_hook_path/_get_validated_reflog_paththroughrepo.common_dir. - Containment-check
commondir/gitdircontents before joining (reuseSymbolicReference._get_validated_path). - Validate
HEADinis_git_dir(requireref: refs/...or a 40-hex sha). - Pass
merge_includes=FalseinRepo._config_reader(git/repo/base.py:765).
Note for the maintainers
Commit 406b98e1 (2026-05-31, "respect core.hooksPath for commit hooks") resolved the hook path via
git rev-parse --git-path, which is immune because git rediscovers the true .git. Commit 9bc287a2
(2026-07-20) reverted it to avoid an unconditional rev-parse dependency — reintroducing the exec step.
Measured at each commit with the healthy-looking layout: 406b98e1 → hook did not fire; 9bc287a2 …
3.1.59 → hook fired.
Scope note
Only the repository-root case is reported: where a real .git exists, git prefers it, and GitPython
does not. A fake git dir in a subdirectory fools real git too, so that variant is out of scope as a
general ecosystem hazard rather than a GitPython defect.
POC Files :
{
"affected": [
{
"ecosystem_specific": {
"fix": "bump",
"range_state": "fixed",
"resource": "gitpython",
"resource_purl": "pkg:pypi/gitpython@3.1.62",
"upstream_fixed_in": "3.1.60"
},
"package": {
"ecosystem": "Homebrew",
"name": "otterdog",
"purl": "pkg:brew/otterdog"
},
"ranges": [
{
"events": [
{
"introduced": "1.0.1"
},
{
"fixed": "1.4.0_3"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"database_specific": {
"confidence": "high",
"source": "matched",
"strategy": "registry",
"upstream_evidence": [
{
"ecosystem": "PyPI",
"key": "pkg:pypi/gitpython@3.1.62",
"name": "gitpython",
"resource": "gitpython",
"strategy": "registry",
"subject_version": "3.1.62"
}
]
},
"details": "### Summary\n\n`Repo.__init__` decides which directory is the git directory by testing candidate paths in an order that\nconsiders the real `.git` **last**. Two earlier tests can be satisfied by ordinary tracked files. Git\nreserves only the literal name `.git`, so `HEAD`, `objects/`, `refs/`, `config`, `gitdir`, `commondir`\nand `hooks/` at a repository root are all legal tracked content.\n\nConsequently, after a victim opens or clones an attacker\u0027s repository, GitPython resolves `git_dir` to\nthe **working-tree root** while real git correctly resolves `\u003croot\u003e/.git`. Everything GitPython then\ntreats as \"inside the git directory\" is attacker-authored content \u2014 including `hooks/`, which it\nexecutes.\n\n### CVE-2026-87817\n\n### Affected code (3.1.59)\n\nThe discovery loop in `git/repo/base.py` tests, in order:\n\n1. `git/repo/base.py:299` \u2014 `isfile(curpath/gitdir)` **and** `isfile(curpath/commondir)` **and** `isfile(curpath/HEAD)`\n2. `git/repo/base.py:320` \u2014 `is_git_dir(curpath)`\n3. `git/repo/base.py:341` \u2014 `dotgit = osp.join(curpath, \".git\")` \u2190 the real git dir, considered last\n\n`is_git_dir` (`git/repo/fun.py:60`) requires only that `objects/` and `refs/` are directories and that\n`HEAD` is a file; **`HEAD`\u0027s contents are never parsed.** The hook path is resolved from\n`index.repo.git_dir` (`git/index/fun.py:73`), i.e. the mis-resolved directory.\n\n### Proof of concept\n\nRequires only `pip install GitPython==3.1.59`. Full script attached as `poc1_rce.py`; it runs entirely\nin a temp directory and the payload only writes a marker file.\n\nAttacker repository \u2014 four ordinary tracked files at the root:\n\n| path | mode | content |\n|---|---|---|\n| `gitdir` | 100644 | `.git\\n` |\n| `commondir` | 100644 | `.git\\n` |\n| `HEAD` | 100644 | `ref: refs/heads/master\\n` |\n| `hooks/pre-commit` | **100755** | `#!/bin/sh` + payload |\n\nVictim \u2014 two ordinary calls:\n\n```python\nrepo = git.Repo.clone_from(url, dst) # or git.Repo(dst)\nrepo.index.commit(\"automated commit\") # code execution happens here\n```\n\nObserved on the PyPI release 3.1.59 (Linux and Windows):\n\n```\nreal git says the git dir is : /tmp/.../victim/.git\nGitPython says it is : /tmp/.../victim \u003c- shadowed\nattacker\u0027s hook executed : True\ngit fsck : (clean)\n```\n\nThe `pre-commit` hook runs at `git/index/base.py:1201`, before `write_tree()`, so it fires even though\nthe commit later fails.\n\n### Impact\n\nA service that opens or clones an untrusted repository with GitPython \u2014 a CI runner building a fork\npull request, a code-scanning/SBOM service, a mirror, a dependency bot, an AI code-review/agent tool \u2014\ncan be made to:\n\n1. **Execute arbitrary commands** via the tracked `\u003croot\u003e/hooks/pre-commit` when the victim calls\n `index.commit()`.\n2. **Read files outside the repository**: the tracked `\u003croot\u003e/config` becomes the repository config and\n is parsed with `merge_includes=True` (`git/repo/base.py:765`), so `[include] path = ~/.aws/credentials`\n discloses the file. (`Repo._config_reader` still defaults `merge_includes=True`, so the hardening\n added in 3.1.59 for `.gitmodules`/GHSA-7833 does not cover this path.)\n3. **Write a config file to an attacker-chosen directory** via an absolute tracked `commondir`.\n\nDelivery is silent: `git clone` exits 0, `git fsck` (including `--strict`, and with\n`transfer.fsckObjects`/`fetch.fsckObjects=true`) reports nothing, and the clone passes every read-only\nprobe (`head.commit`, `branches`, `is_dirty()`, `untracked_files`, `iter_commits`) because a tracked\n`commondir` of `.git` pins `common_dir` to the real `.git`.\n\n### Threat model / preconditions\n\n- Attacker controls the content of a repository the victim opens or clones with GitPython (public repo,\n fork PR, mirrored dependency).\n- For code execution, the victim performs a commit via GitPython\u0027s native `index.commit()`. For the\n file-read impact, opening the repo and reading config is enough.\n- `GIT_WORK_TREE` is **not** a mitigation \u2014 `git_dir` is assigned and the discovery loop breaks before\n the environment is consulted.\n- Real git is unaffected; only GitPython mis-resolves the directory.\n\n### Remediation\n\n1. Test `curpath/.git` **before** the `gitdir`/`commondir`/`HEAD` triple and before `is_git_dir(curpath)`.\n2. Resolve `hook_path` / `_commit_hook_path` / `_get_validated_reflog_path` through `repo.common_dir`.\n3. Containment-check `commondir`/`gitdir` contents before joining (reuse\n `SymbolicReference._get_validated_path`).\n4. Validate `HEAD` in `is_git_dir` (require `ref: refs/...` or a 40-hex sha).\n5. Pass `merge_includes=False` in `Repo._config_reader` (`git/repo/base.py:765`).\n\n### Note for the maintainers\n\nCommit `406b98e1` (2026-05-31, \"respect core.hooksPath for commit hooks\") resolved the hook path via\n`git rev-parse --git-path`, which is immune because git rediscovers the true `.git`. Commit `9bc287a2`\n(2026-07-20) reverted it to avoid an unconditional `rev-parse` dependency \u2014 reintroducing the exec step.\nMeasured at each commit with the healthy-looking layout: `406b98e1` \u2192 hook did not fire; `9bc287a2` \u2026\n`3.1.59` \u2192 hook fired.\n\n### Scope note\n\nOnly the **repository-root** case is reported: where a real `.git` exists, git prefers it, and GitPython\ndoes not. A fake git dir in a subdirectory fools real git too, so that variant is out of scope as a\ngeneral ecosystem hazard rather than a GitPython defect.\n\n###POC Files :\n[poc1_rce.py](https://github.com/user-attachments/files/31388464/poc1_rce.py)\n[poc2_file_read.py](https://github.com/user-attachments/files/31388465/poc2_file_read.py)",
"id": "BREW-otterdog-CVE-2026-87817",
"modified": "2026-10-01T09:31:27Z",
"published": "2026-09-20T11:09:09Z",
"references": [
{
"type": "WEB",
"url": "https://github.com/gitpython-developers/GitPython/security/advisories/GHSA-239g-whfq-7xj9"
},
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2026-87817"
},
{
"type": "WEB",
"url": "https://github.com/gitpython-developers/GitPython/pull/2218"
},
{
"type": "WEB",
"url": "https://github.com/gitpython-developers/GitPython/commit/c7cf4d13b1ed0a2e70f2a1f3c6b4fc6c2652cf0b"
},
{
"type": "PACKAGE",
"url": "https://github.com/gitpython-developers/GitPython"
},
{
"type": "WEB",
"url": "https://github.com/gitpython-developers/GitPython/releases/tag/3.1.60"
},
{
"type": "WEB",
"url": "https://github.com/pypa/advisory-database/tree/main/vulns/gitpython/PYSEC-2026-3982.yaml"
},
{
"type": "WEB",
"url": "https://www.vulncheck.com/advisories/gitpython-before-3.1.60-remote-code-execution-via-git-directory-impersonation"
}
],
"schema_version": "1.7.3",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H",
"type": "CVSS_V3"
}
],
"summary": "GitPython: Repository content can impersonate the git directory, leading to arbitrary code execution",
"upstream": [
"PYSEC-2026-3982",
"CVE-2026-87817",
"GHSA-239g-whfq-7xj9"
]
}
Sightings
| Author | Source | Type | Date | Other |
|---|
Nomenclature
- Seen: The vulnerability was mentioned, discussed, or observed by the user.
- Confirmed: The vulnerability has been validated from an analyst's perspective.
- Published Proof of Concept: A public proof of concept is available for this vulnerability.
- Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
- Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
- Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
- Not confirmed: The user expressed doubt about the validity of the vulnerability.
- Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.
The approach is described in our paper Mapping CVEs to MITRE ATT&CK Techniques: A Curated Gold-Set Classifier and the Limits of LLM-Assisted Label Expansion.
Browse all ATT&CK techniques and the vulnerabilities related to each.
Related by attack behaviour
Vulnerabilities whose description is nearest to this one in the vector space of the CIRCL/vulnerability-attack-technique-biencoder model. This is a similarity search over the bi-encoder space (plain cosine), not a classification, and it has no measured accuracy.