Skip to content

fix: prevent git option injection via new_branch - #755

Merged
EndBug merged 4 commits into
mainfrom
cursor/5a7c11b1
Aug 8, 2026
Merged

fix: prevent git option injection via new_branch#755
EndBug merged 4 commits into
mainfrom
cursor/5a7c11b1

Conversation

@EndBug

@EndBug EndBug commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • Validate new_branch early so empty values, leading hyphens (e.g. --force), and whitespace/control characters are rejected before any git calls
  • Pass the branch after -- on checkout/create/default push so git cannot treat it as an option
  • Document the branch-name constraint and cover accept/reject cases in unit tests; rebuild lib/index.js

Test plan

  • npm test passes (including assertValidBranchName cases)
  • Workflow with a normal new_branch (e.g. feature/foo) still checks out/creates and pushes as before
  • Setting new_branch: --force fails during input validation with a clear error (no force-checkout/force-push)
  • Confirm shipped lib/index.js includes the validation and -- push/checkout argv

Made with Cursor

Summary by CodeRabbit

  • New Features

    • Added validation to ensure new branch names are valid and safe before use.
    • Improved branch checkout and push handling for branch names beginning with special characters.
  • Bug Fixes

    • Prevented invalid, empty, whitespace-only, or unsafe branch names from being accepted.
    • Prevented unsupported remote-helper overrides from executing arbitrary Git transport programs.
  • Documentation

    • Updated setup documentation and input descriptions to clarify branch name requirements and remote-helper restrictions.

Validate new_branch as a branch name and pass it after -- so values like --force cannot force-checkout or force-push.

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

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d90dd5f1-5ce6-401e-80c1-77df24e29f75

📥 Commits

Reviewing files that changed from the base of the PR and between a90b370 and fa67b76.

📒 Files selected for processing (5)
  • README.md
  • action.yml
  • lib/index.js
  • src/util.ts
  • test/util.test.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • README.md
  • action.yml
  • test/util.test.ts

📝 Walkthrough

Walkthrough

The change validates new_branch values, documents the validation rules, and passes branch names safely to Git during checkout and push operations.

Changes

Branch Safety

Layer / File(s) Summary
Branch name validation contract
src/util.ts, test/util.test.ts, README.md, action.yml
assertValidBranchName rejects empty, hyphen-prefixed, whitespace-containing, control-character-containing, and invalid Git branch names. Tests and documentation cover the rules.
Input validation wiring
src/io.ts
checkInputs validates new_branch when the input is provided.
Safe checkout and push commands
src/main.ts
Checkout uses array-form arguments and git checkout -b for missing branches. Named-branch pushes use -- before the branch name. Unnamed pushes retain the structured upstream push call.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Action
  participant InputValidation
  participant Git
  participant Remote
  Action->>InputValidation: validate new_branch
  InputValidation->>Git: run git check-ref-format --branch
  Git-->>InputValidation: return validation result
  InputValidation-->>Action: accept or reject branch name
  Action->>Git: checkout or create branch
  Action->>Git: push named branch with --
  Git->>Remote: push branch
