Summary
Gitea did not limit repeated incorrect TOTP passcodes during sign-in, password reset, or Basic authentication using the X-Gitea-OTP header. Someone who already knows an account's password could make high-rate guesses at its six-digit code and potentially sign in without completing the intended two-factor check.
Affected context
The issue occurs in Gitea authentication flows that accept TOTP codes, including sign-in, password reset, and Basic authentication with the X-Gitea-OTP header. It becomes risky when failed codes can be submitted repeatedly without effective per-account throttling and an attacker has already obtained the account password. The described behavior is to refuse further attempts for an account for 15 minutes after five failed passcodes.
Exploit preconditions
- Attack surface: Gitea authentication endpoints that accept TOTP passcodes.
- Required access: Knowledge of the target account's password; valid TOTP access is not required.
- Trigger point: Repeated submission of incorrect six-digit codes during sign-in, password reset, or Basic authentication.
- Why exploitation is possible: Without effective attempt limits, an attacker can test passcodes at a high rate, increasing the chance of guessing a valid code.
Why this happens
The authentication flows permitted repeated verification attempts without sufficient throttling. This is an authentication rate-limiting weakness mapped to CWE-307: Improper Restriction of Excessive Authentication Attempts. When an authentication factor can be guessed repeatedly, two-factor verification provides less protection against someone who already knows the password.
Potential impact
- An attacker could gain access to an account after learning its password and guessing its TOTP passcode.
- Two-factor authentication may be bypassed for affected authentication flows.
- Compromised accounts could expose data or allow unauthorized actions, depending on account privileges.
General mitigation guidance
Defensive patterns include limiting failed authentication attempts across all flows that accept the same factor, applying per-account cooldowns, and using risk-aware controls to slow automated guessing. Keep authentication state and attempt counters consistent across sign-in, password reset, and Basic authentication paths. Avoid relying solely on source-address limits, since requests may come from multiple addresses, and protect counters against reset or evasion. Apply least privilege to accounts and provide clear, secure recovery paths for users affected by throttling.
How teams detect issues like this
Review authentication handlers for missing or inconsistent attempt limits, especially where multiple endpoints validate the same TOTP factor. Monitor for repeated failed TOTP checks against an account, rapid attempts across many accounts, and unusual use of the X-Gitea-OTP header. Static analysis and code review can check that all authentication paths invoke shared throttling and lockout policy. Policy enforcement can require rate limits and audit events for failed multi-factor checks.

