CVE-2026-76218
Remote code execution via unsafe git options in GitPython Repo.init.
- CVSS 7.7
- CWE-88
- Input Validation and Sanitization
- Remote
GitPython before 3.1.58 contains a remote code execution vulnerability in Repo.init that forwards unsafe git options without validation. Attackers can supply a template parameter pointing to a directory with malicious git hooks that execute arbitrary code when git operations are performed on the initialized repository.
- CWE
- CWE-88
- CVSS base score
- 7.7
- Published
- 2026-08-19
- OWASP
- A03 Injection
- Orthogonal defect classification
- Interface
- Code defect classification
- Missing Check
- Category
- Input Validation and Sanitization
- Subcategory
- Command Injection
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Affected component
- GitPython
- Fixed by upgrading
- Yes
Solution
Upgrade GitPython to version 3.1.58 or newer.
Vulnerable code sample
import os
from git import Repo, GitCommandError
def init_repo(target_path: str, template_path: str) -> Repo:
"""
Initialise a new Git repository at ``target_path`` using the user‑supplied
``template_path``. The template directory may contain malicious Git hooks.
"""
# VULNERABLE: forwards unvalidated template path to Git, enabling command injection via malicious hooks
try:
repo = Repo.init(path=target_path, template=template_path)
except GitCommandError as e:
raise RuntimeError(f"Git init failed: {e}")
return repoPatched code sample
import os
from git import Repo, GitCommandError
def init_repo(target_path: str, template_path: str) -> Repo:
"""
Initialise a new Git repository at ``target_path`` using a validated
``template_path``. Only directories without executable hooks are allowed.
"""
# FIX: validate template path to prevent malicious hooks from being executed
if not os.path.isdir(template_path):
raise ValueError("Template path must be an existing directory")
# Disallow any file named 'post-commit' (common hook) in the template
for root, _, files in os.walk(template_path):
if any(f.startswith('post-') or f.startswith('pre-') for f in files):
raise ValueError("Template contains Git hooks, which are prohibited")
try:
repo = Repo.init(path=target_path, template=template_path)
except GitCommandError as e:
raise RuntimeError(f"Git init failed: {e}")
return repoPublished 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 unsafe git init options (gitpython-developers/GitPython)
git/repo/base.py,git/repo/base.py · Repo.init
Cite this entry
@misc{vaitp:cve202676218,
title = {{Remote code execution via unsafe git options in GitPython Repo.init.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-76218},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-76218/}}
}
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 ::
