Repository navigation
fix: reject remote names starting with '-' - #95
Merged
Merged
Conversation
git fetch was given the remote name without a "--", and git allows a remote named like "--upload-pack=<command>", so fetching it ran that command. Such a name is now never passed to git: as the main remote it is a fatal error before anything is fetched, and as another remote a branch tracks it is handled like a remote that can't be fetched (a warning, and the branches tracking it are skipped). --end-of-options is not used because it needs git 2.24 and gh-sync supports git 2.23. Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 58 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
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.
Problem
fetchRemoterunsgit fetch --prune --quiet --progress <name>without a--. Remote names come fromgit remote -v(that is,.git/config) and from--remote, and git accepts a remote named like--upload-pack=/path/to/script(git remote add -- <name> <url>).git fetchthen reads the name as an option and runs the script. Exploiting this needs write access to.git/config, so the severity is low, but the other places that pass outside values to a command are already guarded (ssh -G --,worktree remove --, the-check onheadRefOid).Fix
A remote name starting with
-is never passed to git.--end-of-optionsis not used because it needs git 2.24 and gh-sync supports git 2.23.--remote): gh-sync stops withfatal: remote name '<name>' starts with '-'before anything is fetched.fetchRemoteitself refuses the name, so it is handled exactly like a remote that can't be fetched: a warning, the branches tracking it are skipped, the main remote's branches are still synced, and the exit status is 1. I chose this over failing the whole run because it is what already happens when one of these remotes is broken, and one badbranch.<name>.remoteshould not stop the unrelated branches from syncing. The non-zero exit status still makes it noticeable.The check lives in
fetchRemote, the only place a bare remote name is an argument to git, so a future caller is covered too. The other uses of a remote name were reviewed: they are all prefixed (refs/remotes/<name>/...insymbolic-ref,show-ref,for-each-ref,checkout --track,merge,branch -f) or only appear in messages.README is not changed: the documented behavior ("Branches tracking a remote that can't be fetched are skipped with a warning") still holds, and this only adds an error for names no normal setup has.
Testing
TestRunRejectsDashRemoteNames: main remote given with--remote, main remote chosen automatically, and a remote tracked by a branch. The--remoteand tracked-remote cases were seen to reach git (which tried to run the named command) before the fix.mise run testandmise run lintpass locally on Linux with git 2.34.1. Windows and macOS were not run locally; CI covers them.--upload-pack=<script that writes a marker file>: the binary built frommainran the script both with--remote=<name>and when a branch tracked that remote; the binary from this branch did not run it in either case and printed the messages above.🤖 Generated with Claude Code