GITEA.DEV · CVE-2026-123002 · Runtime
FIX → 28.4.0
Gitea does not limit wrong guesses at the second-factor prompt after a correct password, so an attacker who has the password can try codes until one works. A successful guess gives a full login and the ability to turn off the victim's two-factor authentication.
first public Nov 15, 2026 · 2 sources
Check it with your coding agent
It reads this page and tells you if your code or app is affected.
Self-hosted Gitea instances up to and including 28.3.0 where at least one account has TOTP two-factor authentication enabled. An attacker needs that account's password, and the flaw sits on the web 2FA login path (POST /user/two_factor), which the advisory says is not covered by any rate limiter or CAPTCHA. Instances without two-factor accounts, or already on 28.4.0, are not exposed.
Not affected if fixed-28.4.0, no-2fa-accounts
Who cares git-hosting, gitea, go, self-hosted
28.3.0, the last affected release.Upgrade to 28.4.0
28.4.0.Affected component: Gitea v1.27.2 (tested gitea/gitea:latest), routers/web/auth/2fa.go TwoFactorPost (POST /user/two_factor), backed by TwoFactor.ValidateAndConsumeTOTP -> pquerna/otp totp.Validate (Skew=1). The scratch-code path TwoFactorScratchPost shares the missing control.
Required privileges: Valid(username + password) for a 2FA-enabled account.
Gitea lets someone who already knows an account's password guess its second-factor code without limit. The login page never restricts how many wrong 2FA guesses it accepts. An attacker can try codes automatically until one works, then sign in as the victim and turn the second factor off.
As only six digits stand between a stolen password and a full login, the second factor provides little real protection.
The route group is registered with only web.Bind, no throttle middleware:
m.Group(, {
m.Get(, auth.TwoFactor)
m.Post(, web.Bind[*forms.TwoFactorAuthForm](), auth.TwoFactorPost)
m.Get(, auth.TwoFactorScratch)
m.Post(, web.Bind[*forms.TwoFactorScratchAuthForm](), auth.TwoFactorScratchPost)
})
Are you affected?
Ask from here. InfraStack checks the affected versions against your stack and answers in your inbox.
InfraStack checks the affected versions against your stack and answers in Slack, with the evidence and the fix.
InfraStack checks it against your stack and answers on your report, with the evidence and the fix.
TwoFactorPost branches on the boolean result and, on failure, only re-renders:
// routers/web/auth/2fa.go (func TwoFactorPost)
ok, err := twofa.ValidateAndConsumeTOTP(ctx, form.Passcode)
if err != nil {
ctx.ServerError("UserSignIn", err)
return
}
if ok {
// ... issue the session, sign in ...
}
ctx.RenderWithErrDeprecated(ctx.Tr("auth.twofa_passcode_incorrect"), tplTwofa, forms.TwoFactorAuthForm{})
The trailing RenderWithErrDeprecated is the entire failure handling: the attempt is not counted and the twofaUid session set by the password step stays valid, so the identical POST repeats indefinitely. No web-layer rate limiter exists in routers/ or modules/web/ to inherit. Gitea's optional login CAPTCHA (RequireCaptchaForLogin) gates only the password step in SignInPost; TwoFactorPost never calls it, so enabling CAPTCHA does not add a check here.
The missing control is the attempt counter, not the crypto. ValidateAndConsumeTOTP uses a conditional UPDATE to reject a reused passcode atomically:
// models/auth/twofactor.go
t.LastUsedPasscode = passcode
n, err := db.GetEngine(ctx).ID(t.ID).
Where(builder.Or(builder.IsNull{"last_used_passcode"}, builder.Neq{"last_used_passcode": passcode})).
Cols("last_used_passcode").Update(t)
...
return n == 1, nil
totp.Validate runs at Skew=1, so 3 of the 1,000,000 codes are valid per 30-second window.
Measured observations:
modules/ssh/ssh.go).An attacker with the password recovers the second factor by exhaustive guessing. With Skew=1, p = 3 / 1,000,000 and expected attempts 1/p = 333,333 (the PoC hit at 309,961). The table uses a conservative 500 req/s, well under the 1,233 req/s the single-client PoC averaged:
| Success chance | Attempts | Time @ 500 req/s |
|---|---|---|
| 50% | 231,049 | 7.7 min |
| Mean (63%) | 333,333 | 11.1 min |
| 90% | 767,528 | 25.6 min |
| 95% | 998,578 | 33.3 min |
| 99% | 1,535,057 | 51.2 min |
After a hit the attacker holds a fully authenticated session and disables the victim's TOTP.
Add an account-keyed failure counter on twofaUid and reject once it is exceeded:
func TwoFactorPost(ctx *context.Context) {
uid, ok := ctx.Session.Get("twofaUid").(int64)
if !ok { ctx.ServerError("UserSignIn", errors.New("not in 2FA session")); return }
if failedTwoFactor(uid) >= 5 {
ctx.RenderWithErrDeprecated(ctx.Tr("auth.twofa_too_many_attempts"), tplTwofa, forms.TwoFactorAuthForm{})
return
}
ok2, err := twofa.ValidateAndConsumeTOTP(ctx, form.Passcode)
// ... on success: resetTwoFactor(uid); sign in ...
incrTwoFactor(uid, 5*time.Minute) // 5 failures / 5 minutes, per account
ctx.RenderWithErrDeprecated(ctx.Tr("auth.twofa_passcode_incorrect"), tplTwofa, forms.TwoFactorAuthForm{})
}
Keying on twofaUid means the ceiling cannot be widened by rotating source addresses, and five attempts per five minutes makes a 333,333-guess search infeasible.
Defense in depth, independent of the counter: emit a failed-authentication log line on a wrong TOTP in the format Gitea's documented fail2ban filter already matches, so operators who rely on fail2ban gain coverage of the web 2FA path, not just SSH.
NVD data is provided by NIST and is public domain. Posts quoted belong to their authors.