Summary
GitPython versions before 3.1.59 do not adequately restrict the --separate-git-dir clone option, allowing repository metadata to be placed outside the intended clone directory. If an attacker can control the separate_git_dir parameter and influence a process that performs a clone, they may create directories in unintended filesystem locations and potentially enable Git hook execution.
Affected context
The vulnerability occurs in applications that use GitPython's Repo.clone_from() or Repo.clone() APIs and expose, derive, or otherwise trust the separate_git_dir parameter. It is most relevant when the cloning process has filesystem permissions that reach locations outside the expected repository workspace and when subsequent Git operations can process metadata or hooks from the redirected directory.
Exploit preconditions
- Attack surface: Application code that invokes GitPython repository-cloning APIs
- Required access: Ability to influence the
separate_git_dirvalue or an equivalent clone configuration - Trigger point: Repository cloning with the separate Git directory option
- Filesystem condition: The running process must have permission to create or modify the selected path
- Why exploitation is possible: The option is not sufficiently constrained by the unsafe clone-option filtering, allowing repository metadata to be redirected outside the intended destination
Why this happens
The underlying bug is incomplete validation and filtering of a filesystem-affecting Git clone option. GitPython fails to treat --separate-git-dir as an unsafe option requiring restriction, so attacker-influenced input can control where repository metadata is created. This maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, because a user-controlled path can escape the application's intended filesystem boundary.
Potential impact
- An attacker may create arbitrary directories where the process has write access.
- Repository metadata may be placed outside the expected clone workspace.
- Git hooks may execute if later Git operations trust and process the redirected metadata.
- The affected application account or host may be compromised.
- Other files or workflows may be impacted through filesystem and repository manipulation.
General mitigation guidance
Mitigation generally focuses on removing attacker control over filesystem destinations and enforcing explicit path boundaries.
Common defensive patterns include:
- Rejecting or tightly constraining externally supplied separate Git directory paths.
- Resolving paths and verifying that they remain beneath an approved workspace.
- Using dedicated, minimally privileged accounts and isolated working directories for repository operations.
- Disabling or neutralizing Git hook execution when hooks are not required.
- Treating cloned repositories and their metadata as untrusted content.
- Applying filesystem permissions, sandboxing, and read-only controls where practical.
- Validating clone options against an explicit allowlist rather than passing arbitrary options through.
How teams detect issues like this
Organizations can look for this issue through:
- Static analysis rules identifying calls to
Repo.clone_from()orRepo.clone()with externally influencedseparate_git_dirvalues. - Code review checks for path canonicalization, workspace-boundary validation, and unrestricted clone-option forwarding.
- Repository and filesystem monitoring for unexpected
.gitdirectories or metadata created outside approved clone roots. - Runtime policy enforcement that restricts write access for Git-processing services and blocks unapproved hook execution.
- Automated security review tools that flag user-controlled paths reaching filesystem and repository APIs.

