Repository navigation
fix: fence leading-dash remote names from git options - #4267
Merged
Merged
Conversation
Git accepts remote names beginning with a dash when the caller uses an option separator, despite the earlier flag-injection audit assuming otherwise. Unfenced names made the local HEAD lookup return a literal HEAD and let remote queries parse the name as an option. Resolve the local HEAD through a verified full ref and place -- before remote operands in ls-remote and remote get-url. Add red-green regressions for default-branch detection and effective URL lookup.
worktrunk-bot
approved these changes
Sep 25, 2026
Collaborator
|
|
max-sixty
enabled auto-merge (squash)
September 25, 2026 07:05
1 task
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.
Summary
HEADbranch--before remote operands ingit ls-remoteandgit remote get-urlRoot cause
Git accepts remote names beginning with
-when creation uses an option separator. The earlier flag-injection audit in #3317 assumed those names were invalid, so three call sites remained unfenced.For a remote named
-x,git rev-parse --abbrev-ref -x/HEADexits successfully and echoes-x/HEAD; Worktrunk stripped the remote prefix and cachedHEADas the default branch. If local HEAD lookup failed,git ls-remote --symref -x HEADandgit remote get-url -xparsed the remote as an option. Option-shaped names can be more than a lookup failure: a remote named--upload-pack=touchmade unfencedls-remoteinvoketouch HEADduring the local reproducer.The local lookup now verifies
refs/remotes/<remote>/HEAD, which cannot begin with an option marker. The two commands that require a raw remote operand now use--.Red/green evidence
Before the fix, the new regressions failed with:
left: Some("HEAD"),right: Some("main")left: None,right: Some("../origin.git")After the fix, both pass. A CLI reproducer with remote name
--upload-pack=touchreturns the remote'stargetbranch and does not create aHEADfile.Verification
cargo nextest run --test integration -E 'test(default_branch)': 67 passedcargo run -- hook pre-merge --yes: 4,967 passed, 1 skipped