Git option injection via unvalidated --from/--to/--commit refs (arbitrary file write / RCE)
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 overwritegit 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 intogit grepbefore--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
- In any git repo:
ocr review --commit '--output=/tmp/ocr_pwn'→/tmp/ocr_pwnis created/overwritten with git diff output. - (RCE path) drive a review in range/commit mode where the ref equals
--open-files-in-pager=...; thecode_searchtool'sgit grepinvocation 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/--commitvalue 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-optionsimmediately before ref arguments in thediff/show/merge-basecalls.
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.
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/--tovalue starting with-at the CLI entry point - Adding
--end-of-optionsguards 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 --verifybefore use
All users will receive the fix automatically on their next use via npm.
Thanks again for helping make OpenCodeReview more secure!