Loading
🚥 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 describes the main change: preventing Git option injection through the new_branch input.
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
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/5a7c11b1

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 19:09

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main.ts`:
- Around line 82-88: Update the checkout flow in the visible branch-handling
chain to remove the `--` separator from both branch operands: use
`git.checkout([targetBranch])` for the existing-branch path and
`git.checkout(['-b', targetBranch], log)` when creating the branch. Preserve the
surrounding success and fallback logging.

In `@src/util.ts`:
- Around line 51-57: Update the validator loop in src/util.ts lines 51-57 to
reject all contract-defined Unicode whitespace and C1 control characters, not
just ASCII values, while preserving existing rejection behavior. Add rejection
cases for \u00A0 and \u0085 in test/util.test.ts lines 72-82 to verify both
categories.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 333d4d79-dffd-4c95-a44f-8aaf5b850584

📥 Commits

Reviewing files that changed from the base of the PR and between 86ab5dc and e3fb019.

📒 Files selected for processing (7)
  • README.md
  • action.yml
  • lib/index.js
  • src/io.ts
  • src/main.ts
  • src/util.ts
  • test/util.test.ts

Comment thread src/main.ts Outdated
Comment thread src/util.ts Outdated
EndBug and others added 2 commits August 8, 2026 22:19
Reject Unicode whitespace/C1 controls in branch names, and drop the checkout -- separator after early validation.

Co-authored-by: Cursor <cursoragent@cursor.com>
Resolve conflicts by keeping new_branch validation alongside remote-helper arg blocking.

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
README.md (2)

132-132: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Implement the Git branch-name checks before documenting new_branch as a valid branch name.

assertValidBranchName() only rejects empty values, leading hyphens, and whitespace/control characters. It still accepts ref forms that Git rejects, such as feature..name, name@{x}, name~1, and name.. Use git check-ref-format --branch or reimplement the full branch-validation rules, then keep the README wording aligned with the enforced limits.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@README.md` at line 132, Update assertValidBranchName() to validate branch
names using git check-ref-format --branch or equivalent complete Git branch
rules, rejecting forms such as feature..name, name@{x}, name~1, and names ending
with a dot. After enforcement is complete, keep the README new_branch
description aligned with the actual accepted constraints.

104-105: 🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win

Use transport-neutral wording for the execution risk.

--upload-pack, --receive-pack, and --exec select the Git service path for the transport peer. They do not always run a local program; SSH transport runs the selected program remotely, while a local helper or file transport may run it locally. Change “arbitrary local program” to wording such as “an arbitrary Git transport program” or “an arbitrary program on the transport peer.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@README.md` around lines 104 - 105, Update the remote-helper override warning
in the README to replace “arbitrary local program” with transport-neutral
wording such as “an arbitrary Git transport program” or “an arbitrary program on
the transport peer,” while preserving the surrounding security guidance.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@README.md`:
- Line 132: Update assertValidBranchName() to validate branch names using git
check-ref-format --branch or equivalent complete Git branch rules, rejecting
forms such as feature..name, name@{x}, name~1, and names ending with a dot.
After enforcement is complete, keep the README new_branch description aligned
with the actual accepted constraints.
- Around line 104-105: Update the remote-helper override warning in the README
to replace “arbitrary local program” with transport-neutral wording such as “an
arbitrary Git transport program” or “an arbitrary program on the transport
peer,” while preserving the surrounding security guidance.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 654a7df6-72e0-43de-9094-c003c2fa478b

📥 Commits

Reviewing files that changed from the base of the PR and between a012262 and a90b370.

📒 Files selected for processing (4)
  • README.md
  • lib/index.js
  • src/util.ts
  • test/util.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/util.ts
  • test/util.test.ts

Reject invalid ref forms via check-ref-format --branch, align docs, and clarify the remote-helper warning wording.

Co-authored-by: Cursor <cursoragent@cursor.com>
@EndBug
EndBug merged commit b4a0134 into main Aug 8, 2026
11 checks passed
@EndBug
EndBug deleted the cursor/5a7c11b1 branch August 8, 2026 20:38
kodiakhq Bot pushed a commit to pdylanross/fatigue that referenced this pull request Aug 12, 2026
Bumps EndBug/add-and-commit from 10 to 11.

Release notes
Sourced from EndBug/add-and-commit's releases.

v11.0.0
What's Changed

