Executive brief
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.
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=<attacker_dir> 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