---
schema_version: '1.0'
id: security-20260808-c870c0
title: 'CVE-2026-76221: GitPython: git-config OPTION-name injection via =/#/whitespace
  bypasses name validator, enabling forged core.sshCommand/hooksPath (RCE)'
url: https://osv.dev/vulnerability/GHSA-jm78-9fvv-mhgr
url_hash: c870c086e5a7fb8f0443797fed110cde7af4baaea3552f7c0996da8618dd4595
canonical_url: https://osv.dev/vulnerability/GHSA-jm78-9fvv-mhgr
source: osv:ghsa
category: security/library
category_raw: cve/library
region: null
tags:
- cve
- CVE-2026-76221
- GHSA-jm78-9fvv-mhgr
- severity:CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
- gitpython
- PyPI
lang: en
published_at: '2026-08-07T15:46:35Z'
fetched_at: '2026-08-08T07:35:11.051483Z'
updated_at: '2026-08-22T14:33:35Z'
status: published
content_hash: a94fa4aaaded12737cd986542a07c3bc427b5441c604a04dbe2ac1085070ffb1
content_changed_at: '2026-08-22T13:15:21.318416Z'
license_note: full
summary: 'GitPython: git-config OPTION-name injection via =/#/whitespace bypasses
  name validator, enabling forged core.sshCommand/hooksPath (RCE)'
summary_source: rss
summary_en: 'GitPython: git-config OPTION-name injection via =/#/whitespace bypasses
  name validator, enabling forged core.sshCommand/hooksPath (RCE)'
summary_omitted_reason: null
redistribution: true
keywords_en:
- bypasses
- core.sshCommand
- CVE
- CVE-2026-76221
- enabling
- forged
- GHSA-jm78-9fvv-mhgr
- git-config
- gitpython
- hooksPath
- injection
- library vulnerability
- name
- OPTION-name
- PyPI
- RCE
- severity:CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
- software security
- validator
- via
- whitespace
entities_en:
- name: CVE
  type: data
- name: PyPI
  type: artifact
topics_en:
- library vulnerability
- software security
numeric_facts: []
entities:
- name: CVE
  type: data
- name: PyPI
  type: artifact
related_auto:
- name: Portal
  type: organization
  weight: 1.0
- name: Hugging Face
  type: organization
  weight: 1.0
computed_at: '2026-08-22T14:33:32Z'
---

# CVE-2026-76221: GitPython: git-config OPTION-name injection via =/#/whitespace bypasses name validator, enabling forged core.sshCommand/hooksPath (RCE)

## TL;DR
GitPython: git-config OPTION-name injection via =/#/whitespace bypasses name validator, enabling forged core.sshCommand/hooksPath (RCE)

## Key Points
- cve / CVE-2026-76221 / GHSA-jm78-9fvv-mhgr / severity:CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H / gitpython / PyPI

## Details
**Severity:** CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
**Advisory:** GHSA-jm78-9fvv-mhgr (CVE-2026-76221)

**Details:**
## 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
```python
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.sshCommand` → `touch <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

**References:**
- 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
- https://github.com/gitpython-developers/GitPython/releases/tag/3.1.58

_Data: OSV.dev (upstream: ghsa) — https://osv.dev/vulnerability/GHSA-jm78-9fvv-mhgr_

## Source
元記事: [CVE-2026-76221: GitPython: git-config OPTION-name injection via =/#/whitespace bypasses name validator, enabling forged core.sshCommand/hooksPath (RCE)](https://osv.dev/vulnerability/GHSA-jm78-9fvv-mhgr) — published 2026-08-07T15:46:35Z
