November 18, 2026
CVE-2026-123002: How I Found a 2FA Bypass in Gitea and Wrote the Patch
Missing rate limiting let anyone with a stolen password brute-force the six-digit TOTP code in about 11 minutes. Here is the bug, the…
By Sandiyo Christan
9 min read
Missing rate limiting let anyone with a stolen password brute-force the six-digit TOTP code in about 11 minutes. Here is the bug, the maths, and the patch I contributed.
TL;DR
Gitea up to and including 28.3.0 accepted an unlimited number of wrong TOTP passcodes at sign-in, in the password reset flow, and for Basic authentication using the X-Gitea-OTP header. Someone who already knew an account's password could guess the six-digit code at roughly 800 requests per second with nothing blocking them. The whole 1,000,000-code keyspace could be exhausted in about 21 minutes, and the expected hit came in around 11. After five failed passcodes, further attempts for the account are now refused for 15 minutes. Tracked as CVE-2026-123002 and fixed in Gitea 28.4.0.
What Gitea is, and why this matters
Gitea is a lightweight, self-hosted Git service written in Go. Think of it as an alternative to GitHub that you run yourself: organisations use it to host private repositories, run code review, and collaborate on software. It is deployed widely across enterprises, open-source communities, and teams who prefer to keep their source code on infrastructure they control.
When you turn on two-factor authentication in Gitea, it generates a TOTP secret. Every 30 seconds your authenticator app produces a fresh six-digit code, and after entering your password you must supply that code to finish logging in.
The promise of that second factor is simple: even if your password leaks, an attacker still cannot get in. This vulnerability broke the promise. A stolen password plus about eleven minutes of automated guessing was enough to walk straight through.
The vulnerability: no brakes on the 2FA endpoint
The core issue was almost mundane. The /user/two_factor POST endpoint enforced no rate limiting, no account lockout, and no backoff on failed attempts.
Here is the vulnerable path in routers/web/auth/2fa.go:
ok, err := twofa.ValidateAndConsumeTOTP(ctx, form.Passcode)
if err != nil {
ctx.ServerError("UserSignIn", err)
return
}
if ok {
// ... issue the session, sign in ...
}
// On failure: just re-render the form. That is all.
// No counter. No lockout. No log entry.
ctx.RenderWithErrDeprecated(
ctx.Tr("auth.twofa_passcode_incorrect"),
tplTwofa, forms.TwoFactorAuthForm{})ok, err := twofa.ValidateAndConsumeTOTP(ctx, form.Passcode)
if err != nil {
ctx.ServerError("UserSignIn", err)
return
}
if ok {
// ... issue the session, sign in ...
}
// On failure: just re-render the form. That is all.
// No counter. No lockout. No log entry.
ctx.RenderWithErrDeprecated(
ctx.Tr("auth.twofa_passcode_incorrect"),
tplTwofa, forms.TwoFactorAuthForm{})That trailing RenderWithErrDeprecated call was the entire failure-handling path. The attempt was never counted, and the twofaUid value written into the session by the password step stayed valid, so the identical POST could be replayed as fast as the server would answer it.
The route group was registered with only web.Bind and no throttling middleware, and there was no web-layer rate limiter anywhere in routers/ or modules/web/ for it to inherit:
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)
})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)
})The maths that makes it work
Let me break this down so it lands regardless of your background.
A TOTP code is six digits, so there are exactly 1,000,000 possible codes, from 000000 to 999999. That sounds like a lot until you remember a computer can try 800 of them every second.
It gets better for the attacker. Gitea validated TOTP with a skew of 1, meaning it accepted the current 30-second window's code plus the previous and the next one. That makes three valid codes out of a million at any given moment, tripling the odds on every guess.
Here is the arithmetic at a deliberately conservative 500 requests per second, well below the 1,233 per second a single-client proof of concept averaged:
Success chance Attempts needed Time @ 500 req/s
-----------------------------------------------------
50% 231,049 7.7 minutes
Mean (63%) 333,333 11.1 minutes
90% 767,528 25.6 minutes
95% 998,578 33.3 minutes
99% 1,535,057 51.2 minutesSuccess chance Attempts needed Time @ 500 req/s
-----------------------------------------------------
50% 231,049 7.7 minutes
Mean (63%) 333,333 11.1 minutes
90% 767,528 25.6 minutes
95% 998,578 33.3 minutes
99% 1,535,057 51.2 minutesWithin a single 30-second window at 800 requests per second an attacker gets roughly 24,000 guesses. With three codes valid at a time, that is about a 7 percent chance of landing it in that window alone, and the odds compound across successive windows. The expected number of attempts is one divided by the per-guess probability: 1,000,000 divided by 3, or about 333,333 tries.
To put it in human terms, the second factor that was supposed to stop a credential-stuffing attacker cold was worth about as long as a coffee break.
The attack, step by step
Step 1. Obtain the victim's password. Through phishing, credential stuffing from a breach dump, or social engineering, the attacker gets the target's Gitea password. This vulnerability assumes the password is already known; it is about what happens next.
Step 2. Log in with it. The attacker submits the password to POST /user/login. Gitea validates it, writes twofaUid into the session, and redirects to the 2FA page.
Step 3. Land on the 2FA prompt. The browser arrives at /user/two_factor. From here a single session cookie is all that ties the attacker's requests to the already-authenticated password step.
Step 4. Brute-force the code. The attacker's script fires hundreds of POST requests per second at /user/two_factor, each carrying a different six-digit guess. Every one is processed. No lockout, no slowdown, no CAPTCHA, and critically no log line a defender could alert on.
Step 5. A code lands. After some hundreds of thousands of attempts, one guess matches and Gitea issues a fully authenticated session. That the previous attempts all failed is irrelevant, because nothing was counting them.
Step 6. Full account compromise. The attacker holds the victim's session. They can read private repositories, modify source code, exfiltrate secrets from CI configuration, open and merge pull requests, and switch off the victim's 2FA to keep long-term access.
Three doors, not one
The missing rate limit was not confined to the sign-in prompt. The same gap existed at three separate entry points, which is part of why the advisory was rated High.
The sign-in flow (POST /user/two_factor) was the primary vector, measured at roughly 800 requests per second with nothing blocking it.
The password reset flow also required a TOTP code and also failed to count wrong ones, so the same brute force worked against account recovery.
Basic authentication with the X-Gitea-OTP header gave a parallel path through the API rather than the web UI, equally unthrottled. An attacker scripting against the API never had to render a page at all.
The scratch-token endpoint /user/two_factor/scratch shared the same missing control, measured at roughly 246 requests per second. Scratch tokens carry more entropy than a six-digit code, so they were less immediately exploitable, but the absent counter was the same absent counter.
Why the existing defences did not help
A fair question: does Gitea really have no protections at all? It has several. None of them covered this endpoint.
CAPTCHA. Gitea offers an optional login CAPTCHA via RequireCaptchaForLogin, but it gates only the password step inside SignInPost. TwoFactorPost never calls it. Administrators who had switched CAPTCHA on reasonably believed their login was hardened, while the 2FA page behind it stayed wide open.
fail2ban. Many operators run fail2ban against their Gitea logs. The 2FA failure branch emitted no log line at all. The failed-authentication format that Gitea's documented fail2ban filter matches exists only in the SSH server, in modules/ssh/ssh.go. A filter watching the web logs would therefore see a completely silent attack: hundreds of thousands of failed authentications leaving no trace.
TOTP replay protection. Gitea did ship a well-built control here, a conditional UPDATE that atomically rejects a reused passcode:
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, nilt.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, nilThat is correct code, and it is worth being precise about what it does. It stops an attacker who has observed a valid code from replaying it. It does nothing against an attacker guessing codes they have never seen, because every guess is a different value. The missing control was never the cryptography. It was the attempt counter.
That distinction matters for anyone auditing their own systems. A 2FA implementation can have flawless TOTP validation, correct replay protection, and a properly seeded secret, and still be bypassable in minutes if nobody counts the failures.
The disclosure, and my contribution
I found this independently and reported it to the Gitea security team through a GitHub Security Advisory, GHSA-mqr5-2993-53cg. My report covered the missing rate limiting on /user/two_factor, with measured throughput, reproduction steps, and a proposed fix. In testing I sent 500 consecutive wrong codes, watched all 500 be accepted without any blocking, then sent the correct code and received a full session.
The Gitea team let me know the issue had already been reported earlier by another researcher, SakusenSec, under GHSA-5mx6-8rwm-52wf. My report was closed as a duplicate and I was credited as a reporter on the original advisory.
If you are early in security research, I want to be clear that this is a normal and good outcome rather than a disappointment. Independent rediscovery is a signal that the finding was real and reachable, and duplicates are routine on any widely-reviewed codebase. What you do next is the part you control.
What made this one stand out for me is that I did not stop at the report. I contributed the patch that fixed it, and the Gitea team acknowledged that in the official 28.4.0 release notes:
Thanks to SakusenSec, Pedromdsn, sandiyochristan and glenaster for reporting the issue, and to sandiyochristan for the patch.
Being credited as both a reporter and the patch author on a CVE is the part of this I am proudest of. Finding the hole and closing it are different skills, and the second one is where the actual protection comes from.
The fix in Gitea 28.4.0
The patch landed in #39993 and was backported to the release/v28 branch in #40374. The approach is deliberately unglamorous, which is exactly right for an authentication control.
A per-account failure counter is keyed on twofaUid. After five failed passcodes, further attempts for that account are refused for 15 minutes. Keying on the account rather than the source address is the important design decision: an IP-keyed limit is widened by rotating proxies, whereas an account-keyed ceiling cannot be escaped by changing where the requests come from.
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, 15*time.Minute)
}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, 15*time.Minute)
}The same control now covers all three doors: the sign-in flow, the password reset flow, and Basic authentication via the X-Gitea-OTP header.
The effect on the attack economics is decisive. Five attempts per fifteen minutes works out at twenty guesses an hour, or about 175,000 a year. The expected 333,333 guesses would therefore take roughly 1.9 years of uninterrupted attempts against a single account, and a 95 percent chance of success would take closer to six. An attack that used to fit inside a coffee break now outlasts the password it started with.
Vulnerability details
CVE ID: CVE-2026-123002
CWE: CWE-307, Improper Restriction of Excessive Authentication Attempts
Severity: High
CVSS v3.1: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:L/A:N
Affected versions: Gitea 28.3.0 and earlier
Patched version: Gitea 28.4.0, released 15 November 2026
Advisory: GHSA-5mx6-8rwm-52wf
Affected component: routers/web/auth/2fa.go, TwoFactorPost and TwoFactorScratchPost
Fixes: #39993 on main, #40374 backported to release/v28
What you should do now
If you run a Gitea instance, upgrade to 28.4.0 or later. Everything up to and including 28.3.0 is affected, and the fix needs no configuration changes.
If you cannot upgrade immediately, put rate limiting in front of Gitea at your reverse proxy, whether that is nginx, Caddy, HAProxy, or a CDN, and point the rules at /user/two_factor, /user/two_factor/scratch, and the password reset endpoints. Treat this as cover rather than a cure, because proxy rules are usually keyed on source address, which a distributed attacker can spread across.
It is also worth checking your logs, with one caveat. Because the vulnerable code emitted nothing on 2FA failure, you will not find failed attempts recorded anywhere. What you can look for instead is an unusual volume of POST requests to /user/two_factor in your reverse proxy or access logs, particularly a large number tied to a single session.
Lessons worth carrying forward
For developers. Never let the first authentication factor stand in for protection of the second. Rate limiting has to exist at every authentication checkpoint on its own terms, because an endpoint reachable only after a password check is still an endpoint an attacker reaches. Log every authentication failure in a format your monitoring already parses, since a control your operators cannot see is a control they cannot act on. And key your counters on the account rather than the address, so the ceiling cannot be widened by rotating infrastructure.
For security researchers. Look at the second factor. A great deal of attention goes to password handling and comparatively little to what happens after it succeeds, which is precisely why gaps survive there. Read the failure branch of authentication code specifically. In this case the tell was something that was not there: an attempt counter that no line of code ever incremented. Absence is harder to spot than a bug you can point at, which is what makes it worth looking for deliberately.
And do not be discouraged by a duplicate. Independent discovery validates the finding. If the report is already filed, the patch usually is not, and that is an open door.
Timeline
26 August 2026. SakusenSec independently discovers and reports the issue as GHSA-5mx6-8rwm-52wf.
8 October 2026. Pedromdsn is credited as an additional reporter.
Late October 2026. I independently discover and report the issue as GHSA-mqr5-2993-53cg.
Early November 2026. My report is closed as a duplicate. I am credited as a reporter and added as a collaborator on the original advisory.
November 2026. I contribute the patch. The fix merges as #39993 and is backported as #40374. glenaster is credited as a further reporter.
15 November 2026. Gitea 28.4.0 ships with the fix and CVE-2026-123002 is assigned.
Credits
This one was found by several people working separately, and all of them deserve naming. Reported by SakusenSec, who filed first, along with Pedromdsn, glenaster, and myself. Patch contributed by me, Sandiyo Christan. Thanks to silverwind and bircni on the Gitea team for triaging, coordinating the advisory, and shipping the backport promptly.
Closing thoughts
Two-factor authentication is only as strong as its least interesting implementation detail. A missing counter turned a defence with one-in-a-million odds per guess into an eleven-minute speed bump, and nothing about the cryptography was wrong. The gap was in the bookkeeping.
If your application has a 2FA implementation, audit it this week. Check that failures are counted, that the counter is keyed to the account, that lockouts actually trigger, and that every failure writes a log line your alerting can see. Then check the paths people forget: password reset, API authentication headers, and recovery codes. The second factor protects the thing you care about most, which makes it exactly the thing worth testing properly.
If this writeup was useful, follow along. I will keep publishing disclosures and deep dives into authentication security.
References
Advisory GHSA-5mx6-8rwm-52wf covering CVE-2026-123002
Gitea 28.4.0 release notes
Fix PR 39993
Backport PR 40374
CWE-307 at MITRE