Summary
GitPython before 3.1.58 contains a config-name injection flaw in its option-name validation logic. If an attacker can influence an option name, they may inject Git configuration directives that cause command execution or alter Git behavior during a later repository operation.
Affected context
The vulnerability occurs in applications that use GitPython to construct or validate Git configuration option names from attacker-influenced input. The risk is highest when those names are written into Git configuration and a later Git operation honors settings such as core.sshCommand or core.hooksPath.
Exploit preconditions
- Attack surface: Application code that passes externally influenced values into GitPython configuration option-name handling
- Required access: Ability to influence or supply an option name, directly or through an application-controlled configuration workflow
- Trigger point: A subsequent Git operation that reads and applies the forged configuration directive
- Why exploitation is possible: Inadequate validation permits special characters, including equals signs, hash symbols, and whitespace, to change the structure and meaning of a configuration entry
Why this happens
The underlying bug is insufficient neutralization and validation of configuration option names. Characters that should remain data can instead introduce separators, comments, or additional configuration syntax, allowing an attacker-controlled name to become a forged Git directive. This behavior maps to CWE-74, Injection, because untrusted input is incorporated into a command or configuration language without enforcing a strict data-only representation.
Potential impact
- Arbitrary commands may execute in the context of a later Git operation.
- Repository contents or generated artifacts could be modified.
- SSH behavior or hook execution could be redirected.
- Credentials, tokens, or other process-accessible data could be exposed.
- Build, deployment, or source-control workflows could be disrupted or compromised.
General mitigation guidance
Mitigation generally focuses on treating configuration option names as a strict
allowlisted data type rather than as free-form strings.
Common defensive patterns include:
- Rejecting option names containing configuration syntax, separators, comments, or whitespace unless explicitly required.
- Using structured configuration APIs that separate option names from values and do not concatenate raw input.
- Allowing only a narrow set of expected option names and values.
- Preventing untrusted users from controlling Git configuration or repository hook paths.
- Running Git operations with least privilege, restricted filesystem access, and minimal environment secrets.
- Isolating repository-processing jobs and disabling unnecessary hooks or command overrides by policy.
How teams detect issues like this
Organizations can look for this issue through:
- Static analysis rules identifying dynamically constructed Git configuration names.
- Code review checks for string concatenation involving option names, equals signs, comments, or whitespace.
- Tests that submit malformed and delimiter-containing names and verify strict rejection.
- Runtime monitoring for unexpected core.sshCommand, core.hooksPath, or other command-related Git settings.
- Policy enforcement that restricts repository hooks, SSH command overrides, and configuration writes in automated jobs.
- Automated security review tools that flag injection-prone configuration APIs and missing allowlists.

