Executive brief
GitPython is a popular Python library that developers use to programmatically interact with git repositories. A vulnerability in the Repo.init() method allows attackers to execute arbitrary code by supplying a malicious --template parameter that points to a directory containing git hooks. When the repository performs git operations, those hooks execute with the privileges of the host process, potentially compromising applications and their data.
Technical details
GitPython's Repo.init() method forwards keyword arguments directly to the git init command without validating or filtering unsafe options. Specifically, the --template option allows an attacker to point git to a directory containing malicious git hooks (e.g., post-commit) that will be copied into the repository's .git/hooks directory. When git operations are subsequently performed on the initialized repository, the attacker's hooks execute with the privileges of the calling process, achieving arbitrary code execution. The vulnerability requires two preconditions: (1) the application must forward a template= kwarg to Repo.init(), and (2) the attacker must be able to stage an executable hook directory at a known path. The fix adds a check_unsafe_options guard with an allow_unsafe_options parameter, similar to protections already applied to Repo.clone().
Affected products
- GitPython GitPython before 3.1.58
Timeline
- 2026-08-04: disclosed
- 2026-08-19: patched: Version 3.1.58 and later