CVE-2026-76217
GitPython < 3.1.58 lets attackers use –pathspec-from-file to read arbitrary files.
- CVSS 7.1
- CWE-73
- Input Validation and Sanitization
- Remote
GitPython versions before 3.1.58 fail to validate options passed to git rm and git checkout commands in IndexFile.remove() and Head.checkout(). Attackers can supply –pathspec-from-file and –pathspec-file-nul parameters to read arbitrary files accessible to the process, with full file contents returned in GitCommandError.stderr.
- CWE
- CWE-73
- CVSS base score
- 7.1
- Published
- 2026-08-19
- OWASP
- A03 Injection
- Orthogonal defect classification
- Checking
- Code defect classification
- Missing Check
- Category
- Input Validation and Sanitization
- Subcategory
- Command Injection
- Accessibility scope
- Remote
- Impact
- Information Disclosure
- Affected component
- GitPython
- Fixed by upgrading
- Yes
Solution
Upgrade GitPython to version 3.1.58 or newer.
Vulnerable code sample
import sys
from git import Repo, GitCommandError
def unsafe_remove(repo_path: str, path: str, opts: dict):
"""
Removes a file from the index using user‑supplied git rm options.
"""
repo = Repo(repo_path)
# VULNERABLE: unchecked options allow injection of --pathspec-from-file etc.
repo.index.remove([path], **opts)Patched code sample
import sys
from git import Repo, GitCommandError
def unsafe_remove(repo_path: str, path: str, opts: dict):
"""
Removes a file from the index using user‑supplied git rm options.
"""
repo = Repo(repo_path)
# FIX: whitelist allowed git‑rm options to prevent injection
allowed = {"r", "f", "cached"} # example safe flags
safe_opts = {k: v for k, v in opts.items() if k in allowed}
repo.index.remove([path], **safe_opts)Published fix
Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.
- Guard pathspec file inputs in high-level commands (gitpython-developers/GitPython)
git/cmd.py,git/index/base.py · IndexFile.remove,git/refs/head.py,git/refs/head.py · Head.checkout,git/refs/head.py · HEAD.reset
Cite this entry
@misc{vaitp:cve202676217,
title = {{GitPython < 3.1.58 lets attackers use --pathspec-from-file to read arbitrary files.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-76217},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-76217/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
