fix: harden config parsing boundaries by Byron · Pull Request #2211 · gitpython-developers/GitPython
Repository navigation
fix: harden config parsing boundaries - #2211
Merged
Byron merged 2 commits into main from config-sanitize-more Aug 10, 2026
Merged
fix: harden config parsing boundaries #2211 Byron merged 2 commits into main from config-sanitize-more
Conversation
Byron commented Aug 10, 2026 · edited Loading
Copy link Copy Markdown
Member
Tasks
This section is for Byron only. Models continuing this PR must not add, remove, check, uncheck, rename, or reorder checkboxes here.
- refackiew
Everything below this line was generated by Codex GPT-5.
Created by Codex on behalf of Byron. Byron will review before this is ready to merge.
Summary
- Preserve parsed multiline Git config values when an unrelated write reserializes the file, keeping each value structurally intact.
- Disable include merging for
.gitmodules, so repository-controlled submodule configuration cannot cause unrelated local files to be opened.
Advisories
- GHSA-284h-m62q-gf8w (
GHSA-284h-m62q-gf8w) - GHSA-7833-fr7j-v32q (
GHSA-7833-fr7j-v32q)
Both advisories remain private/under triage, so reproduction and exploit details are intentionally omitted here.
Advisory summary
GHSA-284h-m62q-gf8w
- Severity: High
- Package:
GitPython(pip) - Affected versions:
<= 3.1.58 - Patched versions: not yet assigned
- CVE: not yet assigned
GHSA-7833-fr7j-v32q
- Severity: High
- Package:
GitPython(pip) - Affected versions:
<= 3.1.58 - Patched versions: not yet assigned
- CVE: not yet assigned
Baselines
- Git
config.catcf5497b14c5aserializes embedded LF with an escape rather than as a physical config line. - Existing GitPython hardening in
41ecc6a4disables include merging for another write-sensitive config parser.
Validation
- Focused regressions for both advisories
pytest -q test/test_config.py(35 passed, 2 skipped)pytest -q(passed after each commit)- Targeted Ruff lint and format checks
git diff --check
fix: preserve multiline config values when writing
4b4e47f
<!-- agent --> GitConfigParser decoded valid multiline values into embedded newlines, but _write() serialized those newlines as indented physical lines. Rewriting an otherwise unchanged config could therefore change its meaning to Git. Serialize resident multiline values with Git-compatible escapes inside a quoted continuation, preserving GitPython read compatibility while keeping each option structurally intact. This addresses GHSA-284h-m62q-gf8w. The regression starts with an inert multiline value, performs an unrelated write, and verifies with both GitPython and git config that it remains one value and does not create another option. Git baseline: config.c parse_value() and write_pair() at cf5497b14c5a escape embedded LF as \\n rather than emitting it as a physical config line. Assisted-by: GPT 5.6 Co-authored-by: GPT 5.6 <codex@openai.com>
fix: ignore includes in submodule configuration
ef7568e
<!-- agent --> Submodule configuration is read from .gitmodules, whose contents may come from an untrusted repository. Its parser inherited merge_includes=True and could therefore open files named by include directives during ordinary submodule enumeration. Disable include merging at the SubmoduleConfigParser construction site. This matches Repo.config_writer() hardening from 41ecc6a and addresses GHSA-7833-fr7j-v32q without changing include behavior for trusted config parsers. The regression points .gitmodules at a non-config file and verifies the submodule entry remains readable without opening the included path. Assisted-by: GPT 5.6 Co-authored-by: GPT 5.6 <codex@openai.com>Byron force-pushed the config-sanitize-more branch from
5326ebf to
ef7568e
Compare
August 10, 2026 11:31 Byron marked this pull request as ready for review August 10, 2026 11:55 Copilot PR reviewer Copilot
AI
lite review requested due to automatic review settings August 10, 2026 11:55 Byron merged commit
a5e047d
into
main
Aug 10, 2026
54 checks passed
Copilot started reviewing on behalf of
Byron
August 10, 2026 11:56
View session
Byron deleted the config-sanitize-more branch August 10, 2026 11:57 chatgpt-codex-connector
Bot
reviewed Aug 10, 2026
View reviewed changes
chatgpt-codex-connector
Bot
left a comment
Copy link Copy Markdown
Contributor
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ef7568e3b3
Your team has set up Codex to review pull requests in this repo . Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Copilot PR reviewer CopilotAI
reviewed Aug 10, 2026
View reviewed changes
Copilot
AI
left a comment
Copy link Copy Markdown
Contributor
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
Pull request overview
Hardens Git config parsing/serialization to prevent unsafe boundary crossings when rewriting config files and when parsing repository-controlled .gitmodules, aligning GitPython behavior more closely with Git's escaping and include-handling expectations.
Changes:
- Update
GitConfigParserwriter to escape/quote values containing special characters (notably multiline values) instead of emitting physical continuation lines. - Disable
[include]merging when parsing.gitmodulesviaSubmoduleConfigParser. - Add regression tests covering multiline rewrite safety, special-character escaping, and
.gitmodulesinclude isolation.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
git/config.py |
Adjusts config serialization to quote/escape special characters to preserve multiline values safely. |
git/objects/submodule/base.py |
Forces .gitmodules parsing to use merge_includes=False to avoid opening arbitrary local files. |
test/test_config.py |
Adds tests to ensure multiline rewrite doesn't create unintended options and that special chars round-trip and match git config. |
test/test_submodule.py |
Adds a test ensuring .gitmodules does not merge includes (and thus doesn't parse unrelated files). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.