Reject git refs that begin with a dash#116
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Git.extractProtospassed the caller-suppliedrefstraight into git's option position:Because
refsits before--, a ref that looks like a flag is parsed bygit archiveas an option, not a tree-ish:--output=/path/x.tarwrites 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-optionsmarker 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 returnsLeftand does not create the target file. The existing extract/missing-ref tests still pass.