chore(deps): bump picomatch by @​dependabot[bot] in EndBug/add-and-commit#724
chore(deps-dev): bump handlebars from 4.7.8 to 4.7.9 by @​dependabot[bot] in EndBug/add-and-commit#725
chore(deps): bump lodash from 4.17.23 to 4.18.1 by @​dependabot[bot] in EndBug/add-and-commit#728
chore(deps-dev): bump ts-jest from 29.4.6 to 29.4.9 by @​dependabot[bot] in EndBug/add-and-commit#727
chore(deps): bump @​actions/github from 9.0.0 to 9.1.0 by @​dependabot[bot] in EndBug/add-and-commit#729
chore(deps): bump @​actions/github from 9.1.0 to 9.1.1 by @​dependabot[bot] in EndBug/add-and-commit#732
chore(deps): bump @​actions/core from 3.0.0 to 3.0.1 by @​dependabot[bot] in EndBug/add-and-commit#733
ci(deps): bump actions/dependency-review-action from 4 to 5 by @​dependabot[bot] in EndBug/add-and-commit#734
chore(deps-dev): bump ts-jest from 29.4.9 to 29.4.11 by @​dependabot[bot] in EndBug/add-and-commit#736
chore(deps-dev): bump jest from 30.3.0 to 30.4.2 by @​dependabot[bot] in EndBug/add-and-commit#735
chore(deps-dev): bump eslint-plugin-prettier from 5.5.5 to 5.5.6 by @​dependabot[bot] in EndBug/add-and-commit#738
chore(deps): bump js-yaml from 4.1.1 to 4.2.0 by @​dependabot[bot] in EndBug/add-and-commit#739
ci(deps): bump actions/checkout from 6 to 7 by @​dependabot[bot] in EndBug/add-and-commit#741
chore(deps): bump undici from 6.24.1 to 6.27.0 by @​dependabot[bot] in EndBug/add-and-commit#744
ci(deps): bump actions/setup-node from 6 to 7 by @​dependabot[bot] in EndBug/add-and-commit#749
chore(deps-dev): bump @​vercel/ncc from 0.38.4 to 0.44.1 by @​dependabot[bot] in EndBug/add-and-commit#746
chore(deps): bump js-yaml from 4.2.0 to 5.2.1 by @​dependabot[bot] in EndBug/add-and-commit#747
chore(deps-dev): bump ts-jest from 29.4.11 to 29.4.12 by @​dependabot[bot] in EndBug/add-and-commit#750
chore(deps): bump js-yaml from 5.2.1 to 5.2.2 by @​dependabot[bot] in EndBug/add-and-commit#751
chore(deps): bump undici from 6.27.0 to 6.28.0 by @​dependabot[bot] in EndBug/add-and-commit#753
fix: reject remote-helper git flags that enable RCE by @​EndBug in EndBug/add-and-commit#754
fix: prevent git option injection via new_branch by @​EndBug in EndBug/add-and-commit#755
fix: verify committed lib/ matches source in CI by @​EndBug in EndBug/add-and-commit#756
fix: stop logging full git config (credential leak) by @​EndBug in EndBug/add-and-commit#758
fix: reject -F/--file git args that can exfiltrate runner files by @​EndBug in EndBug/add-and-commit#759
fix: reject unmatched quotes in matchGitArgs to prevent flag injection by @​EndBug in EndBug/add-and-commit#760
fix: refuse unexpected gitlinks staged by git add by @​EndBug in EndBug/add-and-commit#761
fix: do not report committed=true for empty commit SHA by @​EndBug in EndBug/add-and-commit#757
ci: pin actions-tagger and restrict release workflow permissions by @​EndBug in EndBug/add-and-commit#762
fix: neutralize bidi and control chars in action logs by @​EndBug in EndBug/add-and-commit#763

Full Changelog: EndBug/add-and-commit@v10.0.0...v11.0.0



Commits

645ecc0 11.0.0
06e788f fix: neutralize bidi and control chars in action logs (#763)
68ec86a ci: pin actions-tagger and restrict release workflow permissions (#762)
f1bb0cc fix: do not report committed=true for empty commit SHA (#757)
ebc24bf fix: refuse unexpected gitlinks staged by git add (#761)
75038f8 fix: reject unmatched quotes in matchGitArgs to prevent flag injection (#760)
d07c930 fix: reject -F/--file git args that can exfiltrate runner files (#759)
0971289 fix: stop logging full git config (credential leak) (#758)
c38a33b fix: verify committed lib/ matches source in CI (#756)
b4a0134 fix: prevent git option injection via new_branch (#755)
Additional commits viewable in compare view




Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


Dependabot commands and options

You can trigger Dependabot actions by commenting on this PR:

@dependabot rebase will rebase this PR
@dependabot recreate will recreate this PR, overwriting any edits that have been made to it
@dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency
@dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
@dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
@dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
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