Описание
Gogs has a Protected Branch Deletion Bypass in Web Interface
Summary
An access control bypass vulnerability in Gogs web interface allows any repository collaborator with Write permissions to delete protected branches (including the default branch) by sending a direct POST request, completely bypassing the branch protection mechanism. This vulnerability enables privilege escalation from Write to Admin level, allowing low-privilege users to perform dangerous operations that should be restricted to administrators only.
Although Git Hook layer correctly prevents protected branch deletion via SSH push, the web interface deletion operation does not trigger Git Hooks, resulting in complete bypass of protection mechanisms.
Details
Affected Component
- File:
internal/route/repo/branch.go - Function:
DeleteBranchPost(lines 110-155) - Route Configuration:
internal/cmd/web.go:589m.Post("/delete/*", reqSignIn, reqRepoWriter, repo.DeleteBranchPost)
Root Cause
The DeleteBranchPost function performs the following checks when deleting a branch:
- ✅ User authentication (
reqSignIn) - ✅ Write permission check (
reqRepoWriter) - ✅ Branch existence verification
- ✅ CommitID matching (optional parameter)
- ❌ Missing protected branch check
- ❌ Missing default branch check
While the UI layer (internal/route/repo/issue.go:646-658) correctly checks protected branch status and hides the delete button, attackers can directly construct POST requests to bypass UI restrictions.
Vulnerable Code
Vulnerable implementation (internal/route/repo/branch.go:110-155):
Correct implementation in Git Hook (internal/cmd/hook.go:122-125):
Correct UI layer check (internal/route/repo/issue.go:646-658):
PoC
Prerequisites
- Have Write permissions to the target repository (collaborator or team member)
- Target repository has protected branches configured (e.g., main, master, develop)
- Access to Gogs web interface
Send Malicious POST Request
Impact
- Bypass branch protection mechanism: The core function of protected branches is to prevent deletion, and this vulnerability completely undermines this mechanism
- Delete default branch: Can cause repository to become inaccessible (git clone/pull failures)
- Bypass code review: After deleting protected branch, can push new branch bypassing Pull Request requirements
- Privilege escalation: Writer permission users can perform operations that should only be allowed for Admins
Пакеты
gogs.io/gogs
< 0.14.1
0.14.1
Связанные уязвимости
Gogs is an open source self-hosted Git service. Versions 0.13.4 and below have an access control bypass vulnerability which allows any repository collaborator with Write permissions to delete protected branches (including the default branch) by sending a direct POST request, completely bypassing the branch protection mechanism. This vulnerability in the DeleteBranchPost function eenables privilege escalation from Write to Admin level, allowing low-privilege users to perform dangerous operations that should be restricted to administrators only. Although Git Hook layer correctly prevents protected branch deletion via SSH push, the web interface deletion operation does not trigger Git Hooks, resulting in complete bypass of protection mechanisms. In oder to exploit this vulnerability, attackers must have write permissions to the target repository, protected branches configured to the target repository and access to the Gogs web interface. This issue has been fixed in version 0.14.1.