Repository navigation
Forget only the failed logins of the name that just logged in - #276
Merged
Merged
Conversation
A successful login deleted every login_attempt row of the address. The throttle is keyed on the address, so anyone holding an account - a self-registered pending one is enough, login checks no role - could guess at another account's password without end: nine wrong guesses at the victim's name, one login as themselves, repeat. The same reset applied to the registration-token budget, because /register recorded a wrong token under whatever username was typed, and the attacker types their own. Clear only the rows recorded under the username that just authenticated. A wrong registration token is recorded under "register:<name>", which no account can carry (the username format forbids ':'), so no login reaches those rows at all. The cost: failures under a mistyped username stay counted until the window ends, even once the right name has logged in. Those rows are guesses the address made, and only a username the person actually logged in with is proven to be theirs.
Wrong registration tokens are counted under register:<name> so that a login can never clear them, which only works while no username can hold a colon. The username patterns that make sure of that live in two other places, so a test now tries to register such a name.
This was referenced Oct 9, 2026
danielplohmann
added a commit
that referenced
this pull request
Oct 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The login throttle from #101 is keyed on the source address: ten failures in fifteen minutes and the address is refused on
/loginand/register. A successful login then forgot every failure the address had made (mcritweb/db.py:801,clear_login_failures), so that someone who mistyped their own password a few times does not carry the count around. That reset was available to anyone holding an account - a self-registeredpendingone is enough, since/loginchecks no role. Nine wrong guesses at another account's name, one login as themselves, and the budget was full again. The same reset applied to the registration token:/registerrecorded a wrong token under whatever username was typed, and the attacker types their own.Change.
clear_login_failures(remote_addr, username)deletes only the rows recorded under the name that just authenticated (mcritweb/db.py:801-818);login()passes the typed name (mcritweb/views/authentication.py:297)./registerrecords a wrong token underregister:<name>(mcritweb/views/authentication.py:42-48, used at:201and:215). No account can carry that string: the username pattern on/registerand on/admin/change_usernameallows letters, digits, dots and underscores only (its$also accepts one trailing newline, but never a colon), so no login ever reaches those rows.test_no_account_can_be_named_like_a_registration_token_counterpins that, since the patterns live elsewhere. The lookup is an exactWHERE username = ?, with SQLite's default binary collation, so a case variant of a name is a different name.mallorymallorymallorymalloryregister:malloryThe cost. Failures under a mistyped username stay counted until the window ends, even once the right name has logged in: two attempts as
alciefollowed by a login asaliceleave the address with two of its ten attempts spent for the rest of the fifteen minutes. That is the right side to err on. The throttle meters guesses made from an address, and only a name the person actually logged in with is proven to be theirs; the alternative of also clearing rows for names that do not exist would hand any account holder an unmetered way to confirm which names exist (#101).Verification. Measured offline, through HTTP against a loopback app. A reproducer that alternates nine wrong guesses at a victim's name with a login as the attacker's own account, on a scratch copy of master and of this branch, both at 1cdc195: master lets all 54 guesses through unthrottled and the victim's password still logs in afterwards; the branch refuses the guesses once ten are counted. The registration-token variant, 54 wrong tokens in six rounds of nine plus a login: master refuses 0 of 54, the branch 44 of 54. A second probe that types the attacker's name in three variants (as is, capitalised, with a trailing newline on an account of exactly that name) is throttled in every variant, and
register:...names are refused by both/registerand/admin/change_username.Tests.
tests/testLoginThrottle.py:102(another account's login does not forget the failures) andtests/testLoginThrottle.py:191(a login does not forget wrong registration tokens). Both fail on master and pass here, andtest_no_account_can_be_named_like_a_registration_token_counterfails if the registration pattern ever accepts a colon; the existingtest_a_successful_login_forgets_the_failuresstill passes, so a person's own mistyped passwords are still forgiven.Relation to open PRs.
fix/login-keeps-account-changesis stacked on this branch: it changes the line directly aboveclear_login_failuresinlogin(), so the two could not be kept independent. Merge this one first. A trial merge (git merge-tree) with #254 and #262 is clean. #160 already conflicts with master in twelve files,authentication.pyamong them; this branch adds no file to that list.Not changed here: parallel guesses that all pass the throttle check before any of them is recorded. That is on master and independent of the reset.