VAITP Dataset

← Back to the dataset

CVE-2026-76222

GitPython 3.1.58+ allows .gitmodules submodule name path traversal, creating repos outside target directory.

  • CVSS 8.4
  • CWE-22
  • Input Validation and Sanitization
  • Remote

GitPython before 3.1.58 fails to validate submodule names from .gitmodules files, allowing attackers to create Git repositories at arbitrary filesystem paths outside the intended clone directory. Attackers can craft malicious repositories with traversal sequences in submodule names that GitPython processes during submodule initialization, creating attacker-controlled Git repositories at escaped filesystem locations.

CVSS base score
8.4
Published
2026-08-19
OWASP
A01 Broken Access Control
Orthogonal defect classification
Checking
Code defect classification
Missing Check
Category
Input Validation and Sanitization
Subcategory
Path Traversal
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
GitPython
Fixed by upgrading
Yes

Solution

Upgrade GitPython to version 3.1.58 or later.

Vulnerable code sample

import os
from git import Repo

def init_submodules(repo_path: str, work_dir: str) -> None:
    """
    Clone a repository and initialize its submodules.
    Vulnerable to path traversal via malicious submodule names.
    """
    repo = Repo.clone_from(repo_path, work_dir)
    for submodule in repo.submodules:
        # VULNERABLE: uses submodule.path directly, allowing ".." traversal
        sub_path = os.path.join(work_dir, submodule.path)
        os.makedirs(sub_path, exist_ok=True)
        submodule.update(init=True, to_revision='HEAD')

Patched code sample

import os
from git import Repo

def init_submodules(repo_path: str, work_dir: str) -> None:
    """
    Clone a repository and initialize its submodules.
    Sanitizes submodule paths to prevent directory traversal.
    """
    repo = Repo.clone_from(repo_path, work_dir)
    work_dir_abs = os.path.abspath(work_dir)
    for submodule in repo.submodules:
        # FIX: normalize and verify submodule path stays within work_dir
        sub_path = os.path.abspath(os.path.join(work_dir, submodule.path))
        if not sub_path.startswith(work_dir_abs + os.sep):
            raise ValueError(f"Unsafe submodule path: {submodule.path}")
        os.makedirs(sub_path, exist_ok=True)
        submodule.update(init=True, to_revision='HEAD')

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.

  • Validate submodule names on every module path branch (gitpython-developers/GitPython)
    git/objects/submodule/base.py · Submodule._module_abspath
  • Validate submodule names before filesystem operations (gitpython-developers/GitPython)
    git/objects/submodule/base.py, git/objects/submodule/base.py · Submodule.add, git/objects/submodule/base.py · Submodule.module, git/objects/submodule/base.py · Submodule.move, git/objects/submodule/base.py · Submodule.remove, git/objects/submodule/base.py · Submodule.rename, git/objects/submodule/base.py · Submodule.update, git/objects/submodule/base.py · Submodule._module_abspath

Cite this entry

@misc{vaitp:cve202676222,
  title        = {{GitPython 3.1.58+ allows .gitmodules submodule name path traversal, creating repos outside target directory.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-76222},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-76222/}}
}

Download this entry as JSON Download the whole dataset

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 ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.