Aug 7, 2026·8 min read·52 visits
GitPython prior to 3.1.58 allows arbitrary command execution when executing git commands with split_single_char_options=False due to validation desynchronization.
An unsafe option guard bypass vulnerability exists in GitPython before version 3.1.58. When keyword arguments are passed to Git commands with split_single_char_options=False, GitPython's argument validation helper fails to inspect the combined short-option value. This discrepancy allows short-option token smuggling or clustering manipulation, enabling remote attackers to bypass option blocklists and execute arbitrary system commands.
GitPython is an open-source Python library designed to provide a native programmatic interface for interacting with Git repositories. Applications rely on this package to automate complex git operations such as cloning remote repositories, checking out branches, and managing revision histories. The library acts as a high-level wrapper, serializing Python functions and keyword arguments into command-line parameters that are eventually passed to the system's local Git binary via the standard subprocess module.
Because GitPython interacts directly with a shell-executable binary, any application that passes untrusted user input directly to GitPython commands exposes a severe attack surface. To mitigate the risk of parameter injection, GitPython implements an internal security validation layer. This layer checks options against a list of dangerous parameters (such as --upload-pack or -u) that could allow external command execution. If any blocked options are detected, the system raises an exception and halts execution.
This security advisory focuses on a technical flaw in this safety validation logic designated as GHSA-WVPP-8HX9-P66J. The vulnerability is classified under CWE-88 (Improper Neutralization of Argument Delimiters in a Command) and manifests when keyword arguments are formatted with the option split_single_char_options=False. In this configuration, GitPython fails to evaluate combined short-option flags properly, introducing a logic gap that enables unauthenticated remote code execution via short-option smuggling.
When exploitation is successful, an attacker can bypass all internal safety blacklists and force the host operating system to execute arbitrary binaries or scripts. The flaw does not require authentication and can be triggered remotely if an application exposes Git wrappers (such as cloning configurations) to external web inputs. The vulnerability affects all versions of GitPython prior to version 3.1.58.
The underlying root cause of GHSA-WVPP-8HX9-P66J lies in a logical desynchronization between two key internal functions inside GitPython's execution wrapper: transform_kwargs and _option_candidates. The transform_kwargs function is responsible for converting Python keyword arguments into actual string arguments for command-line serialization. Conversely, the _option_candidates function extracts and normalizes these parameters for safety analysis, ensuring they do not match restricted elements in check_unsafe_options.
When developers supply single-character keyword arguments (such as n="value"), the split_single_char_options boolean flag controls how the parameters are serialized. If set to True, the library splits them into discrete arguments: the flag and its parameter (e.g., ["-n", "value"]). If configured to False, the serializer merges them into a single string (e.g., ["-nvalue"]). The core vulnerability is triggered when split_single_char_options=False because _option_candidates and transform_kwargs handle the merged token unsafely.
During argument parsing, _option_candidates extracted only the primary single-character key (e.g., -n) and completely discarded the attached value (e.g., uhelper). Consequently, the safety engine evaluated only the safe -n option, allowing the command to proceed. However, when transform_kwargs subsequently generated the final command string, it created the merged option -nuhelper.
When the resulting argument list is passed to the underlying git binary, the executable parses the combined string according to POSIX short-option clustering rules. Git interprets the string character by character: -n is treated as a safe option, the subsequent u is treated as a nested short option (equivalent to -u or --upload-pack), and the remaining helper string is bound as the argument for -u. By smuggling the unsafe -u option within a benign single-character key, attackers successfully bypass the blocklist.
To understand the exact mechanics of the desynchronization, we analyze the vulnerable implementation of _option_candidates in git/cmd.py alongside the corrective patch implemented in version 3.1.58. The fix was committed under hash 96a888f4d782cb2f80452148e48e60ce4af6d541.
In the vulnerable implementation, the logic for handling keyword arguments inside _option_candidates was as follows:
# Vulnerable logic inside git/cmd.py
key = str(key)
options.append(f"-{key}" if len(key) == 1 else f"--{dashify(key)}")
if len(key) == 1 and split_single_char_options:
options.extend(
str(value)
for value in values
if value is not True and value not in (False, None) and str(value).startswith("-")
)Notice that if split_single_char_options was False, the if condition was skipped entirely. The generator appended only the base flag (-{key}) to the candidate list and ignored value completely. Because the validation engine lacked visibility into the concatenated string, check_unsafe_options remained unaware of the nested command parameters.
To resolve this desynchronization, the developers restructured the conditional branches to handle the split_single_char_options=False scenario explicitly. The patch modified git/cmd.py as follows:
# Patched implementation in git/cmd.py (GitPython >= 3.1.58)
key = str(key)
if len(key) != 1:
options.append(f"--{dashify(key)}")
elif split_single_char_options:
options.append(f"-{key}")
options.extend(
str(value)
for value in values
if value is not True and value not in (False, None) and str(value).startswith("-")
)
else:
# Correctly reconstruct the merged short option for validation
options.extend(
f"-{key}" if value is True else f"-{key}{value}"
for value in values
if value is True or (value is not False and value is not None)
)This new branch ensures that when split_single_char_options=False, the exact string generated for subprocess execution (-{key}{value}) is also appended to the options candidate list. Consequently, passing n="uhelper" now produces the validation candidate -nuhelper. Since the validation engine matches candidates using substring checks, this correctly triggers a blocklist exception on the smuggled u parameter.
The implemented fix is robust for the evaluated single-character path. However, security researchers should note that long option keys (e.g., len(key) != 1) still only append --{dashify(key)} to candidates and do not inspect the associated value parameter in _option_candidates. While Git's parsing of long options is less susceptible to POSIX short-option clustering, developers must ensure that no custom command wrappers treat long-option values as secondary arguments.
Exploiting this vulnerability requires specific environment conditions. First, the target application must utilize GitPython to interact with Git repositories. Second, the application must expose an execution interface where external input directly controls keyword arguments. Third, either the application or the developer's custom configuration must specify split_single_char_options=False during command execution.
Consider a vulnerable Python web application that allows users to clone repositories and configure specific Git flags through a query parameter. The following proof-of-concept script demonstrates how an attacker can leverage this configuration to execute arbitrary system binaries:
# Vulnerable Application Context (GitPython < 3.1.58)
from git import Git
from git.exc import UnsafeOptionError
git_client = Git()
# Malicious payload designed to execute an external helper binary
# under the guise of an 'n' (no-checkout) flag value.
user_supplied_option = "utouch /tmp/pwned;git-upload-pack"
try:
# The application processes arguments with split_single_char_options disabled
git_client.clone(
"https://github.com/example/repo.git",
n=user_supplied_option,
split_single_char_options=False
)
except Exception as e:
print(f"Execution resulted in: {e}")When this script runs, the internal workflow triggers as follows:
This exploitation flow demonstrates how minor desynchronizations in argument tokenization lead directly to complete command-injection pathways, bypassing all intended blacklist validation layers.
The security impact of GHSA-WVPP-8HX9-P66J is critical, carrying an estimated CVSS v3.1 score of 9.8. Because GitPython is widely used in continuous integration and continuous deployment (CI/CD) pipelines, automated build platforms, and developer tooling, an argument injection vulnerability of this nature poses severe risks. An attacker who successfully exploits this flaw achieves unauthenticated remote code execution (RCE) within the context of the running application process.
Depending on the privileges of the host process, RCE can lead to full system compromise, lateral movement within internal networks, and unauthorized access to intellectual property such as source code repositories. In containerized environments, attackers may exploit this vector to escape containers or access cloud metadata services to harvest sensitive credentials.
To mitigate this vulnerability, system administrators and developers must take immediate action. The primary remediation strategy is upgrading the GitPython package to version 3.1.58 or higher, which incorporates the corrected _option_candidates validation logic. Upgrading can be performed via the standard Python package manager:
pip install --upgrade GitPython>=3.1.58If immediate upgrading is not feasible, developers should implement defensive programming workarounds. Avoid disabling split_single_char_options when processing untrusted inputs. Additionally, implement robust input validation filters to reject any keyword values that begin with letters matching dangerous short-options (such as u or c), or strictly sanitize input against alphanumeric character sets. Organizations can also deploy Semgrep static analysis rules within their development pipelines to flag any vulnerable occurrences of split_single_char_options=False in their source code repositories.
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H| Product | Affected Versions | Fixed Version |
|---|---|---|
GitPython gitpython-developers | < 3.1.58 | 3.1.58 |
| Attribute | Detail |
|---|---|
| CWE ID | CWE-88 |
| Attack Vector | Network |
| CVSS v3.1 | 9.8 (Critical) |
| EPSS Score | N/A |
| Impact | Remote Command Execution (RCE) |
| Exploit Status | Proof of Concept (PoC) |
| CISA KEV Status | Not Listed |
The product constructs a command-line string or command array using input from an upstream source, but it does not neutralize or incorrectly neutralizes argument delimiters, allowing an attacker to supply additional command-line arguments.
CVE-2026-28385 (GHSA-3gq2-x4qg-p4g6) is a Server-Side Request Forgery (SSRF) vulnerability in Canonical LXD versions 4.12 through 6.9. An authenticated user possessing the can_create_images entitlement can force the LXD daemon to execute arbitrary outbound HTTP and HTTPS requests via the /1.0/images API endpoint. Due to the absence of egress destination validation, an attacker can probe host loopback services, RFC 1918 private network segments, and cloud Instance Metadata Services (IMDS) from the network position of the privileged LXD daemon.
Canonical LXD and LXC Incus contain an arbitrary file write vulnerability (CWE-73 / CWE-59) in the `/1.0/instances/<name>/exec` REST API endpoint. When an instance is unpacked from an image archive, top-level symbolic links are extracted directly onto the host filesystem within the instance storage directory. If a crafted image includes a symbolic link named `exec-output` pointing to an arbitrary host path, invoking the execution endpoint with `record-output: true` causes the privileged host daemon to follow the symlink and write command output files directly to the target host directory. An authenticated attacker with permissions to import images and execute commands can exploit this flaw to write controlled content to sensitive host directories such as `/etc/cron.d`, resulting in arbitrary code execution on the host as `root`.
CVE-2026-48749 (tracked as GHSA-vghh-5rfx-xhq8 for LXD and GHSA-2q3f-q5pq-g8wv for Incus) is a critical container escape vulnerability in the Canonical LXD and Linux Containers Incus system container managers. By importing a specially crafted container image archive containing duplicate tar member headers, an authenticated attacker can replace the instance rootfs directory with a symbolic link pointing to the underlying host root filesystem. When performing file operations on a stopped container, the privileged forkfile helper binary resolves the symbolic link without confinement and chroots directly into the host filesystem, granting arbitrary root-level file read and write access.
GHSA-fmc8-p6q7-75cc (associated with CVE-2026-48755) is a critical argument injection vulnerability in Canonical LXD (github.com/canonical/lxd). The vulnerability occurs during instance and storage volume backup operations when processing the user-supplied compression_algorithm configuration parameter. While LXD validates the primary executable token against an allowlist of supported compression binaries, it fails to sanitize or restrict subsequent tokens parsed via shellquote.Split. These additional arguments are passed directly to exec.Command. An authenticated attacker with privileges to trigger backups can inject command-line flags for utilities like zstd to read staged files from a container filesystem and write them to arbitrary paths on the underlying host filesystem, such as /etc/cron.d/, achieving root-level arbitrary code execution on the host.
A critical path traversal vulnerability caused by improper input validation (CWE-20) exists in the direct image download handler of Canonical LXD and Linux Containers Incus. When an authenticated user requests an image import using the URL source type, the daemon reads the image fingerprint from an untrusted HTTP response header (`Incus-Image-Hash` or `LXD-Image-Hash`) without validating that it conforms to a SHA-256 format. This unvalidated string is concatenated directly into a filesystem path via `filepath.Join` prior to file creation and cryptographic verification, allowing directory traversal sequences to write arbitrary files on the host filesystem as root.
CVE-2026-9639 (GHSA-j93m-3j9p-m5m8) is a null pointer dereference vulnerability in Canonical LXD affecting versions 5.0.0 through 5.21.4 and 6.0 through 6.8. The flaw resides in the (*lxdBackend).CreateCustomVolumeFromBackup method within lxd/storage/backend_lxd.go. An authenticated attacker with the can_create_storage_volumes permission can upload a crafted custom volume backup tarball that omits the expires_at field on a snapshot entry, triggering an unhandled SIGSEGV panic and terminating the LXD daemon.