Summary
GitPython versions before 3.1.54 contain an option-validation bypass that can allow crafted Git options to reach sensitive command execution paths. If an attacker can control option dictionaries passed to affected GitPython methods, they may execute arbitrary operating-system commands through the Git upload-pack option.
Affected context
The vulnerability occurs in GitPython integrations that use the affected option-handling logic in versions before 3.1.54. It applies to methods such as clone_from, fetch, pull, push, ls_remote, iter_commits, blame, and archive when attacker-influenced keyword arguments or option dictionaries are accepted and forwarded to Git subprocesses.
Exploit preconditions
- Attack surface: Application code invoking affected GitPython methods
- Required access: Ability to influence Git option dictionaries or single-character keyword argument values
- Trigger point: Git command construction and execution through an affected API method
- Why exploitation is possible: The
check_unsafe_optionsguard can be bypassed, allowing a command-affecting option to reach the underlying Git process
Why this happens
The underlying bug is an incomplete validation of Git options. The guard checks option representations but does not reliably account for options smuggled through single-character keyword argument values, allowing attacker-controlled arguments to bypass the intended safety boundary.
This maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command, because untrusted input can influence arguments interpreted by an operating-system command or subprocess.
Potential impact
- Attackers may execute arbitrary operating-system commands in the application process context
- Application credentials, source code, or repository data could be exposed
- The host or execution environment could be modified
- Compromised processes may be used for lateral movement or supply-chain tampering
General mitigation guidance
Mitigation generally focuses on preventing untrusted data from becoming Git command options and ensuring subprocess boundaries remain tightly controlled.
Common defensive patterns include:
- Use a maintained GitPython release line containing robust option validation
- Allowlist supported Git options instead of forwarding arbitrary dictionaries
- Treat repository URLs, refspecs, and command parameters as untrusted input
- Separate user-controlled values from command construction and validate them against expected schemas
- Run Git operations with least-privilege accounts, restricted filesystem access, and minimal environment credentials
- Prefer fixed argument arrays and disable unnecessary subprocess capabilities where practical
How teams detect issues like this
Organizations can look for this vulnerability through:
- Static analysis rules identifying attacker-controlled dictionaries passed to GitPython command methods
- Code review checks for dynamic option construction, especially single-character keyword names and values
- Inventory searches for affected GitPython versions and uses of the listed methods
- Runtime monitoring of unexpected Git subprocess arguments, repository access, or child-process creation
- Policy enforcement requiring allowlisted Git options and security review for subprocess wrappers
Automated dependency and code-review tools can help identify vulnerable library usage and unsafe argument-flow patterns.

