Skip to content

[WIP] Fix GitPython vulnerability for config-name injection - #18

Merged
eliasinul merged 2 commits into
devfrom
copilot/fix-gitpython-vulnerability
Aug 24, 2026
Merged

[WIP] Fix GitPython vulnerability for config-name injection#18
eliasinul merged 2 commits into
devfrom
copilot/fix-gitpython-vulnerability

Conversation

Copilot AI commented Aug 24, 2026

Copy link
Copy Markdown
Contributor
  • Update GitPython from 3.1.57 to 3.1.59 in uv.lock via uv lock --upgrade-package gitpython

Reachability Assessment

GitPython is not directly used in this codebase — no files import git, use config_writer(), or call set_value(). It is a transitive dependency pulled in by snakemake. 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_section with a crafted option name) and a search of all .py files 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_section writes the option name verbatim into the config file, so an option name such as sshCommand = touch <cmd> # is written as \tsshCommand = touch <cmd> # = <value>, which git parses as core.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 when label == "section"; for the "option" label it falls through with just the UNSAFE_CONFIG_CHARS_RE = [\r\n\x00] regex. write_section then 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) or core.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

with repo.config_writer() as cw:
    cw.set_value("core", "sshCommand = touch /tmp/RCE #", "x")
# git config --get core.sshCommand  ->  touch /tmp/RCE

Attack Chain

  1. Entry: app calls config writer with attacker-controlled OPTION name: set_value("core", "sshCommand = touch /tmp/RCE #", "x").
  2. Check: _assure_config_name_safe(option, "option") @ config.py. Guard: regex matches only [\r\n\x00]; bracket/quote state machine is gated on label=="section". Bypass proof: =,#,space pass → no ValueError.
  3. Sink: write_section writes "\tsshCommand = touch /tmp/RCE # = x\n" (config.py:702).
  4. Impact: git parses 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') → no ValueError; file line sshCommand = touch <RCE> # = x; git config --get core.sshCommandtouch <RCE> (rc=0). Also verified core.hooksPath via both GitConfigParser and repo.config_writer(). Fix-commit read: bracket/quote checks are inside if 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
GHSA-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>

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-mhgr

<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 ...

…E via config option-name injection)

Co-authored-by: eliasinul <107138989+eliasinul@users.noreply.github.com>
@eliasinul eliasinul closed this Aug 24, 2026
Copilot stopped work on behalf of eliasinul due to an error August 24, 2026 23:35
Copilot AI requested a review from eliasinul August 24, 2026 23:35
@eliasinul eliasinul reopened this Aug 24, 2026
@eliasinul
eliasinul marked this pull request as ready for review August 24, 2026 23:36
@eliasinul
eliasinul merged commit 4a2c0cc into dev Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants