Summary
Gogs versions 0.13.4 and earlier contain an access control bypass that lets users with Write permissions delete protected branches, including the default branch, via a crafted POST request to the web interface.
Because the web-based branch deletion path does not enforce branch protection rules or trigger Git hooks, collaborators can effectively escalate their privileges from Write to Admin for destructive repository operations.
Affected context
This vulnerability affects Gogs instances where:
- Protected branches (including the default branch) are configured for repositories
- Users with Write permissions are present as collaborators
- The Gogs web interface is exposed and used for repository management operations
The problem occurs specifically in the HTTP branch deletion flow, where the DeleteBranchPost handler does not fully enforce the same protection and hook logic that applies to operations performed via Git over SSH.
Exploit preconditions
- Attack surface: Gogs web application HTTP endpoint handling branch deletion (DeleteBranchPost).
- Required access: Valid authenticated user account with at least Write permissions on the target repository.
- Configuration state: Protected branches configured on the repository, including any branch intended to be non-deletable (e.g., default branch).
- Trigger point: Direct POST request to the branch deletion endpoint for a protected branch.
- Why exploitation is possible: The web-based deletion flow bypasses branch protection checks and does not invoke Git hooks, so authorization logic that would normally block deletion is never executed for this code path.
Why this happens
The root cause is an inconsistent authorization model between different code paths that perform the same sensitive action.
In the DeleteBranchPost function, the application checks that the user can write to the repository, but it fails to apply branch protection rules that are enforced elsewhere (such as via Git hooks on SSH pushes).
This mismatch maps to CWE-863: Incorrect Authorization, where access control decisions are incomplete or applied to the wrong scope, letting users perform actions that should require a higher privilege level (Admin).
Conceptually, the bug is an authorization gap: a sensitive operation (protected branch deletion) is reachable through an alternative interface that does not enforce the intended policy.
Potential impact
- Deletion of protected branches, including the default branch of critical repositories
- Effective privilege escalation from Write to Admin-level destructive capabilities within a repository
- Disruption of development workflows by removing active or release branches
- Loss of important code history if backups or mirroring are not in place
- Facilitation of malicious changes to repository state, such as removing review-enforced branches to weaken governance
General mitigation guidance
Mitigation typically focuses on enforcing consistent authorization for all paths that modify repository state and treating protected operations as privileged actions.
Helpful defensive patterns include:
- Centralizing authorization checks for branch operations so all interfaces (web, API, SSH) share the same policy logic.
- Treating branch protection as a hard policy layer that is evaluated for every branch mutation, regardless of protocol or UI flow.
- Restricting the ability to delete branches, especially default or protected branches, to a clearly defined higher-privilege role and avoiding reliance solely on per-repository write permissions.
- Designing web handlers so that any action equivalent to a Git operation reuses the same permission and hook pipelines as Git itself.
- Implementing defense-in-depth by requiring confirmation steps or additional authorization (e.g., admin-only toggles) for destructive actions on protected resources.
How teams detect issues like this
Detection can focus on both behavioral and code-centric indicators:
- Static analysis and code review:
- Look for controller or handler functions that perform sensitive operations (like branch deletion, force pushes, configuration changes) but only check generic repository write access instead of explicit branch protection rules.
- Identify duplicated authorization logic across interfaces; verify that all code paths use shared, centralized policy routines.
- Flag endpoints that bypass or fail to invoke hook and validation pipelines associated with Git operations.
- Policy and configuration checks:
- Enforce policies that map protected branch operations to stricter roles and monitor code changes that relax those rules.
- Use automated checks in CI to ensure new endpoints that manipulate branches call the same protection/authorization functions as existing, vetted paths.
- Runtime monitoring:
- Log all branch deletion events with actor identity and branch name; alert when protected branches are deleted by non-admin users.
- Periodically audit repository events for anomalies, especially deletions or force updates involving designated protected branches.

