Summary
Gogs has a Protected Branch Deletion Bypass in Web Interface
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):
func DeleteBranchPost(c *context.Context) {
branchName := c.Params("*")
commitID := c.Query("commit")
defer func() {
redirectTo := c.Query("redirect_to")
if !tool.IsSameSiteURLPath(redirectTo) {
redirectTo = c.Repo.RepoLink
}
c.Redirect(redirectTo)
}()
if !c.Repo.GitRepo.HasBranch(branchName) {
return
}
if len(commitID) > 0 {
branchCommitID, err := c.Repo.GitRepo.BranchCommitID(branchName)
if err != nil {
log.Error("Failed to get commit ID of branch %q: %v", branchName, err)
return
}
if branchCommitID != commitID {
c.Flash.Error(c.Tr("repo.pulls.delete_branch_has_new_commits"))
return
}
}
// 🔴 Vulnerability: Missing protected branch check here
// Should add check like:
// protectBranch, err := database.GetProtectBranchOfRepoByName(c.Repo.Repository.ID, branchName)
// if protectBranch != nil && protectBranch.Protected { ... }
if err := c.Repo.GitRepo.DeleteBranch(branchName, git.DeleteBranchOptions{
Force: true,
}); err != nil {
log.Error("Failed to delete branch %q: %v", branchName, err)
return
}
if err := database.PrepareWebhooks(c.Repo.Repository, database.HookEventTypeDelete, &api.DeletePayload{
Ref: branchName,
RefType: "branch",
PusherType: api.PUSHER_TYPE_USER,
Repo: c.Repo.Repository.APIFormatLegacy(nil),
Sender: c.User.APIFormat(),
}); err != nil {
log.Error("Failed to prepare webhooks for %q: %v", database.HookEventTypeDelete, err)
return
}
}
Correct implementation in Git Hook (internal/cmd/hook.go:122-125):
// check and deletion
if newCommitID == git.EmptyID {
fail(fmt.Sprintf("Branch '%s' is protected from deletion", branchName), "")
}
Correct UI layer check (internal/route/repo/issue.go:646-658):
protectBranch, err := database.GetProtectBranchOfRepoByName(pull.BaseRepoID, pull.HeadBranch)
if err != nil {
if !database.IsErrBranchNotExist(err) {
c.Error(err, "get protect branch of repository by name")
return
}
} else {
branchProtected = protectBranch.Protected
}
c.Data["IsPullBranchDeletable"] = pull.BaseRepoID == pull.HeadRepoID &&
c.Repo.IsWriter() && c.Repo.GitRepo.HasBranch(pull.HeadBranch) &&
!branchProtected // UI layer has check, but backend doesn't
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
# Directly send DELETE request bypassing UI protection
curl -X POST \
-b cookies.txt \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "_csrf=YOUR_CSRF_TOKEN" \
"https://gogs.example.com/username/repo/branches/delete/main"
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
The application does not correctly enforce access controls, allowing a principal to access resources or operations beyond their granted permissions. Typical impact: unauthorized data access or execution of privileged operations.
Affected versions
Security releases
Kodem intelligence
Severity tells you how bad this could be in the worst case. It does not tell you whether you are exposed. Exploitability and impact are functions of runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A vulnerable package can sit in your dependency tree and never run.
Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter. Kodem's runtime-powered SCA identifies whether this CVE is reachable in your applications.
Already deployed Kodem?
See it in your environmentNew to Kodem? Get a demo →Remediation advice
Kodem Kai can prioritize this vulnerability in your dependency tree and generate a fix recommendation.
Frequently Asked Questions
- What is CVE-2026-25232? CVE-2026-25232 is a high-severity incorrect authorization vulnerability in gogs.io/gogs (go), affecting versions < 0.14.1. It is fixed in 0.14.1. The application does not correctly enforce access controls, allowing a principal to access resources or operations beyond their granted permissions.
- Which versions of gogs.io/gogs are affected by CVE-2026-25232? gogs.io/gogs (go) versions < 0.14.1 is affected.
- Is there a fix for CVE-2026-25232? Yes. CVE-2026-25232 is fixed in 0.14.1. Upgrade to this version or later.
- Is CVE-2026-25232 exploitable, and should I be worried? Whether CVE-2026-25232 is exploitable in your environment depends on whether the vulnerable code is present and reachable. A CVSS score is a worst-case rating; it does not account for your specific deployment, configuration, or usage patterns. Kodem, an Intelligent Application Security platform, uses runtime intelligence to show which vulnerabilities actually execute in production, so you can focus on the ones that represent real risk. Get a demo
- What actually determines whether CVE-2026-25232 is exploitable, and how bad it is? Exploitability and impact are not fixed properties of a CVE. They depend on runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A high CVSS score on a dependency that never runs is not the same as real risk. Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter.
- How do I fix CVE-2026-25232? Upgrade
gogs.io/gogsto 0.14.1 or later.