/

CVE-2025-64175

Severity:

HIGH RISK

(8.8)

Improper Authentication in Gogs 2FA Recovery Code Validation

CVE-2025-64175

Analyzed

Vulnerability type

Category:

Improper Authentication

CWE:

CWE-287

Impact:

Two-Factor Authentication Bypass and Account Takeover

Severity:

HIGH RISK

(8.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

Gogs versions 0.13.3 and earlier contain an authentication flaw where 2FA recovery codes are not scoped to individual users.

An attacker who already knows a victim's username and password can reuse any unused recovery code, including one from their own account, to bypass the victim's 2FA and fully take over the account.

Affected context

This vulnerability affects Gogs instances that have two-factor authentication enabled and support recovery codes as a fallback mechanism.

The issue arises in the 2FA recovery code validation logic, where the system treats recovery codes as globally valid tokens rather than associating them strictly with the user who owns them.

It becomes relevant in environments where users rely on 2FA for securing access to repositories, organizations, and administrative features in self-hosted Gogs deployments.

Exploit preconditions

  • Attack surface: Web login endpoint that handles 2FA challenges and recovery code verification.
  • Required access: The attacker must already know the victim's valid username and password (e.g., via credential stuffing, phishing, or reuse).
  • Trigger point: Submission of a valid but unused recovery code during the 2FA step for the victim's account.
  • Why exploitation is possible: The server-side logic verifies the recovery code as valid and unused but does not ensure that the code belongs to the account currently being authenticated, enabling cross-account reuse.

Why this happens

The core issue is an authentication design flaw where 2FA recovery codes are treated as generic tokens instead of being tightly bound to a specific user identity.

During the 2FA recovery flow, the implementation appears to check only whether a recovery code is valid and unused, without enforcing a constraint that the code's ownership matches the username undergoing authentication.

This maps to CWE-287: Improper Authentication, as the system fails to correctly verify the user's identity in the multi-factor step and accepts proof of possession that is not actually linked to the target account.

In abstract terms, this reflects an insecure pattern where secondary authentication factors are not scoped or keyed by user, allowing one user's factor to satisfy another user's challenge.

Potential impact

  • Full account takeover of any user whose username and password are known.
  • Effective nullification of 2FA protections for affected Gogs instances.
  • Unauthorized access to private repositories and source code.
  • Potential compromise of organizations, webhooks, and deployment pipelines tied to the compromised account.
  • Escalation to administrative control if targeted users hold admin or privileged roles.

General mitigation guidance

Effective mitigation focuses on enforcing strict binding between recovery codes and the user identity being authenticated, and strengthening MFA design:

  • Ensure that all second-factor artifacts (recovery codes, tokens, backup keys) are stored and verified in a way that is cryptographically and logically scoped to a specific user.
  • Treat recovery codes as per-user secrets: lookup and validate them only in the context of the currently authenticated username, never globally.
  • Centralize authentication logic so that all MFA checks, including recovery flows, pass through a unified component with clear guarantees about user scoping.
  • Employ defense in depth by logging and rate limiting 2FA and recovery attempts, reducing the impact of credential theft.
  • Apply least-privilege principles for high-value accounts (e.g., separate accounts for admin tasks) so that a single account compromise yields minimal blast radius.

These patterns help ensure that even if primary credentials are exposed, second factors still meaningfully constrain access.

How teams detect issues like this

Detection efforts can focus on both code-level issues and runtime anomalies:

  • Static analysis and code review:
  • Review MFA and recovery flows for database queries or lookups that do not include a user identifier when fetching or validating recovery codes.
  • Flag any authentication routines where validation of secondary factors is performed without explicit reference to the current account context.
  • Enforce architectural policies that all factor validation APIs require both a user identity and the factor value.
  • Automated checks:
  • Use application security testing tools to model authentication workflows and verify that second factors cannot be swapped across accounts.
  • Integrate unit and integration tests that simulate recovery code usage across different accounts to catch scoping regressions.
  • Operational monitoring:
  • Monitor logs for repeated successful recovery code logins following failures, especially where the recovery code usage pattern spans multiple accounts or IPs.
  • Set alerts for unusual recovery code usage rates or for backup codes being used immediately after password-based authentication from atypical locations.

These strategies make it easier to catch improper authentication patterns early in development and identify suspicious 2FA behavior in production.

Sources

SourceLink
github.comgithub.com/gogs/gogs/security/advisories/GHSA-p6x6-9mx6-26wj

Frequently asked

questions

Exploitability is high wherever attackers can obtain valid usernames and passwords, such as through credential stuffing or phishing.

Once an attacker has those credentials and access to any valid unused recovery code (for example, from their own account), bypassing the victim's 2FA is straightforward.

No direct server access is required.

The attacker needs network access to the Gogs web interface and valid username/password pairs for targets; they can then provide any unused recovery code during 2FA to bypass it.

The safest fix pattern is to enforce strict per-user scoping of all 2FA recovery codes and to validate them only in combination with the specific account identity.

Implement recovery code verification so that it always queries and invalidates codes in the context of the user currently authenticating, not across the entire system.

Prevention relies on designing authentication flows with clear ownership and scoping rules:

  • Model 2FA and recovery artifacts as user-bound secrets, never global tokens.
  • Establish code review checklists specifically for authentication and MFA logic.
  • Add automated tests for cross-account misuse of second factors.
  • Periodically perform threat modeling for login and recovery flows to ensure they resist credential theft and factor reuse attacks.
Find out what's already
exploitable in your codebase.