security: pass --end-of-options to git diff in DiffBinary#141
Merged
Conversation
A base or head revision that begins with a dash was passed positionally to "git diff --full-index --binary", so git could interpret it as a command-line option. A revision such as "--output=/path" made git write the diff to an arbitrary path, an attacker-controlled file write when the revision came from a user-supplied branch name.
9eae348 to
7f5be6e
Compare
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.
DiffBinarypasses thebaseandheadrevisions positionally togit diff --full-index --binary. When a revision begins with a dash, git can interpret it as a command-line option instead of a revision. A value such as--output=/pathmakes git write the diff to an arbitrary path, which is an attacker-controlled file write when the revision originates from a user-supplied branch name.This inserts
--end-of-optionsbefore the positional revisions so such a value is always treated as a revision, which then fails to resolve rather than changing the command's behavior.I verified against git 2.50 that
git diff --full-index --binaryaccepts--end-of-options(unlikegit reset, see #134) and that the marker turns the injection into a fatal "must come before non-option arguments" error with no file written. Added a regression test.Relates to gogs/gogs security advisory GHSA-2grc-qr7q-6m36.