GitPython: Arbitrary file read via --pathspec-from-file in IndexFile.remove() and Head.checkout()
GitPython versions prior to 3.1.58 contain a vulnerability in the IndexFile.remove() and Head.checkout() methods. These methods forward arbitrary keyword arguments into git rm and git checkout commands without proper validation. When used with the --pathspec-from-file and --pathspec-file-nul options, this allows an attacker to cause Git to treat the entire contents of a chosen file as a pathspec, leading to the file's contents being leaked in error messages. This results in an arbitrary file read vulnerability disclosed through GitCommandError.stderr.
AI Analysis
Technical Summary
GitPython's IndexFile.remove() and Head.checkout() methods forward **kwargs directly into git rm and git checkout commands without guarding unsafe options. By passing --pathspec-from-file=<file> together with --pathspec-file-nul, Git treats the entire file as a single NUL-delimited pathspec. When the pathspec does not match any files, Git outputs an error message quoting the entire file contents verbatim. GitPython surfaces this error output through GitCommandError.stderr, effectively leaking the contents of any file accessible to the caller. This vulnerability affects GitPython versions prior to 3.1.58 and is a variant of a previously assessed issue (GHSA-3f7w-8rr8-f37f) but at different call sites that were previously considered safe. The root cause is the lack of validation or restriction on unsafe git command options in these methods.
Potential Impact
An attacker with the ability to invoke these GitPython methods with crafted parameters can read arbitrary files on the system that the process has access to. This can lead to disclosure of sensitive information such as configuration files or credentials. The vulnerability does not allow code execution or modification, only information disclosure. The CVSS score of 6.5 reflects a medium severity impact with network attack vector, low attack complexity, and requiring some privileges.
Mitigation Recommendations
A patch is available in GitPython version 3.1.58 that addresses this issue by properly guarding unsafe options in the affected methods. Users should upgrade to version 3.1.58 or later to remediate this vulnerability. Until patched, avoid passing untrusted input to the pathspec_from_file and pathspec_file_nul parameters in IndexFile.remove() and Head.checkout().
GitPython: Arbitrary file read via --pathspec-from-file in IndexFile.remove() and Head.checkout()
Description
GitPython versions prior to 3.1.58 contain a vulnerability in the IndexFile.remove() and Head.checkout() methods. These methods forward arbitrary keyword arguments into git rm and git checkout commands without proper validation. When used with the --pathspec-from-file and --pathspec-file-nul options, this allows an attacker to cause Git to treat the entire contents of a chosen file as a pathspec, leading to the file's contents being leaked in error messages. This results in an arbitrary file read vulnerability disclosed through GitCommandError.stderr.
CVSS v3.1
Score 6.5medium
Affected software
Run on your own infrastructure? Check whether these packages are installed with threat-finder — our free open-source scanner.
AI-Powered Analysis
Machine-generated threat intelligence
Technical Analysis
GitPython's IndexFile.remove() and Head.checkout() methods forward **kwargs directly into git rm and git checkout commands without guarding unsafe options. By passing --pathspec-from-file=<file> together with --pathspec-file-nul, Git treats the entire file as a single NUL-delimited pathspec. When the pathspec does not match any files, Git outputs an error message quoting the entire file contents verbatim. GitPython surfaces this error output through GitCommandError.stderr, effectively leaking the contents of any file accessible to the caller. This vulnerability affects GitPython versions prior to 3.1.58 and is a variant of a previously assessed issue (GHSA-3f7w-8rr8-f37f) but at different call sites that were previously considered safe. The root cause is the lack of validation or restriction on unsafe git command options in these methods.
Potential Impact
An attacker with the ability to invoke these GitPython methods with crafted parameters can read arbitrary files on the system that the process has access to. This can lead to disclosure of sensitive information such as configuration files or credentials. The vulnerability does not allow code execution or modification, only information disclosure. The CVSS score of 6.5 reflects a medium severity impact with network attack vector, low attack complexity, and requiring some privileges.
Mitigation Recommendations
A patch is available in GitPython version 3.1.58 that addresses this issue by properly guarding unsafe options in the affected methods. Users should upgrade to version 3.1.58 or later to remediate this vulnerability. Until patched, avoid passing untrusted input to the pathspec_from_file and pathspec_file_nul parameters in IndexFile.remove() and Head.checkout().
Technical Details
- Gcve Source
- db.gcve.eu
- Osv Id
- GHSA-hh9p-6wh2-4mfc
- Osv Schema Version
- 1.4.0
- Aliases
- []
- Ecosystems
- ["PyPI"]
- Database Specific Severity
- MODERATE
- Cvss Version
- 3.1
Threat ID: 6a774331bf8831d539b463f2
Added to database: 08/08/2026, 14:54:41 UTC
Last enriched: 08/08/2026, 15:41:39 UTC
Last updated: 08/09/2026, 00:49:37 UTC
Views: 8
Community Reviews
0 reviewsCrowdsource mitigation strategies, share intel context, and vote on the most helpful responses. Sign in to add your voice and help keep defenders ahead.
Want to contribute mitigation steps or threat intel context? Sign in or create an account to join the community discussion.
Actions
Updates to AI analysis require Pro Console access. Upgrade inside Console → Billing.
Need more coverage?
Upgrade to Pro Console for AI refresh and higher limits.
For incident response and remediation, OffSeq services can help resolve threats faster.
Latest Threats
Check if your credentials are on the dark web
Instant breach scanning across billions of leaked records. Free tier available.