Get a Demo

Let's Patch It!

Book a short call with one our specialists, we'll walk you through how Endor Patches work, and ask you a few questions about your environment (like your primary programming languages and repository management). We'll also send you an email right after you fill out the form, feel free to reply with any questions you have in advance!

CVE

CVE-2026-25232

Gogs has a Protected Branch Deletion Bypass in Web Interface
Back to all
CVE

CVE-2026-25232

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

  • Fileinternal/route/repo/branch.go
  • FunctionDeleteBranchPost (lines 110-155)
  • Route Configurationinternal/cmd/web.go:589

  ```go

  m.Post("/delete/*", reqSignIn, reqRepoWriter, repo.DeleteBranchPost)

  ```

Root Cause

The DeleteBranchPost function performs the following checks when deleting a branch:

  1. ✅ User authentication (reqSignIn)
  2. ✅ Write permission check (reqRepoWriter)
  3. ✅ Branch existence verification
  4. ✅ CommitID matching (optional parameter)
  5. ❌ Missing protected branch check
  6. ❌ 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

  1. Have Write permissions to the target repository (collaborator or team member)
  2. Target repository has protected branches configured (e.g., main, master, develop)
  3. 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"

<img width="1218" height="518" alt="image" src="https://github.com/user-attachments/assets/745da7c3-6139-408c-9747-ccbe9ea8548f" />

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

Package Versions Affected

Package Version
patch Availability
No items found.

Automatically patch vulnerabilities without upgrading

Fix Without Upgrading
Detect compatible fix
Apply safe remediation
Fix with a single pull request

CVSS Version

Severity
Base Score
CVSS Version
Score Vector
C
H
U
7.1
-
4.0
CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X
C
H
U
0
-
C
H
U
6.5
-
3.1
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H

Related Resources

No items found.

References

https://github.com/gogs/gogs/security/advisories/GHSA-2c6v-8r3v-gh6p, https://nvd.nist.gov/vuln/detail/CVE-2026-25232, https://github.com/gogs/gogs/pull/8124, https://github.com/gogs/gogs/commit/7b7e38c88007a7c482dbf31efff896185fd9b79c, https://github.com/gogs/gogs, https://github.com/gogs/gogs/releases/tag/v0.14.1

Severity

6.5

CVSS Score
0
10

Basic Information

Ecosystem
Base CVSS
6.5
EPSS Probability
0.00014%
EPSS Percentile
0.02713%
Introduced Version
0,v0.12.0,v0.0.0-20191024085146-01c8df01ec06,v0.11.29,v0.0.0-20170611043414-4400d2fdd933,v0.9.113,v0.0.0-20160902031221-73fedc727538
Fix Available
0.14.1,v0.14.0-rc.1,v0.0.0-20260131175107-7b7e38c88007

Fix Critical Vulnerabilities Instantly

Secure your app without upgrading.
Fix Without Upgrading