Harden unsafe Git option validation#2180
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens GitPython’s unsafe Git option validation to block additional high-risk option spellings and close bypasses where unsafe options could be smuggled via argument transformation, while preserving explicit opt-in via allow_unsafe_options=True.
Changes:
- Extend
Git._option_candidates()to include option-like values emitted by split single-character kwargs, so unsafe-option checks cover those tokens too. - Add
--templateto the clone unsafe-option denylist to prevent hook installation during clone by default. - Add
allow_unsafe_optionsgating and unsafe-option checks to diff call paths (commit/tree/index) to reject--output/-ounless explicitly allowed, with regression tests.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
git/cmd.py |
Expands option-candidate detection to include split single-char kwarg values that look like options. |
git/repo/base.py |
Adds --template to unsafe_git_clone_options and documents why it’s unsafe. |
git/diff.py |
Adds allow_unsafe_options and blocks unsafe revision/output options prior to diff invocation. |
git/index/base.py |
Adds allow_unsafe_options to index diff and enforces unsafe-option checks; propagates flag through delegated diff calls. |
test/test_git.py |
Adds regression tests ensuring split single-char kwarg values are included in unsafe-option candidate detection. |
test/test_diff.py |
Adds regression tests ensuring diff output options are rejected by default and allowed only with explicit opt-in. |
test/test_clone.py |
Extends clone unsafe-option tests to cover --template and template=.... |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
<!-- agent --> Single-character keyword arguments are transformed into an option token and a separate value token. The unsafe-option candidate builder only checked the keyword name, allowing an option-like value to bypass guards shared by clone, remote, revision, blame, and archive operations. Include dash-prefixed values only when short options are actually split, including sequence values, while preserving bare values and the non-splitting compatibility path. Git baseline a23bace9 defines clone -n and --upload-pack as distinct options, matching the argv boundary this validation now preserves. Refs GHSA-r9mr-m37c-5fr3. Co-authored-by: Sebastian Thiel <sebastian.thiel@icloud.com>
<!-- agent --> Treat git clone --template as unsafe because caller-controlled templates can install hooks that execute during clone. Add regression coverage for both direct option and keyword forms. References GHSA-6p8h-3wgx-97gf. Validated against Git baseline a23bace9. Co-authored-by: Sebastian Thiel <sebastian.thiel@icloud.com>
<!-- agent --> Reject unsafe diff options before revision parsing or Git invocation so callers cannot write command output to arbitrary filesystem paths. Cover commit and index diffs, including option-like revisions, and preserve an explicit allow_unsafe_options escape hatch. References GHSA-fjr4-x663-mwxc. Validated against Git baseline a23bace9. Co-authored-by: Sebastian Thiel <sebastian.thiel@icloud.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Tasks
This section is for Byron only. Models continuing this PR must not add, remove, check, uncheck, rename, or reorder checkboxes here.
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
Harden GitPython's unsafe-option validation against three high-severity advisories affecting GitPython <= 3.1.53:
No CVEs or patched release versions are assigned yet.
Changes
--templateto the unsafe clone-option denylist.allow_unsafe_options=Falseto commit/tree/index diff paths and consistently guard--output/-o.allow_unsafe_options=True.Validation
Git behavior was checked against baseline
a23bace9.