Skip to content

Log at most 32 characters of a throttled login's username - #281

Merged
danielplohmann merged 2 commits into
masterfrom
fix/throttle-log-bounded-name
Oct 24, 2026
Merged

danielplohmann merged 2 commits into
masterfrom
fix/throttle-log-bounded-name

Conversation

@r0ny123

@r0ny123 r0ny123 commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

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 /login or /register could 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. %r already 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 most LOGGED_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 /register counts under since #276, fits too.

Looked at, not changed. The failed attempts recorded in login_attempt also keep the typed name. Those rows are bounded already: at most LOGIN_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 names count_recent_login_failures and clear_login_failures compare, 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_name spends the budget, sends a 100,000-character name to /login and /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_whole is 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 adds registration_token_attempt() next to the new helper and changes what /register passes 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.py and testSettingsPages.py pass (60 tests).

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.
@danielplohmann
danielplohmann merged commit f3c1ccc into master Oct 24, 2026
8 checks passed
danielplohmann added a commit that referenced this pull request Oct 24, 2026
@r0ny123
r0ny123 deleted the fix/throttle-log-bounded-name branch October 30, 2026 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants