Skip to content

fix: reject unmatched quotes in matchGitArgs to prevent flag injection - #760

Merged
EndBug merged 2 commits into
mainfrom
cursor/c23c747f
Aug 8, 2026
Merged

fix: reject unmatched quotes in matchGitArgs to prevent flag injection#760
EndBug merged 2 commits into
mainfrom
cursor/c23c747f

Conversation

@EndBug

@EndBug EndBug commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • Reject unmatched ' / " in matchGitArgs before string-argv parsing so values like fix'--force cannot inject --force into custom push/fetch/pull/tag/tag_push/commit args
  • Add regression tests for the quote-injection PoC and balanced quoting
  • Document the rejection and warn against interpolating untrusted refs into custom git-arg strings

Test plan

  • npm test (includes new matchGitArgs quote cases)
  • Confirm origin fix'--force --set-upstream throws unmatched-quote error
  • Confirm balanced quotes still parse (e.g. origin a'b'c --set-upstream, --longOption 'hello world')
  • Confirm commit message with apostrophes (e.g. Let's go) is unaffected
  • Confirm rebuilt lib/ matches source

Made with Cursor

Summary by CodeRabbit

  • Bug Fixes

    • Improved Git argument parsing by rejecting inputs with unmatched single or double quotes.
    • Preserved support for balanced quotes, including quoted values containing spaces and embedded quote characters.
    • Helps prevent malformed or potentially unsafe command-line arguments from being processed.
  • Documentation

    • Updated guidance on sanitizing untrusted Git values and avoiding flag injection risks.
    • Added recommendations to use trusted, static branch names in force-push examples.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@EndBug, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 15 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1018b387-5491-4978-978f-36212fbc1308

📥 Commits

Reviewing files that changed from the base of the PR and between 4e74267 and 1b82cf0.

📒 Files selected for processing (4)
  • README.md
  • lib/index.js
  • src/util.ts
  • test/util.test.ts
📝 Walkthrough

Walkthrough

matchGitArgs now rejects unmatched quotes before parsing while preserving balanced quoted arguments. The README documents sanitization requirements and trusted branch names. Tests cover both rejection and successful parsing.

Changes

Git argument safety

Layer / File(s) Summary
Quote validation and parsing tests
src/util.ts, test/util.test.ts
matchGitArgs validates single- and double-quote balance before parsing. Tests cover unmatched quotes and balanced quoted arguments.
Safe Git argument usage guidance
README.md
The README documents quote rejection, sanitization of untrusted values, and trusted branch names for force-push examples.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main change: rejecting unmatched quotes in matchGitArgs to prevent flag injection.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch cursor/c23c747f
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/c23c747f

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@EndBug
EndBug marked this pull request as ready for review August 8, 2026 21:58
Co-authored-by: Cursor <cursoragent@cursor.com>
@EndBug
EndBug merged commit 75038f8 into main Aug 8, 2026
11 checks passed
@EndBug
EndBug deleted the cursor/c23c747f branch August 8, 2026 22:07
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.

1 participant