Skip to content

Reject git refs that begin with a dash#116

Merged
ghostdogpr merged 1 commit into
mainfrom
fix/git-ref-arg-injection
Jul 9, 2026
Merged

Reject git refs that begin with a dash#116
ghostdogpr merged 1 commit into
mainfrom
fix/git-ref-arg-injection

Conversation

@ghostdogpr

Copy link
Copy Markdown
Owner

Problem

Git.extractProtos passed the caller-supplied ref straight into git's option position:

new ProcessBuilder("git", "archive", "--format=tar", ref, "--", ":(glob)**/*.proto")

Because ref sits before --, a ref that looks like a flag is parsed by git archive as an option, not a tree-ish:

  • --output=/path/x.tar writes the archive to an arbitrary file (silently overwriting it); tar then reads empty stdin and the diff proceeds against an empty tree;
  • --remote=<url> / --exec=<cmd> make git contact a remote.

Any automation that builds the ref from external input inherits this.

Fix

A legitimate git ref/tree-ish never begins with -, so reject such refs up front with a clear error before invoking git. (git archive's own --end-of-options marker can't be used here — it also neutralizes the -- path separator, breaking the pathspec.)

Test

A regression test (red before the fix): extractProtos("--output=<file>") against a real repo now returns Left and does not create the target file. The existing extract/missing-ref tests still pass.

extractProtos passed the ref straight into 'git archive --format=tar <ref>
-- ...', in git's option position. A ref such as --output=/path, --remote=url
or --exec=cmd was therefore interpreted as a git-archive option rather than a
tree-ish, letting a caller redirect the archive to an arbitrary file or reach
a remote. A legitimate git ref never starts with '-', so reject those before
invoking git.
@ghostdogpr ghostdogpr merged commit 2e389f1 into main Jul 9, 2026
3 checks passed
@ghostdogpr ghostdogpr deleted the fix/git-ref-arg-injection branch July 9, 2026 05:29
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