/

CVE-2026-67326

Severity:

HIGH RISK

(7.0)

Input Validation Flaw (CWE-20) in GitPython Config Writer

CVE-2026-67326

Analyzed

Vulnerability type

Category:

Improper Input Validation

CWE:

CWE-20

Impact:

Remote Code Execution via Malicious Git Hooks

Severity:

HIGH RISK

(7.0)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

GitPython fails to properly validate newline characters in the section parameter of config_writer(), enabling injection of arbitrary section headers into .git/config.

Under conditions where an attacker can influence config_writer() input, this can be abused to forge a [core] hooksPath pointing to attacker-controlled directories, leading to remote code execution when git hooks run.

Affected context

This vulnerability affects applications or tooling that embed GitPython (before 3.1.50) and invoke config_writer() to manipulate repository configuration.

It is most relevant when user-supplied or otherwise untrusted values are passed as the section name, and when the resulting .git/config is later consumed by a git client that honors hooksPath.

Environments where git hooks are enabled and can be triggered (for example, during commits, pushes, or other lifecycle actions) are particularly exposed.

Exploit preconditions

  • Attack surface: Any interface that allows an attacker to control or influence the section parameter of GitPython's config_writer().
  • Required access: Ability to supply or tamper with configuration values used by config_writer(), typically via application inputs, APIs, or plugin systems.
  • Trigger point: A crafted section value containing newline characters is written into .git/config, resulting in injected section headers and a forged core.hooksPath pointing to attacker-controlled content.
  • Why exploitation is possible: The library does not sanitize or reject newline characters in the section field, permitting config injection and redirection of git hooks to arbitrary directories.

Why this happens

The underlying issue is improper input validation in GitPython's configuration writing logic.

The section parameter, which should represent a single well-formed configuration section name, is not checked for control characters such as newlines.

This allows attackers to break out of the intended section context and inject additional, unintended sections into .git/config, including a spoofed [core] section with a malicious hooksPath.

Conceptually, this aligns with CWE-20: Improper Input Validation, where failure to constrain and sanitize inputs permits structural manipulation of configuration data and redirection of execution to attacker-controlled locations.

Potential impact

  • Remote code execution via malicious git hooks located in attacker-controlled directories.
  • Execution of arbitrary scripts during common git workflows (e.g., commit, push, merge) on developer or CI/CD machines.
  • Compromise of developer workstations, build agents, or automation systems that use GitPython to manage git configuration.
  • Introduction of backdoors or supply-chain attacks by tampering with repositories and build outputs.

General mitigation guidance

Effective mitigation focuses on constraining configuration input and minimizing trust in dynamic configuration sources.

Recommended defensive patterns include:

  • Enforcing strict validation on section names passed to config_writer(), rejecting or escaping newline and other control characters.
  • Restricting the origin of configuration values so that only trusted, predefined section identifiers are used when writing .git/config.
  • Decoupling user-controllable inputs from low-level git configuration, introducing mapping layers or whitelists for allowable section names and paths.
  • Operating with least privilege by limiting the availability and use of git hooks in high-risk environments such as CI/CD infrastructure.
  • Applying defense-in-depth by treating git configuration as sensitive and reviewing any automation that programmatically modifies .git/config.

How teams detect issues like this

Detection can target both code-level patterns and runtime configuration anomalies.

Possible approaches include:

  • Static analysis rules that flag calls to GitPython's config_writer() where the section argument is derived from user input or unconstrained variables.
  • Code review checklists that require validation of all configuration section names and paths, with special scrutiny on .git/config writers.
  • Automated scanning of repositories or workspaces for suspicious .git/config entries, such as unexpected [core] sections or hooksPath values pointing outside approved directories.
  • Security policies in CI/CD pipelines that monitor for or block unapproved git hooks directories and enforce standardized configuration templates.

Automated code review tools and configuration linters can help surface misuse of configuration writers before deployments.

Sources

SourceLink
github.comgithub.com/gitpython-developers/GitPython/security/advisories/GHSA-mv93-w799-cj2w
vulncheck.comvulncheck.com/advisories/gitpython-before-newline-injection-via-config-writer-section

Frequently asked

questions

It can be, depending on how GitPython is integrated. If an application exposes an API or interface that allows remote users to control configuration values passed to config_writer(), a remote attacker may exploit the issue. Otherwise, exploitation may be limited to local or insider threat scenarios.

An attacker needs the ability to influence the section parameter used by GitPython's config_writer() and ensure the resulting .git/config is used by a git client that triggers hooks. This might be via a web form, configuration file, plugin system, or other indirect input channel.

The safest general fix pattern is to strictly validate and sanitize section names before invoking config_writer(), disallowing control characters such as newlines and enforcing a whitelist of expected section identifiers. Additionally, isolating or disabling git hooks where they are not required reduces the impact.

To prevent similar issues, adopt a defensive stance toward configuration-writing APIs: validate all inputs, avoid directly passing user-controlled data into configuration structures, and implement robust code review practices focused on configuration and hook handling. Incorporating automated checks for configuration injection patterns in CI pipelines further reduces the risk of recurrence.

Find out what's already
exploitable in your codebase.