Skip to content

security: pass --end-of-options to git diff in DiffBinary#141

Merged
unknwon merged 1 commit into
masterfrom
security/diffbinary-end-of-options
Jul 16, 2026
Merged

security: pass --end-of-options to git diff in DiffBinary#141
unknwon merged 1 commit into
masterfrom
security/diffbinary-end-of-options

Conversation

@unknwon

@unknwon unknwon commented Jul 16, 2026

Copy link
Copy Markdown
Member

DiffBinary passes the base and head revisions positionally to git 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=/path makes 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-options before 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 --binary accepts --end-of-options (unlike git 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.

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.
@unknwon unknwon force-pushed the security/diffbinary-end-of-options branch from 9eae348 to 7f5be6e Compare July 16, 2026 02:58
@unknwon unknwon merged commit 5429319 into master Jul 16, 2026
4 checks passed
@unknwon unknwon deleted the security/diffbinary-end-of-options branch July 16, 2026 03:00
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