Executive brief
GitPython is a Python library used to interact with Git repositories. When GitPython reads and then re-writes Git configuration files, it incorrectly handles multi-line values by converting them into separate configuration directives. An attacker can exploit this by crafting a repository with a malicious configuration value that, when GitPython performs a routine config write operation, becomes a live directive (such as core.hooksPath) that executes arbitrary code during Git hook operations like commit or push.
Technical details
The vulnerability exists in GitConfigParser's read and write logic. GitPython's _read() method correctly parses standard git config multi-line values (quoted values with backslash continuation and decoded \n escape sequences). However, write_section() re-serializes these values using an unsafe path that replaces embedded newlines with newline+tab sequences, which git does not recognize as continuation syntax. This transforms a legitimate dormant value like "A\nhooksPath = ../evil-hooks" into two separate config directives when re-parsed. An attacker can embed this in a repository's .git/config or an included config file; the next time a GitPython-based application performs any routine config write (e.g., setting user.name), the dormant value is re-serialized, activating the injected core.hooksPath directive. This enables arbitrary code execution when git triggers hooks. The fix is available in GitPython 3.1.59 and later.
Affected products
- Python Software Foundation GitPython <= 3.1.58
Timeline
- 2026-08-10: disclosed: Original advisory GHSA-284h-m62q-gf8w published
- 2026-08-25: other: Duplicate advisory GHSA-9557-234j-7rv9 published
- 2026-08-25: patched: Patched version 3.1.59 available