Executive brief
GitPython is a Python library used by developers to programmatically interact with Git repositories. Versions before 3.1.51 contain a flaw in their input validation that allows attackers to bypass security checks by using abbreviated git option names. An attacker who can control function parameters in an application using GitPython can execute arbitrary commands on the server running the application, potentially compromising source code, credentials, and system integrity.
Technical details
This is an OS command injection vulnerability (CWE-78) rooted in an incomplete blocklist (CWE-184). The vulnerable code's _canonicalize_option_name() function normalizes option names by converting underscores to hyphens and performs exact-match lookup against a dictionary of dangerous options (--upload-pack, --receive-pack, --exec, --config, etc.). However, it fails to account for git's unambiguous long-option prefix abbreviation feature: git accepts any unambiguous prefix of a long option (e.g., --upload-p, --upload-pa, or --upload-pac all resolve to --upload-pack). An attacker can bypass the blocklist by passing abbreviated kwarg keys like upload_p, which canonicalize to upload-p, miss the exact-match check, and are emitted to git as --upload-p=<value>, where git expands them to dangerous options. Attack vector requires network access and authenticated user interaction with a host application that flows attacker-controlled kwarg keys into GitPython clone/fetch/pull/push calls with default allow_unsafe_options=False. Exploitation results in arbitrary command execution. Patch available in GitPython 3.1.51.
Affected products
- GitPython Contributors GitPython before 3.1.51
Timeline
- 2026-07-12: disclosed
- 2026-07-12: patched: Version 3.1.51 released