open-code-review icon indicating copy to clipboard operation
open-code-review copied to clipboard

Git option injection via unvalidated --from/--to/--commit refs (arbitrary file write / RCE)

Open Aravindargutus opened this issue 5 months ago • 2 comments

OpenCodeReview Version

v1.3.4

Operating System

macOS (Apple Silicon)

Installation Method

npm (global)

LLM Provider

Anthropic (Claude)

Bug Description

Bug description

Ref values supplied via --from, --to, and --commit are passed as bare positional arguments to git subcommands without any --/--end-of-options guard separating them from option flags. A ref value beginning with - is therefore interpreted by git as an option rather than a revision, and several of those options have dangerous side effects:

  • git diff --output=<file> … → arbitrary file overwrite
  • git grep -O<cmd> / --open-files-in-pager=<cmd> → arbitrary command execution

Affected call sites:

  • internal/diff/git.go:118 — git diff … <base> <p.to> "--" (p.to before --)
  • internal/diff/git.go:125 — git show … <p.commit> (no --)
  • internal/diff/git.go:260 — git merge-base <from> <to> (no --)
  • internal/tool/filereader.go:130,216 — git show <Ref>:<path> (Ref concatenated raw)
  • internal/tool/code_search.go:70 — <ref> appended into git grep before --
  • internal/tool/file_find.go:75 — git ls-tree -r --name-only <ref>

The values are never validated as refs before reaching git (git's own ref-naming rules forbid a leading -, but these raw strings bypass that check).

Steps to Reproduce

Steps to reproduce

  1. In any git repo: ocr review --commit '--output=/tmp/ocr_pwn' → /tmp/ocr_pwn is created/overwritten with git diff output.
  2. (RCE path) drive a review in range/commit mode where the ref equals --open-files-in-pager=...; the code_search tool's git grep invocation launches the supplied program once a match exists.

Expected Behavior

Expected behaviour

A ref value that is not a valid git revision — in particular one that begins with - — must be rejected before any git invocation, and refs must be passed to git in a way that cannot be reinterpreted as command-line options. No --from/--to/ --commit value should be able to cause git to write files or execute commands.

Actual behaviour

ocr review --commit '--output=/path/to/file' (or --to, --from) reaches git diff/show and writes the diff to an attacker-chosen path; a ref such as --open-files-in-pager=<cmd> reaching the git grep path in code_search can execute an arbitrary command. The shipped GitHub Action avoids this only because it happens to use head.sha and an origin/ prefix; any other automation that forwards an untrusted branch/commit name to these flags is exploitable.

Logs / Error Output


Additional Context

Suggested fix

  • Validate every non-empty --from/--to/--commit value at ingestion: reject any value starting with - and confirm it resolves (git rev-parse --verify --end-of-options <ref>^{commit}).
  • Defense in depth: insert --end-of-options immediately before ref arguments in the diff/show/merge-base calls.

Aravindargutus avatar Jun 12 '26 16:06 Aravindargutus

We confirmed the git option-injection issue.

--output=<file> is reachable through the current ocr review --commit flow and can write an attacker-chosen file. We also confirmed that git grep --open-files-in-pager=<cmd> is a real RCE sink in the code_search path, but we have not found a stable end-to-end RCE path through the current ocr review flow because the malicious ref fails earlier during diff loading.

MuoDoo avatar Jun 12 '26 17:06 MuoDoo

Hi @Aravindargutus,

Thank you for discovering and reporting this critical RCE vulnerability. Your proof-of-concept with the -O<path> flag injection via git grep was particularly insightful.

This has been fixed in v1.3.5 (PR #112). The fix includes:

  • Rejecting any --commit/--from/--to value starting with - at the CLI entry point
  • Adding --end-of-options guards before user-supplied refs in all git command call sites (git show, git diff, git grep, git ls-tree, git log, git merge-base)
  • Validating refs via git rev-parse --verify before use

All users will receive the fix automatically on their next use via npm.

Thanks again for helping make OpenCodeReview more secure!

lizhengfeng101 avatar Jun 13 '26 03:06 lizhengfeng101