Skip to content

fix: fence leading-dash remote names from git options - #4267

Merged
max-sixty merged 2 commits into
max-sixty:mainfrom
Duang777:fix/leading-dash-remotes
Sep 25, 2026
Merged

max-sixty merged 2 commits into
max-sixty:mainfrom
Duang777:fix/leading-dash-remotes

Conversation

@Duang777

Copy link
Copy Markdown
Contributor

Summary

  • resolve cached remote HEADs through a verified full ref, so a leading-dash remote cannot be echoed back as a bogus HEAD branch
  • place -- before remote operands in git ls-remote and git remote get-url
  • cover both default-branch detection and effective URL lookup with leading-dash remote regressions

Root 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/HEAD exits successfully and echoes -x/HEAD; Worktrunk stripped the remote prefix and cached HEAD as the default branch. If local HEAD lookup failed, git ls-remote --symref -x HEAD and git remote get-url -x parsed the remote as an option. Option-shaped names can be more than a lookup failure: a remote named --upload-pack=touch made unfenced ls-remote invoke touch HEAD during 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:

  • default branch: left: Some("HEAD"), right: Some("main")
  • effective URL: left: None, right: Some("../origin.git")

After the fix, both pass. A CLI reproducer with remote name --upload-pack=touch returns the remote's target branch and does not create a HEAD file.

Verification

  • cargo nextest run --test integration -E 'test(default_branch)': 67 passed
  • cargo run -- hook pre-merge --yes: 4,967 passed, 1 skipped
  • clippy, rustfmt, rustdoc, doctests, and pre-commit hooks passed

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

Copy link
Copy Markdown
Collaborator

test (macos) failed on one PTY test, switch_picker::test_switch_picker_prs_rows_survive_alt_x_removal. It timed out after 30s waiting for "Loading open PRs" while the picker frame was still blank (job log). The same test passed in test (linux) on this commit, and the other 4,966 macOS tests passed. This PR's changes are platform-independent argument fencing, so I'm treating the failure as a timing flake and leaving the approval in place. Rerunning the macOS job after the rest of the workflow run finishes should clear it.

@max-sixty
max-sixty enabled auto-merge (squash) September 25, 2026 07:05
@max-sixty
max-sixty merged commit 2014eb3 into max-sixty:main Sep 25, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants