CVE-2026-76219: GitPython before 3.1.58 Arbitrary File Overwrite via read-tree
Summary IndexFile.fromtree, IndexFile.reset (→ fromtree) and IndexFile.mergetree append caller-influenced treeish strings positionally to git read-tree with no unsafe-option guard, no allowunsafeoptions parameter, and no -- separator. git read-tree --index-output=<file> writes the resulting index to an arbitrary path, and last-occurrence-wins lets an injected --index-output override the method's internal temp path — clobbering an arbitrary file with a valid git-index blob. This is a distinct, never-guarded sink: commit 3af0c251 (GHSA-3f7w-8rr8-f37f) guarded only checkoutindex and tag; readtree was left unprotected (it is among the acknowledged unguarded call sites in that advisory's sweep but was never reported or fixed).
Root Cause fromtree (index/base.py:388), reset (delegates to fromtree), and mergetree (index/base.py:291) call repo.git.readtree(arglist) with no checkunsafeoptions and no --. The treeish is caller-influenced and positional.
Impact Arbitrary file overwrite / destruction at the privileges of the host process. Content is constrained to a git-index blob (not attacker-chosen, so not RCE), but the target path is fully attacker-controlled — corrupting/truncating configs or destroying files at attacker-chosen writable locations = I:H + A:H (per the skill's "overwrite-any-path = I:H" rule). Pure VALUE control (positional treeish). Default configuration.
Proof of Concept python IndexFile.fromtree(repo, "--index-output=/home/victim/.bashrc") target overwritten with a valid git-index blob (DIRC...)
Attack Chain 1. Entry: app calls IndexFile.fromtree(repo, treeish) / reset(commit=…) / mergetree(base=…, rhs=…) with attacker treeish="--index-output=/home/victim/.bashrc". 2. Check: NONE — the methods have no allowunsafeoptions and never call checkunsafeoptions. 3. Sink: repo.git.readtree(arglist) — no --. argv (fromtree, observed): ['git','read-tree','--index-output=<tmp>','--index-output=/…/victim'] (last-wins). 4. Impact: target path created/overwritten with a valid git-index blob; existing content destroyed.
Bypass Evidence Independently reproduced (gate harness): IndexFile.fromtree(repo,'--index-output=<victim>') → victim overwritten; before=IMPORTANT ORIGINAL CONTENT, after starts DIRC\x00\x00\x00\x02… (destructive clobber, valid index blob). reset(commit=…) and both mergetree positionals verified. Fix-commit read: 3af0c251 touched only checkoutindex+tag; readtree untouched on HEAD.
Affected Versions GitPython <= 3.1.57 (sinks present verbatim on the latest release tag).
Suggested Fix Add a checkunsafeoptions guard (with an allowunsafeoptions parameter) to fromtree/reset/mergetree, and/or place a -- separator before the positional treeish arguments; block --index-output (a path-taking option) on this sink.
Other sources
GitPython versions before 3.1.58 contain an arbitrary file overwrite vulnerability in IndexFile.fromtree, IndexFile.reset, and IndexFile.mergetree methods that append caller-influenced treeish strings to git read-tree without option validation or argument separation. Attackers can inject the --index-output option to overwrite arbitrary files with a valid git-index blob, destroying existing file content at attacker-controlled writable paths.
— NVD
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
debian/python-gitto a version that resolves this vulnerability.Fixed in 3.1.30-1+deb12u3 - Upgrade
Upgrade
debian/python-gitto a version that resolves this vulnerability.Fixed in 3.1.44-1+deb13u1 - Upgrade
Upgrade
debian/python-gitto a version that resolves this vulnerability.Fixed in 3.1.61-1 - Upgrade
Upgrade
alpine/py3-gitpythonto a version that resolves this vulnerability.Fixed in 3.1.61-r0 - Upgrade
Upgrade
pip/GitPythonto a version that resolves this vulnerability.Fixed in 3.1.58 - Upgrade
Upgrade
debian/python-gitto a version that resolves this vulnerability.Fixed in 3.1.30-1+deb12u3Fixed in 3.1.44-1+deb13u1Fixed in 3.1.61-1 - Upgrade
Upgrade to a fixed release to a version that resolves this vulnerability.
Fixed in 3.1.58
Event History
Frequently Asked Questions
Who is exposed to this issue?
Applications using GitPython versions before 3.1.58 are exposed if they call IndexFile.from_tree, IndexFile.reset, or IndexFile.merge_tree with treeish strings influenced by a lower-privileged attacker.
What does an attacker need to exploit it?
The attacker needs the ability to influence a treeish string passed to one of the affected methods. They can inject the --index-output option and target a path that is writable in the context of the affected application.
What is the impact of successful exploitation?
Successful exploitation can overwrite an arbitrary writable file with a valid Git index blob. This destroys the existing contents of the targeted file and can affect integrity and availability.