GitPython Repo.init argument injection via --template

Severity: high · CVSS 7.5 · Published 2026-08-19

GitPython is a popular Python library used to interact with Git repositories. The Repo.init() method fails to validate user-supplied parameters before passing them to the git command, allowing an attacker to plant malicious git hooks that execute arbitrary code when the repository is used. An attacker needs low privileges and must stage an executable hook directory, but once exploited, this results in complete takeover of the process running GitPython.

Technologies: Gitpython Project Gitpython. Vendors: Gitpython Project.

Quick answers

Is This vulnerability exploited in the wild?
No. Junglewise Threat Intelligence has no report of This vulnerability being exploited in the wild.
How severe is This vulnerability?
High severity, with a CVSS score of 7.5, published 19 August 2026.
Which products and versions are affected?
Gitpython Project Gitpython <= 3.1.57.
Is there a fix for This vulnerability?
A patch was published on 2026-08-19: GitPython 3.1.58 and later include the fix Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.
How is This vulnerability attacked?
It is attacked over the network, in a software library.
Am I affected?
Check whether you run Gitpython Project Gitpython at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

Technical details

GitPython's Repo.init() method (git/repo/base.py:1435) forwards **kwargs directly to git init without any check_unsafe_options guard or allow_unsafe_options parameter. The vulnerability is an argument injection (CWE-88) where the --template option is passed unsanitized to the git command. When git init --template=&lt;attacker_dir&gt; executes, it copies hooks from the attacker-controlled directory into the repository's .git/hooks directory. Subsequently, when any git operation (e.g., commit) occurs, the malicious hook is executed with the privileges of the host process, achieving arbitrary code execution. Attack complexity is rated as High (AC:H) because two preconditions must be met: the application must pass a user-controlled template kwarg to Repo.init(), and the attacker must have the ability to stage an executable hook directory at a known path. The --template option is already recognized as unsafe for Repo.clone() but was overlooked in Repo.init(). GitPython 3.1.58 and later include the necessary guards.

Affected products

  • GitPython GitPython <= 3.1.57

Timeline

  • 2026-08-19: disclosed
  • 2026-08-19: patched: GitPython 3.1.58 and later include the fix
  • 2026-08-19: advisory: GHSA-298h-jpq4-m665 and GHSA-9rj7-rf2p-w77r; the former is marked as duplicate

References

This page as Markdown. Free to reuse under CC BY 4.0 with a link back.