/

CVE-2026-42215

Severity:

HIGH RISK

(8.8)

Command Injection in GitPython Push APIs

CVE-2026-42215

Analyzed

Vulnerability type

Category:

Command Injection

CWE:

CWE-78

Impact:

Remote 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 versions 3.1.30 through 3.1.46 contain a command injection vulnerability where certain Git transport options are blocked in the CLI flags, but their Python keyword argument equivalents are not.

If an application forwards attacker-controlled keyword arguments like upload_pack or receive_pack into GitPython's clone or remote APIs, an attacker can trigger arbitrary command execution even when unsafe options are ostensibly disabled.

Affected context

This vulnerability appears in Python applications that embed GitPython and:

  • Use Repo.clone_from(), Remote.fetch(), Remote.pull(), or Remote.push()
  • Accept or propagate user-controlled or otherwise untrusted data into GitPython keyword arguments
  • Rely on GitPython's allow_unsafe_options=False default to block dangerous Git options

The risk is most pronounced in services like source code management frontends, CI/CD orchestrators, or web APIs that perform Git operations on behalf of remote users.

Exploit preconditions

  • Attack surface: Any code path that calls:
  • git.Repo.clone_from(...)
  • remote.fetch(...)
  • remote.pull(...)
  • remote.push(...)

with keyword arguments that influence Git transport options.

  • Required access: Ability to control or significantly influence function kwargs such as upload_pack or receive_pack (directly via an API parameter, indirectly via configuration, job specs, or serialized tasks).
  • Trigger point: Invocation of Git operations where dangerous options are passed via kwargs rather than the corresponding CLI flags, causing Git to execute attacker-supplied commands.
  • Why exploitation is possible: The library's safeguard that blocks dangerous Git options examines CLI-style arguments but does not equivalently enforce restrictions on the parallel Python keyword params (upload_pack, receive_pack). This mismatch leaves a command execution vector open even when allow_unsafe_options is set to its safe default.

Why this happens

The underlying bug belongs to CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').

GitPython attempts to limit exposure to dangerous Git transport options by filtering certain command-line flags (e.g., --upload-pack, --receive-pack) when allow_unsafe_options is False. However, the API exposes Python keyword arguments (upload_pack, receive_pack) that semantically map to the same Git capabilities but are not subjected to the same safety checks. When untrusted data reaches these kwargs, it can be incorporated into the underlying Git command line without proper neutralization or validation. This design gap between option filtering and the higher-level API leaves a command injection channel that bypasses the intended security control.

Potential impact

  • Execution of arbitrary OS commands with the privileges of the application process.
  • Compromise of the host running the vulnerable service or CI/CD pipeline.
  • Unauthorized access, modification, or exfiltration of source code repositories.
  • Lateral movement within build or deployment infrastructure using the compromised process.
  • Tampering with build artifacts, leading to supply-chain compromise for downstream consumers.

General mitigation guidance

Effective mitigation centers on not trusting caller-provided Git options and ensuring invariant-safe Git operations:

  • Avoid passing user-controlled or loosely validated values into GitPython keyword arguments that influence Git transport or helper binaries, especially upload_pack and receive_pack.
  • Introduce strict allowlists for permitted Git options, transports, and remote URLs; reject or ignore anything outside a well-defined, minimal set.
  • Encapsulate Git operations behind a narrow internal API that only accepts high-level parameters (e.g., repository URL, branch, reference) and never raw Git options or arbitrary kwargs.
  • Drop privileges and isolate Git operations using least-privilege OS accounts, reduced filesystem access, and, where feasible, container or sandbox boundaries to constrain the blast radius of command execution.
  • Treat any configuration, job specification, or pipeline definition that can influence Git options as untrusted input and validate it accordingly.

Architectural patterns that keep Git invocation logic centralized and declarative generally reduce the opportunity for option-level injections.

How teams detect issues like this

Detection typically involves code-centric and process-centric approaches:

  • Static analysis and code search:
  • Scan for calls to Repo.clone_from, Remote.fetch, Remote.pull, and Remote.push that pass dynamic keyword arguments, particularly upload_pack and receive_pack.
  • Flag patterns where kwargs are built from HTTP request data, environment variables, YAML/JSON configs, or job descriptors without sanitization or allowlisting.
  • Code review signals:
  • Question any use of GitPython kwargs that manipulate transport helpers, custom binaries, or arbitrary Git command-line fragments.
  • Investigate utility wrappers that accept **kwargs and forward them directly into GitPython APIs.
  • Policy and tooling:
  • Enforce secure coding guidelines that prohibit passing untrusted data into Git options across the codebase.
  • Use automated review tools or linters that can identify dangerous GitPython usage patterns and surface them during CI.
  • Runtime monitoring (defense in depth):
  • Monitor for unusual Git sub-process invocations or unexpected binaries launched under Git-related service accounts.
  • Apply command-logging and anomaly detection on Git service hosts to catch suspicious option usage indicative of injection attempts.

Sources

SourceLink
github.comgithub.com/gitpython-developers/GitPython/releases/tag/3.1.47
github.comgithub.com/gitpython-developers/GitPython/security/advisories/GHSA-rpm5-65cw-6hj4

Frequently asked

questions

It can be, depending on how GitPython is integrated. If a web service, CI system, or API forwards user input into GitPython kwargs controlling Git options, a remote attacker may exploit this path to achieve command execution. In purely local, non-interactive scripts without untrusted input, the practical risk is lower.

An attacker must be able to influence the parameters passed to GitPython's Git operations, particularly keyword arguments such as upload_pack and receive_pack. This influence might come from HTTP request parameters, configuration files, pipeline specifications, or other external inputs that the application uses to drive Git operations.

The safest pattern is to avoid exposing GitPython's low-level option kwargs to untrusted sources altogether. Wrap Git operations in a higher-level, internal API that only accepts sanitized, strongly-typed parameters (e.g., repository URL and branch) and internally uses secure defaults without forwarding arbitrary kwargs.

Prevention hinges on combining secure API design with input-governance practices:

  • Design wrapper interfaces that do not mirror every underlying library option, especially those that influence command execution.
  • Apply strict input validation and allowlists for any configuration that affects external command invocation.
  • Include library-usage rules in security reviews, ensuring that safety flags and filters actually cover all equivalent code paths.
  • Integrate automated checks that flag risky uses of subprocess-like libraries or wrappers, including GitPython, before code is merged.
Find out what's already
exploitable in your codebase.