# CVE-2026-87817: GitPython git directory impersonation leading to code execution

Source: https://junglewise.ai/threats/cve-2026-87817-gitpython-git-directory-impersonation-leading-to-code-execution  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2026-09-09. Updated: 2026-09-26  
License: CC BY 4.0 with a link back

CVE-2026-87817 · Severity: high · CVSS 8.8 · Published 2026-09-09

GitPython is a Python library used to interact with Git repositories. An attacker can create a malicious repository with specially crafted files that trick GitPython into treating the repository's working directory as the Git control directory. When a developer or automated service clones or opens this repository and performs a commit operation, the attacker's code executes with the same privileges as the GitPython user, potentially compromising the entire system or exposing sensitive credentials.

Technologies: [Gitpython Project Gitpython](https://junglewise.ai/threats/technologies/gitpython), [gitpython (PyPI)](https://junglewise.ai/threats/technologies/pypi-gitpython). Vendors: [Gitpython Project](https://junglewise.ai/threats/vendors/gitpython-project), [PyPI](https://junglewise.ai/threats/vendors/pypi).

## Quick answers

**Is CVE-2026-87817 exploited in the wild?** No. Junglewise Threat Intelligence has no report of CVE-2026-87817 being exploited in the wild.

**How severe is CVE-2026-87817?** High severity, with a CVSS score of 8.8, published 9 September 2026.

**Which products and versions are affected?** gitpython (PyPI) <= 3.1.59, ECOSYSTEM:introduced=0,fixed=3.1.60.

**Is there a fix for CVE-2026-87817?** Yes. gitpython (PyPI): upgrade to 3.1.60 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**How is CVE-2026-87817 attacked?** It is attacked over the network, in a software library.

**Am I affected by CVE-2026-87817?** Check whether you run Gitpython Project Gitpython or gitpython (PyPI) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

## How to fix

- gitpython (PyPI): upgrade to 3.1.60 or later

  ```sh
  pip install "gitpython>=3.1.60"
  ```


## Technical details

GitPython's Repo.__init__ method determines the git directory by testing candidate paths in an order that prioritizes tracked files (gitdir, commondir, HEAD) before testing the actual .git directory. An attacker can create a repository with ordinary tracked files at the root directory that satisfy these checks, causing GitPython to resolve git_dir to the working tree instead of the real .git directory. This allows the attacker to place a malicious pre-commit hook in a tracked hooks/ directory that executes when index.commit() is called. The vulnerability also enables arbitrary file reads via the tracked config file (with merge_includes enabled) and arbitrary file writes through an attacker-controlled commondir path. The attack is "silent"—git clone exits successfully, git fsck reports nothing, and standard repository checks pass. GitPython versions before 3.1.60 are affected; the fix involves validating .git before other candidates, validating hook paths through common_dir, and disabling merge_includes in config parsing.

## Affected products

- GitPython Developers GitPython before 3.1.60

## Identifiers

- CVE-2026-87817
- GHSA-239g-whfq-7xj9
- PYSEC-2026-3982

## Timeline

- 2026-08-26: disclosed: GitHub Security Advisory (GHSA-239g-whfq-7xj9) published
- 2026-09-09: advisory: CVE-2026-87817 published

## References

- [https://github.com/gitpython-developers/GitPython/security/advisories/GHSA-239g-whfq-7xj9](https://github.com/gitpython-developers/GitPython/security/advisories/GHSA-239g-whfq-7xj9)
- [https://www.vulncheck.com/advisories/gitpython-before-3.1.60-remote-code-execution-via-git-directory-impersonation](https://www.vulncheck.com/advisories/gitpython-before-3.1.60-remote-code-execution-via-git-directory-impersonation)

## Related threats

- [GitPython command wrappers omit unsafe protocol and option checks](https://junglewise.ai/threats/cve-2026-110857-gitpython-command-wrappers-omit-unsafe-protocol-and-option)
- [GitPython submodule path traversal to arbitrary hook execution](https://junglewise.ai/threats/cve-2026-114145-gitpython-is-a-python-library-used-to-interact-with-git)
- [GitPython symlink following in Submodule.move()](https://junglewise.ai/threats/cve-2026-110860-gitpython-from-3-1-62-before-3-2-0-contains-a-symlink-following)
- [GitPython argument injection in Head.checkout()](https://junglewise.ai/threats/cve-2026-110859-gitpython-before-3-2-0-contains-an-argument-injection)
- [GitPython remote code execution in Remote.pull() refspec argument](https://junglewise.ai/threats/cve-2026-110858-gitpython-from-3-1-30-before-3-2-0-contains-a-remote-code)
