Skip to content

security: fix argument injection in pull request merge (rebase) - #8301

Merged
unknwon merged 3 commits into
gogs:mainfrom
jburgess-r7:fix/merge-argument-injection
Jun 6, 2026
Merged

unknwon merged 3 commits into
gogs:mainfrom
jburgess-r7:fix/merge-argument-injection

Conversation

@jburgess-r7

@jburgess-r7 jburgess-r7 commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

Branch names starting with -- (e.g. --exec=<cmd>) are passed unsanitized to git rebase in Merge(), allowing argument injection. Since git rebase --exec runs commands via sh -c, this is an RCE for any user who can create a pull request with rebase merging enabled.

This patch rejects branch names starting with - at the top of Merge(), and adds --end-of-options to the git rebase invocation as defense-in-depth (consistent with how git-module v1.8.7 already handles Clone, Push, Fetch, etc).

Ref: GHSA-qf6p-p7ww-cwr9

@jburgess-r7
jburgess-r7 requested a review from unknwon as a code owner May 29, 2026 07:35
@pcastelovigo

Copy link
Copy Markdown

Please can OP merge this??

Crypto-Cat and others added 2 commits June 5, 2026 22:28
Reject branch names starting with a hyphen in Merge() to prevent argument
injection into git commands. A malicious branch name like '--exec=<cmd>'
would be interpreted as a flag by git rebase, resulting in arbitrary command
execution on the server.

Additionally, add '--end-of-options' to the git rebase invocation as
defense-in-depth, consistent with the existing use of '--end-of-options'
in the git-module library (Clone, Push, Fetch, etc).

Ref: GHSA-qf6p-p7ww-cwr9
@unknwon
unknwon force-pushed the fix/merge-argument-injection branch from 46e1137 to c66ec87 Compare June 6, 2026 02:30

@unknwon unknwon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@unknwon
unknwon merged commit a9dbafb into gogs:main Jun 6, 2026
7 checks passed
@unknwon unknwon added this to the 0.14.3 milestone Jun 6, 2026
unknwon added a commit that referenced this pull request Jun 7, 2026
Co-authored-by: Jonah Burgess <[email protected]>
Co-authored-by: Joe Chen <[email protected]>
(cherry picked from commit a9dbafb)
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.

4 participants