Repository navigation
Log at most 32 characters of a throttled login's username - #281
Merged
Merged
Conversation
The throttle's log line named the account as typed. The name comes from the form at whatever length was sent, up to the form field limit, and a refused attempt is cheap: it is answered before any password hashing. So every refused /login or /register could add half a megabyte to the log. A real username is 3 to 20 characters and is still logged whole; anything longer is cut at 32 and logged with its length.
This was referenced Oct 9, 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.
When an address has spent its login attempts,
_throttled()logs a warning that names the account the attempts are aimed at, as typed (mcritweb/views/authentication.py:65). The name comes straight from the form, so its length is whatever was sent, up to Flask's form field limit (500 KB by default). A refused attempt is cheap to send: it is answered before any password hashing (authentication.py:291). So every refused/loginor/registercould add that much to the log. Measured in the test client, with the address over its budget: a 100,000-character name gave a 100,068-character log line on both routes, and a 499,000-character name a 499,068-character one.%ralready kept the line from breaking the log apart; only its length was unbounded.Change. The name goes through
_name_for_log()(authentication.py:56): logged whole when it is at mostLOGGED_NAME_LENGTH(32) characters, otherwise its first 32 characters and its length, e.g.'xxxxxxxx'... (100000 characters). A username is 3 to 20 characters (administration.py:28,authentication.py:219), so a real account is always named whole;register:<name>, which/registercounts under since #276, fits too.Looked at, not changed. The failed attempts recorded in
login_attemptalso keep the typed name. Those rows are bounded already: at mostLOGIN_ATTEMPT_LIMIT(10) per address before the throttle stops recording, pruned once they leave the 15-minute window (mcritweb/db.py:751-764). Cutting the name there as well would change which namescount_recent_login_failuresandclear_login_failurescompare, for no gain.Verification. In the test client only: a refused attempt does not reach the backend or write to the corpus, so there is nothing for the live testbed to show beyond the log line the tests below read.
Tests. In
tests/testLoginThrottle.py:test_a_refused_attempt_logs_a_bounded_namespends the budget, sends a 100,000-character name to/loginand/register, and checks that both throttle lines are under 200 characters and end with the name's length. It fails without the change.test_a_refused_attempt_still_names_a_real_account_wholeis a guard: a 20-character name is still logged as before.Relation to open PRs. Stacked on #276 (
fix/login-throttle-own-failures; its two commits come first in this branch), which addsregistration_token_attempt()next to the new helper and changes what/registerpasses to_throttled(). Merge #276 first; the diff here then shrinks to this branch's own commit. A trial merge (git merge-tree) with #278, #277, #279, #280, #254 and #262 is clean, and on the merged tree with #278,testLoginThrottle.py,testLogin.pyandtestSettingsPages.pypass (60 tests).