[WIP] Fix GitPython vulnerability for config-name injection - #18
Merged
Conversation
…E via config option-name injection) Co-authored-by: eliasinul <107138989+eliasinul@users.noreply.github.com>
Copilot stopped work on behalf of
eliasinul due to an error
August 24, 2026 23:35
eliasinul
marked this pull request as ready for review
August 24, 2026 23:36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
uv lock --upgrade-package gitpythonReachability Assessment
GitPython is not directly used in this codebase — no files import
git, useconfig_writer(), or callset_value(). It is a transitive dependency pulled in bysnakemake. The vulnerable API (config_writer().set_value(section, option_name, value)with attacker-controlled option names) is never called directly by this project's code.Confidence: High — the advisory names a specific API (
set_value/write_sectionwith a crafted option name) and a search of all.pyfiles in the repository confirms zero direct imports or usage of GitPython APIs.The update is primarily to satisfy vulnerability scanners rather than to address an active risk in this codebase.
Original prompt
This section details the Dependabot vulnerability alert you should resolve
<alert_title>GitPython: git-config OPTION-name injection via =/#/whitespace bypasses name validator, enabling forged core.sshCommand/hooksPath (RCE)</alert_title>
<alert_description>## Summary
GitPython's config-name validator only neutralizes CR/LF/NUL for the
"option"label; it does not reject=,#,;,[,], or whitespace in an option name.write_sectionwrites the option name verbatim into the config file, so an option name such assshCommand = touch <cmd> #is written as\tsshCommand = touch <cmd> # = <value>, which git parses ascore.sshCommand = touch <cmd>(the trailing#comments out the intended value). This forges arbitrary config directives (core.sshCommand,core.hooksPath,alias.*) → RCE on the next git operation. This is a distinct field (option name, not section name) and distinct character class (=/#/space, not newline/bracket) from GHSA-3rp5-jjmw-4wv2 (section-name bracket injection) and GHSA-mv93-w799-cj2w / GHSA-v87r-6q3f-2j67 (newline injection).Root Cause
_assure_config_name_safe(name, label)(git/config.py:897) applies the bracket/quote state machine ONLY whenlabel == "section"; for the"option"label it falls through with just theUNSAFE_CONFIG_CHARS_RE = [\r\n\x00]regex.write_sectionthen writes the option name verbatim into"\t%s = %s\n"(config.py:702).Impact
Arbitrary git-config directive injection → remote code execution via
core.sshCommand(fires on any ssh git operation, no staged file needed) orcore.hooksPath(with a staged hook). Requires the embedding application to forward a caller-influenced OPTION NAME into the config writer (name-control model, the same name-control model accepted by the related published advisories GHSA-3rp5-jjmw-4wv2 and GHSA-mv93-w799-cj2w). Default configuration.Proof of Concept
Attack Chain
set_value("core", "sshCommand = touch /tmp/RCE #", "x")._assure_config_name_safe(option, "option")@ config.py. Guard: regex matches only[\r\n\x00]; bracket/quote state machine is gated onlabel=="section". Bypass proof:=,#,space pass → noValueError.write_sectionwrites"\tsshCommand = touch /tmp/RCE # = x\n"(config.py:702).core.sshCommand=touch /tmp/RCE→ arbitrary code execution on next git op.Bypass Evidence
Independently reproduced (gate harness):
set_value('core','sshCommand = touch <RCE> #','x')→ noValueError; file linesshCommand = touch <RCE> # = x;git config --get core.sshCommand→touch <RCE>(rc=0). Also verifiedcore.hooksPathvia bothGitConfigParserandrepo.config_writer(). Fix-commit read: bracket/quote checks are insideif label == "section"; the"option"label is not covered.Affected Versions
GitPython <= 3.1.57(validator present verbatim on the latest release tag).Suggested Fix
Apply the section-name safety checks (reject
=,#,;,[,], whitespace) to the"option"label as well, or validate the fully-rendered config line after substitution.Reported by zx (Jace) — GitHub: @manus-use</alert_description>
high
https://github.com/gitpython-developers/GitPython/security/advisories/GHSA-jm78-9fvv-mhgr https://github.com/gitpython-developers/GitPython/pull/2204 https://github.com/gitpython-developers/GitPython/commit/a495ccd3b547ccd60b2187215823b72a9c0188bf https://github.com/gitpython-developers/GitPython/releases/tag/3.1.58 https://github.com/advisories/GHSA-jm78-9fvv-mhgrGHSA-jm78-9fvv-mhgr
GitPython
pip
<vulnerable_versions>= 3.1.57</vulnerable_versions>
<patched_version>3.1.58</patched_version>
<manifest_path>uv.lock</manifest_path>
<agent_instructions>resolve the root cause
</agent_instructions>
<task_instructions>Resolve this alert by updating the affected package to a non-vulnerable version. Prefer the lowest non-vulnerable version (see the patched_version field above) over the latest to minimize breaking changes. Include a Reachability Assessment section in the PR description. Review the alert_description field to understand which APIs, features, or configurations are affected, then search the codebase for usage of those specific items. If the vulnerable code path is reachable, explain how (which files, APIs, or call sites use the affected functionality) and note that the codebase is actively exposed to this vulnerability. If the vulnerable code path is not reachable, explain why (e.g. the affected API is never called, the vulnerable configuration ...