security: harden RevParse and pass --end-of-options across git commands#142
Merged
Conversation
A revision that starts with a dash is interpreted by "git rev-parse" as a command-line option rather than an object, allowing an authenticated user to inject options such as "--absolute-git-dir" through parameters meant for commit SHAs or branch references and leak internal server details to the error logs. The "--end-of-options" separator does not help here because "git rev-parse" does not honor it for revisions, so reject such input outright. RevParse is the single funnel for user-controlled revisions (CatFileCommit, blobs, trees, submodules), so the guard closes the whole class at one place.
Bring the master branch up to parity with v2 by adding the "--end-of-options" separator to the remaining commands that accept it: checkout, reset, fetch, pull, commit, count-objects, fsck, for-each-ref, ls-tree, remote, tag, archive, show (blob), receive-pack, upload-pack, and update-server-info. This hardens them against argument injection as a defense-in-depth measure.
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.
Two changes:
RevParse guard (the fix). A revision that starts with a dash is interpreted by
git rev-parseas a command-line option rather than an object, allowing an authenticated caller to inject git options through parameters meant for commit SHAs or branch references.--end-of-optionsdoes not help here becausegit rev-parsedoes not honor it for revisions, so this rejects such input outright.RevParseis the single funnel for user-controlled revisions (CatFileCommit, blobs, trees, submodules), so the guard closes the whole class at one place.Parity hardening (defense-in-depth). Bring master up to parity with the
v2branch by adding the--end-of-optionsseparator to the remaining commands that accept it: checkout, reset, fetch, pull, commit, count-objects, fsck, for-each-ref, ls-tree, remote, tag, archive, show (blob), receive-pack, upload-pack, and update-server-info.The v2 counterpart of the guard is #143.
Refs GHSA-mxrh-2rxr-6mqc.