fix: block unsafe long-option prefixes (GHSA-2f96-g7mh-g2hx)#2161
Open
Byron wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses GHSA-2f96-g7mh-g2hx by hardening GitPython’s unsafe-option filtering to also reject abbreviated long options (leveraging Git’s acceptance of long-option prefixes), and adds regression tests to prevent bypasses like upload_p → upload-pack.
Changes:
- Update
Git.check_unsafe_optionsto treat prefixes of unsafe long options as unsafe. - Add regression tests covering abbreviated unsafe options for clone/fetch/pull/push APIs.
- Expand unit coverage for canonicalization and prefix behavior in unsafe-option checks.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
git/cmd.py |
Implements prefix-aware unsafe-option matching (needs adjustment to avoid blocking safe short options). |
test/test_git.py |
Adds unit cases asserting abbreviated long options are detected as unsafe. |
test/test_remote.py |
Adds fetch/pull/push regression cases for abbreviated unsafe options. |
test/test_clone.py |
Adds clone/clone_from regression cases for abbreviated upload-pack options. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+983
to
+986
| if canonical_unsafe_option.startswith(canonical_option): | ||
| raise UnsafeOptionError( | ||
| f"{unsafe_option} is not allowed, use `allow_unsafe_options=True` to allow it." | ||
| ) |
c705fe7 to
ae091b7
Compare
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.
PR_HEADER
Tasks
Advisory
<= 3.1.50(to latest main at the time of report)Advisory summary
Git accepts long-option abbreviations, so exact-match unsafe-option checks could be bypassed (
upload_pmatchingupload-pack).This change keeps unsafe-option checks centralized in
Git.check_unsafe_optionsand rejects canonical option prefixes in addition to exact matches.Changes
git/cmd.py: prefix-aware unsafe-option matching against canonicalized option names.test/test_git.py: regression cases for abbreviated dangerous option names.test/test_remote.py: fetch/pull/push regression cases for abbreviated options.test/test_clone.py: clone and clone_from regression cases for abbreviated upload options.Validation
stg show c705fe7e...(contains the comment-only fix-up on top of the advisory patch stack)git rev-parse c705fe7ecodex review --commit c705fe7e(no blocking findings; comment-only change)pytestis not installed in this environment.Created by Codex on behalf of Byron. Byron will review before this is ready to merge.