Summary
GitPython before version 3.1.59 does not disable merge_includes while parsing .gitmodules files, allowing attacker-controlled include directives to reference arbitrary local paths. When submodule configuration is accessed, the resulting parsing error may disclose the first line of a targeted file through its exception message.
Affected context
The issue occurs in applications that use GitPython to inspect repositories containing attacker-controlled .gitmodules files. Risk is higher when a repository is cloned, imported, or otherwise processed from an untrusted source and the application accesses repo.submodules, allowing included paths to be interpreted before the configuration is safely constrained.
Exploit preconditions
- Attack surface: GitPython repository and submodule configuration parsing
- Required access: Ability to provide or modify a repository containing a malicious
.gitmodulesfile - Trigger point: Access to the repository's submodule collection or equivalent configuration parsing path
- Why exploitation is possible: Include directives are honored without adequately restricting referenced paths, and parser errors may incorporate content read from the targeted file
Why this happens
The vulnerability results from treating attacker-controlled .gitmodules include directives as trusted configuration. Because merge includes remain enabled during parsing, an external file path can influence which local file is read. If parsing then fails, the exception message may contain data from that file, mapping to CWE-73: External Control of File Name or Path and an information disclosure condition.
Potential impact
- Sensitive local file content may be disclosed
- Credentials, tokens, or configuration data could be exposed
- Error logs or API responses may unintentionally propagate disclosed data
- Applications processing untrusted repositories could suffer cross-tenant information leakage
General mitigation guidance
Mitigation generally focuses on preventing untrusted repository configuration from controlling local file access.
Common defensive patterns include:
- Disable or reject include processing when parsing
.gitmodulesfrom untrusted repositories - Use an allowlist of permitted configuration sources and repository-relative paths
- Resolve and validate paths before opening files, while preventing traversal outside approved directories
- Avoid returning raw parser exceptions to untrusted users
- Minimize process privileges and filesystem access for repository-processing services
- Treat cloned or uploaded repository metadata as untrusted input by default
How teams detect issues like this
Organizations can detect this class of issue through:
- Static analysis checks for configuration parsers that enable external includes
- Code review searches for unrestricted path construction and file access driven by repository metadata
- Tests using malicious
.gitmodulesfiles with external include targets and assertions that no local content appears in errors - Runtime monitoring for unexpected reads outside repository workspaces
- Policy enforcement that blocks repository-processing components from accessing sensitive filesystem locations
- Automated security review tools that flag externally controlled file paths and unsafe configuration handling

