Summary
Gogs exposes several repository management API endpoints that incorrectly allow write-level collaborators to perform admin-only actions such as disabling the issue tracker or wiki, changing external URLs, or triggering mirror sync operations.
When collaborators can directly call these misgated APIs, they may redirect repository visitors or manipulate project metadata beyond their intended privileges.
Affected context
This vulnerability occurs in Gogs deployments where:
- API endpoints for repository configuration rely on weaker access checks than the corresponding web UI actions.
- reqRepoWriter() is used to gate operations that semantically require repository admin privileges.
- Collaborators with write-level access can interact with the REST API directly, independent of UI restrictions.
It primarily affects configuration actions on issue trackers, wikis, and mirror synchronization for individual repositories.
Exploit preconditions
- Attack surface: Gogs HTTP API endpoints for repository management.
- Required access: Valid authenticated account with write-level collaborator access to a target repository (AccessModeWrite).
- Trigger point: Direct invocation of:
- PATCH /api/v1/repos/:owner/:repo/issue-tracker
- PATCH /api/v1/repos/:owner/:repo/wiki
- POST /api/v1/repos/:owner/:repo/mirror-sync
- Why exploitation is possible: These endpoints are gated by reqRepoWriter() instead of reqRepoAdmin(), allowing users who are not repository admins to perform operations that should require AccessModeAdmin.
Why this happens
The underlying issue is a mismatch between intended authorization semantics and the implementation of access checks on API endpoints.
While the web UI correctly protects sensitive repository administration actions behind reqRepoAdmin(), the corresponding API routes were wired to reqRepoWriter(), effectively broadening who can invoke them.
This maps to CWE-269 (Improper Privilege Management) and CWE-863 (Incorrect Authorization) because the system fails to enforce the proper privilege level and uses inconsistent authorization logic across different interfaces.
Potential impact
- Collaborators may disable the native issue tracker for a repository without admin approval.
- Collaborators may disable the built-in wiki or alter its configuration unexpectedly.
- Collaborators can inject attacker-controlled external issue tracker or wiki URLs that redirect repository visitors to malicious or misleading sites.
- Collaborators can trigger mirror synchronization operations, potentially affecting downstream mirrored repositories.
- Project governance and workflow controls can be undermined when non-admin users gain effective control over key repository features.
General mitigation guidance
Effective mitigation focuses on enforcing consistent, least-privilege authorization across all interfaces:
- Align API endpoint guards with the same access checks used by the web UI for equivalent operations, ensuring configuration changes require repository admin privileges.
- Define clear authorization policies for repository roles and use role-based checks rather than ad hoc mode comparisons.
- Centralize privilege checks in shared helpers so that changes to authorization semantics propagate uniformly to UI and API routes.
- Regularly review repository management actions to confirm they are protected by the strongest appropriate access mode and avoid privilege creep.
- Consider defense-in-depth measures such as administrative confirmation workflows for high-impact configuration changes.
How teams detect issues like this
Detection typically involves:
- Static analysis or code-level audits to locate API handlers performing sensitive operations gated by weaker access checks (e.g., writer vs admin).
- Comparing authorization middleware usage between web UI routes and corresponding API endpoints to find inconsistencies in role enforcement.
- Implementing policy-based tests that assert only admin-level users can perform specific configuration changes, run as part of CI.
- Monitoring logs for unusual configuration changes initiated by non-admin accounts, such as issue tracker or wiki settings toggled by collaborators.
- Employing automated code review tools that flag authorization patterns deviating from established security guidelines.

