GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — reject control chars in written values in configuration by Byron · Pull Request #2137 · gitpython-developers/GitPython

Conversation

@Byron

@Byron Byron commented Apr 28, 2026

Copy link
Copy Markdown
Member

Reject writing invalid values to Git configuration.
This is a deviation from Git, but it's safer that way, and the config implementation isn't conforming anyway.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@codex @Byron
reject control chars in written values in configuration
c417af4
Reject CR, LF, and NUL in GitConfigParser values before writing them
to git config files (which also is a deviation from Git which escapes them).

GitConfigParser._write() serializes embedded newlines as indented
continuation lines by replacing "\n" with "\n\t". Git itself skips
leading whitespace before parsing config tokens, so an injected value
such as:

    foo
    [core]
    hooksPath=/tmp/hooks

is written in a form where the indented "[core]" line is still parsed by
Git as a real section header. This lets attacker-controlled input passed
to config_writer().set_value() poison repository config, including
core.hooksPath, and redirect hook execution for later Git operations.

Fail closed instead of stripping or normalizing these characters. Silent
normalization can hide unsanitized caller input, and GitPython does not
currently round-trip Git-style escaped values such as "\n" as embedded
newlines.

Apply the validation to set_value(), add_value(), and the public set()
path so callers cannot bypass the safer helper API. Add regression tests
for the advisory payload and for CR, LF, NUL, and bytes values.

This preserves existing read behavior for config files that already
contain multiline values while preventing GitPython from writing new
unsafe values.

Co-authored-by: Sebastian Thiel <[email protected]>
Copilot AI review requested due to automatic review settings April 28, 2026 22:21
Copilot started reviewing on behalf of Byron April 28, 2026 22:24
View session
Copilot AI reviewed Apr 28, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens config writing by rejecting unsafe control characters in Git configuration values to prevent config-injection style payloads.

Changes:

  • Add validation to reject CR (\r), LF (\n), and NUL (\x00) in values being written to config.
  • Apply the validation to set, set_value, and add_value.
  • Add tests ensuring unsafe values are rejected and do not result in injected sections/options.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
git/config.py Introduces _value_to_string_safe() and uses it to reject CR/LF/NUL when writing config values.
test/test_config.py Adds regression tests for rejecting config-injection payloads and other unsafe value characters.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread git/config.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@codex @Byron
avoid duplicate validation in set_value
8e24503
Co-authored-by: Sebastian Thiel <[email protected]>
@Byron
Byron merged commit b049a13 into main Apr 28, 2026
59 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@lifeomic-review-bot lifeomic-review-bot Bot mentioned this pull request May 8, 2026
Bump gitpython from 3.1.47 to 3.1.49 lifeomic/fhir-petl#34
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@Byron @codex
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.