/

CVE-2026-87817

Severity:

HIGH RISK

(8.8)

Code Injection (CWE-94) in GitPython Repository Hooks

CVE-2026-87817

Analyzed

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

Impact:

Arbitrary Code Execution

Severity:

HIGH RISK

(8.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

GitPython before 3.1.60 may fail to properly validate a repository's Git-directory location, allowing tracked files to impersonate Git metadata such as gitdir, commondir, and HEAD. If a victim opens or clones a crafted repository and calls index.commit(), a malicious pre-commit hook may execute arbitrary code in the victim's environment.

Affected context

The issue can occur when GitPython processes a cloned or opened repository whose tracked files influence the location or interpretation of Git metadata. Risk is higher when repository contents are obtained from an untrusted source and application code invokes commit operations without independently validating repository structure or hook behavior.

Exploit preconditions

  • Attack surface: GitPython repository opening, cloning, and commit-handling paths
  • Required access: The attacker must be able to supply or influence a repository and its tracked files
  • Trigger point: A victim or service calls index.commit() on the affected repository
  • Why exploitation is possible: Insufficient validation may allow tracked files to impersonate Git-directory metadata and expose a malicious pre-commit hook to the commit workflow

Why this happens

The underlying bug is inadequate validation of the location and identity of the Git directory when repository metadata is resolved. This can cause attacker-controlled tracked files to be treated as trusted Git control data, including hook locations. When a commit operation invokes the resulting hook, attacker-supplied code may run in the process context. This behavior maps to CWE-94, Improper Control of Generation of Code, because untrusted repository content can influence executable hook processing.

Potential impact

  • Arbitrary code could execute with the privileges of the GitPython process
  • Application credentials, tokens, or repository data may be exposed
  • A compromised developer or service environment could be used for lateral movement
  • Build, automation, or source-control workflows may be tampered with

General mitigation guidance

Mitigation generally focuses on reducing trust in repository-provided metadata

and preventing untrusted hooks from executing in automated workflows.

Common defensive patterns include:

  • Use a maintained GitPython release that contains the relevant security correction
  • Treat repositories from untrusted sources as hostile input
  • Validate repository paths and Git-directory relationships independently of tracked files
  • Disable or restrict hook execution for automation and sandbox repository operations where feasible
  • Prefer isolated, least-privileged workers for repository processing
  • Avoid exposing credentials, write access, or sensitive host resources to repository-handling processes
  • Apply allowlists and policy checks before invoking commit operations on externally supplied repositories

How teams detect issues like this

Detection can include:

  • Static analysis and dependency review for repository APIs that resolve Git metadata or invoke hooks
  • Code review checks for commit operations performed on untrusted or insufficiently validated repositories
  • Repository policy enforcement that blocks unexpected gitdir, commondir, HEAD, or hook-related structures
  • Runtime monitoring for child processes launched during repository processing
  • Alerts for unusual process execution, file changes, or network access originating from Git automation workers
  • Automated security review tools that identify unsafe hook execution and untrusted repository handling

Sources

SourceLink
github.comgithub.com/gitpython-developers/GitPython/security/advisories/GHSA-239g-whfq-7xj9
vulncheck.comvulncheck.com/advisories/gitpython-before-3.1.60-remote-code-execution-via-git-directory-impersonation

Frequently asked

questions

It can be exploitable through a repository supplied remotely or obtained from an

untrusted source, but exploitation generally requires a victim application or

user to process that repository and invoke the relevant commit operation.

The attacker typically needs the ability to provide or influence repository

contents. They do not necessarily need access to the victim's local filesystem

before the repository is opened or cloned.

Use a security-corrected dependency, validate repository metadata independently,

and prevent untrusted hooks from running during automated repository operations.

Treat repository contents as untrusted input, isolate Git-processing workloads,

enforce least privilege, monitor unexpected child processes, and apply code

review or policy checks to hook and commit execution paths.

Find out what's already
exploitable in your codebase.