Prevent argument injection in git CLI calls#446
Merged
Conversation
Entire-Checkpoint: ac699460bd01
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a security vulnerability by preventing argument injection in two git CLI wrapper functions. When refs or commit hashes starting with - were passed to git checkout or git reset --hard, they could be interpreted as git flags rather than arguments, leading to unintended behavior (e.g., creating branches, silently resetting to HEAD).
Changes:
- Added input validation to reject refs/hashes starting with
-inCheckoutBranch()andperformGitResetHard() - Added comprehensive tests demonstrating both attack vectors and validating the fixes
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| cmd/entire/cli/git_operations.go | Added dash-prefix validation to CheckoutBranch() to prevent argument injection attacks |
| cmd/entire/cli/rewind.go | Added dash-prefix validation to performGitResetHard() to prevent argument injection attacks |
| cmd/entire/cli/resume_test.go | Added security tests validating that both functions reject dash-prefixed inputs, plus imported strings package |
evisdren
reviewed
Feb 20, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
cmd/entire/cli/resume_test.go:177
- The test case
CheckoutBranch("-b evil")likely doesn’t reproduce the described argument-injection behavior becauseexec.CommandContextpasses the entire string as a single argv element (it won’t split on spaces). Git option parsing typically requires-band the branch name as separate args (or a single arg form like-B<name>/--orphan=<name>). As written, this test may have already failed even before the fix, so it may not actually prove the vulnerability. Consider changing the injected ref to a single-argument option form that Git will accept (e.g., a long option with=or a short option with an attached value) and assert it would have changed repo state without the new validation.
t.Run("rejects ref starting with dash to prevent argument injection", func(t *testing.T) {
// "git checkout -b evil" would create a new branch named "evil" instead
// of failing, because git interprets "-b" as a flag.
err := CheckoutBranch("-b evil")
if err == nil {
t.Fatal("CheckoutBranch() should reject refs starting with '-', got nil")
}
if !strings.Contains(err.Error(), "invalid ref") {
t.Errorf("CheckoutBranch() error = %q, want error containing 'invalid ref'", err.Error())
}
Soph
approved these changes
Feb 23, 2026
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.
Entire-Checkpoint: ac699460bd01
branch, git reset --hard -q silently resets to HEAD).
Test plan