Skip to content

fix(server): stop clone URLs being parsed as git options - #8121

Open
Lucenx9 wants to merge 1 commit into
pingdotgg:mainfrom
Lucenx9:fix/git-clone-option-injection
Open

fix(server): stop clone URLs being parsed as git options#8121
Lucenx9 wants to merge 1 commit into
pingdotgg:mainfrom
Lucenx9:fix/git-clone-option-injection

Conversation

@Lucenx9

@Lucenx9 Lucenx9 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

User-provided clone URLs were passed to git clone before an end-of-options marker. A URL beginning with - could therefore be parsed as a Git option instead of a repository value.

Add -- before the remote URL and destination so both remain positional arguments, and add focused regression coverage for normal and dash-prefixed clone inputs.

Tests:

  • vp test run apps/server/src/sourceControl/SourceControlRepositoryService.test.ts
  • vp run --filter t3 typecheck
  • Targeted lint and format checks for both changed files

Model: openai/gpt-5.6-sol via OpenCode


Note

Medium Risk
Changes how clone commands are built for untrusted URLs; scope is narrow but touches security-sensitive shell/git invocation.

Overview
Fixes a command-injection class issue where user-supplied clone URLs passed directly to git clone could be interpreted as Git flags when they start with - (e.g. --upload-pack=...).

cloneRepository now inserts Git’s end-of-options marker (--) before the remote URL and destination directory name so both are always treated as positional arguments. Existing clone expectations were updated, and a regression test asserts dash-prefixed URLs are forwarded safely.

Reviewed by Cursor Bugbot for commit 368ecef. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Pass -- before clone URL and directory in SourceControlRepositoryService.cloneRepository

Inserts an end-of-options marker (--) into the git clone args in SourceControlRepositoryService.ts so dash-prefixed remoteUrl or directoryName values are treated as positional arguments instead of git options. Adds a test for dash-prefixed remote URLs and updates an existing test to assert the new args.

Macroscope summarized 368ecef.

Summary by CodeRabbit

  • Bug Fixes
    • Improved repository cloning reliability for remote URLs and destination paths that begin with a dash.
    • Prevented option-like values from being misinterpreted as command-line flags.
    • Added regression coverage to verify these URLs are preserved correctly during cloning.

Copilot AI lite review requested due to automatic review settings August 24, 2026 18:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c2ff4851-7915-4e82-847d-e8a8045c1829

📥 Commits

Reviewing files that changed from the base of the PR and between f035a0f and 368ecef.

📒 Files selected for processing (2)
  • apps/server/src/sourceControl/SourceControlRepositoryService.test.ts
  • apps/server/src/sourceControl/SourceControlRepositoryService.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

cloneRepository now passes -- before the remote URL and destination. Tests verify standard and option-like URLs use the updated Git argument order.

Changes

Clone argument safety

Layer / File(s) Summary
Clone command argument boundary
apps/server/src/sourceControl/SourceControlRepositoryService.ts, apps/server/src/sourceControl/SourceControlRepositoryService.test.ts
cloneRepository inserts -- before the remote URL and destination. Tests verify the argument order, working directory, destination, and preservation of an option-like URL.

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

Merge Risk: ⚪ Minimal · up to 368ec

The change ensures clone URLs and destination names are treated as positional Git arguments, preventing dash-prefixed inputs from being parsed as options. Its scope is localized and covered by regression tests, so no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: juliusmarminge

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the fix to prevent clone URLs from being parsed as Git options.
Description check ✅ Passed The description explains the problem, solution, regression tests, and validation checks, and the focused scope matches the template.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files.
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 unit tests (beta)
  • Create PR with unit tests

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.

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Aug 24, 2026
@Lucenx9

Lucenx9 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@macroscopeapp

macroscopeapp Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — The production change modifies how untrusted clone URLs and destination names are passed to Git, addressing a security-sensitive option-parsing path. The scope is narrow and regression coverage is included, but the command-invocation security implications warrant additional scrutiny.

You can add or adjust custom eligibility rules. Learn more.

@Lucenx9

Lucenx9 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

Review: correct ✅

The -- end-of-options marker is the right fix here. Both remoteUrl and preparedDestination.directoryName sit after the marker, so dash-prefixed values are always treated as positional arguments by git. Covering directoryName matters too — it's derived from the user-supplied destinationPath, which was equally injectable. Since args are spawned execFile-style (no shell), -- fully closes the option-injection vector.

Verified:

  • Normal URLs are unaffected (-- is a no-op for them) — existing test updated accordingly.
  • The new regression test asserts the exact args array at the right seam (mocked GitVcsDriver), consistent with the file's existing test pattern.
  • Ran vp test run apps/server/src/sourceControl/SourceControlRepositoryService.test.ts — 8/8 pass.

The PR's tests mock GitVcsDriver, so they prove the args are built correctly but never exercise a real git binary. Filling that gap locally (git 2.55):

  • git clone -- "$PWD/src.git" dest → succeeds, -- is a no-op for normal URLs ✅
  • git clone -- "--upload-pack=touch /tmp/pwned" destfatal: repository '--upload-pack=touch /tmp/pwned' does not exist, exit 128, /tmp/pwned not created — the value stays positional and fails safely ✅
  • Control without --: git clone "--upload-pack=..." dest shifts the positional slots (dest is reported as the repository), confirming the option-injection class was real pre-fix ✅

One minor caveat: -- as end-of-options requires git ≥ 2.24 (Nov 2019). The repo pins no minimum git version, but a ~6-year floor is fine in practice — not worth blocking.

Findings (non-blocking, same class elsewhere):

  1. GitHubCli.ts#L418["repo", "view", input.repository, ...] passes the user-supplied repository string positionally to gh with no -- guard. A value starting with - hits the same option-parsing issue in the gh CLI. Worth a follow-up.
  2. GitVcsDriverCore.ensureRemote (remote add <name> <url>) has the same shape, though the URL there is provider-derived rather than raw user input, so the risk is lower.

Neither blocks this PR — the fix is narrow, correct, and tested. Safe to merge.


Model: glm-5.3 · Harness: Pi Agent

@Lucenx9

Lucenx9 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 368ecef240

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants