GitPython: Unguarded git option forwarding in Repo.init enables arbitrary command execution via --template clone hooks
GitPython versions up to 3.1.57 have a vulnerability in the Repo.init() method where unsafe git options are forwarded without validation. Specifically, the --template option can be exploited by an attacker to plant malicious git hooks that execute arbitrary code during subsequent git operations. This occurs because Repo.init() directly passes kwargs to git init without checking for unsafe options, unlike the clone path which has protections. Exploitation requires the attacker to control the template directory and stage executable hooks. A fix is available that adds unsafe option checks to Repo.init().
AI Analysis
Technical Summary
The vulnerability exists in GitPython's Repo.init() method, which forwards all keyword arguments directly to the underlying git init command without any guard against unsafe options. The --template option allows specifying a directory whose hooks are copied into the new repository's .git/hooks directory. An attacker who can control the template directory can plant malicious hooks that execute arbitrary code on the next git operation. Unlike git clone, which has a denylist for unsafe options, Repo.init() lacks such checks, making it vulnerable. The attack requires two conditions: the application must forward a template kwarg controlled by the attacker, and the attacker must stage an executable hook directory at a known path. This vulnerability is tracked as GHSA-9rj7-rf2p-w77r and affects GitPython versions prior to 3.1.58.
Potential Impact
Successful exploitation results in arbitrary code execution with the privileges of the host process running the git operation. The attack complexity is high because the attacker must both stage an executable hook directory and influence the template argument passed to Repo.init(). The impact includes full compromise of the affected environment through malicious git hooks triggered on subsequent git commands.
Mitigation Recommendations
A patch is available that adds a check_unsafe_options guard to Repo.init(), including a denylist of unsafe options such as --template and --separate-git-dir. Users should upgrade to GitPython version 3.1.58 or later where this fix is implemented. Until patched, avoid passing untrusted input to the template parameter in Repo.init() to prevent arbitrary code execution.
GitPython: Unguarded git option forwarding in Repo.init enables arbitrary command execution via --template clone hooks
Description
GitPython versions up to 3.1.57 have a vulnerability in the Repo.init() method where unsafe git options are forwarded without validation. Specifically, the --template option can be exploited by an attacker to plant malicious git hooks that execute arbitrary code during subsequent git operations. This occurs because Repo.init() directly passes kwargs to git init without checking for unsafe options, unlike the clone path which has protections. Exploitation requires the attacker to control the template directory and stage executable hooks. A fix is available that adds unsafe option checks to Repo.init().
CVSS v3.1
Score 7.5high
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
The vulnerability exists in GitPython's Repo.init() method, which forwards all keyword arguments directly to the underlying git init command without any guard against unsafe options. The --template option allows specifying a directory whose hooks are copied into the new repository's .git/hooks directory. An attacker who can control the template directory can plant malicious hooks that execute arbitrary code on the next git operation. Unlike git clone, which has a denylist for unsafe options, Repo.init() lacks such checks, making it vulnerable. The attack requires two conditions: the application must forward a template kwarg controlled by the attacker, and the attacker must stage an executable hook directory at a known path. This vulnerability is tracked as GHSA-9rj7-rf2p-w77r and affects GitPython versions prior to 3.1.58.
Potential Impact
Successful exploitation results in arbitrary code execution with the privileges of the host process running the git operation. The attack complexity is high because the attacker must both stage an executable hook directory and influence the template argument passed to Repo.init(). The impact includes full compromise of the affected environment through malicious git hooks triggered on subsequent git commands.
Mitigation Recommendations
A patch is available that adds a check_unsafe_options guard to Repo.init(), including a denylist of unsafe options such as --template and --separate-git-dir. Users should upgrade to GitPython version 3.1.58 or later where this fix is implemented. Until patched, avoid passing untrusted input to the template parameter in Repo.init() to prevent arbitrary code execution.
Technical Details
- Gcve Source
- db.gcve.eu
- Osv Id
- GHSA-9rj7-rf2p-w77r
- Osv Schema Version
- 1.4.0
- Aliases
- []
- Ecosystems
- ["PyPI"]
- Database Specific Severity
- HIGH
- Cvss Version
- 3.1
Threat ID: 6a774331bf8831d539b46414
Added to database: 08/08/2026, 14:54:41 UTC
Last enriched: 08/08/2026, 15:41:49 UTC
Last updated: 08/08/2026, 16:02:47 UTC
Views: 5
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.