---
id: "CVE-2026-123002"
page: "https://infrastack.ai/live/CVE-2026-123002"
kind: "vulnerability"
aliases: ["CVE-2026-123002", "GHSA-5mx6-8rwm-52wf"]
title: "MFA TOTP brute-force via missing rate limiting on TwoFactorPost (POST /user/two_factor)"
severity: "high"
cvss: 8.2
epss: null
exploited: false
status: "open"
category: "runtime"
products: [{"name": "gitea.dev", "fixed": ["28.4.0"], "affected": "<= 28.3.0", "ecosystem": "go"}]
ecosystems: ["go"]
tags: ["cwe-307", "git-hosting", "gitea", "go", "runtime", "self-hosted"]
not_affected_if: ["fixed-28.4.0", "no-2fa-accounts"]
published_at: "2026-11-15T21:03:09+00:00"
first_seen_at: "2026-11-15T21:12:48+00:00"
updated_at: "2026-11-15T21:14:11+00:00"
sources: [{"source": "ghsa-repo", "url": "https://github.com/go-gitea/gitea/security/advisories/GHSA-5mx6-8rwm-52wf", "first_seen_at": "2026-11-15T21:12:48+00:00"}, {"source": "nvd", "url": "https://nvd.nist.gov/vuln/detail/CVE-2026-123002", "first_seen_at": "2026-11-15T22:40:23+00:00"}]
exploit_sources: []
---

# MFA TOTP brute-force via missing rate limiting on TwoFactorPost (POST /user/two_factor)

Link for people: https://infrastack.ai/live/CVE-2026-123002 (this .md is for agents)

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.

_Summary, check and fix written by a model from the sources; labelled as such._

## Affected

- go:gitea.dev affected <= 28.3.0 fixed 28.4.0

## How to check

- Compare the running Gitea version with `28.3.0`, the last affected release.
- Check whether any accounts have two-factor authentication enabled, since only those reach the vulnerable prompt.

## Fix

- Gitea: upgrade to `28.4.0`.

## Timeline

- 2026-11-15T21:12:48+00:00 ghsa-repo https://github.com/go-gitea/gitea/security/advisories/GHSA-5mx6-8rwm-52wf
- 2026-11-15T22:40:23+00:00 nvd https://nvd.nist.gov/vuln/detail/CVE-2026-123002

## Documents

- [advisory] Maintainer's advisory: github.com https://github.com/go-gitea/gitea/security/advisories/GHSA-5mx6-8rwm-52wf
- [fix] Release notes: github.com https://github.com/go-gitea/gitea/releases/tag/v28.4.0

## From the sources

**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.

## Summary

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. 

## Details

The route group is registered with only `web.Bind`, no throttle middleware:

```go
// routers/web/web.go
	m.Group("/two_factor", func() {
		m.Get("", auth.TwoFactor)
		m.Post("", web.Bind[*forms.TwoFactorAuthForm](), auth.TwoFactorPost)
		m.Get("/scratch", auth.TwoFactorScratch)
		m.Post("/scratch", web.Bind[*forms.TwoFactorScratchAuthForm](), auth.TwoFactorScratchPost)
	})
```

`TwoFactorPost` branches on the boolean result and, on failure, only re-renders:

```go
// 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:

```go
// 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:
- 30 consecutive wrong codes all returned HTTP 200 with no lockout.
- Window tolerance confirmed at offsets -1/0/+1 (3 valid codes per 30s window).
- The 2FA failure branch emits no log line, so a fail2ban filter watching the log cannot see failed TOTP attempts (that log format exists only in the SSH server, `modules/ssh/ssh.go`).

## Impact

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. 

## Remediation

Add an account-keyed failure counter on `twofaUid` and reject once it is exceeded:

```go
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.

---

_Free to read, with fair use of about 60 pages a minute. For higher limits or API access: sales@infrastack.ai_
