Make usernames one case-insensitive namespace (B-57)
The login throttle keyed on body.username.lower() while the lookup matched User.username exactly, so "Bob" and "bob" were two accounts sharing one rate-limit bucket — each able to lock the other out — and registration happily accepted near-duplicate names, which on a custodial system is an impersonation vector. Uniqueness is now the database's job: a unique index on lower(username), with register and login both matching through func.lower(). The name is still stored exactly as typed, since that's what /admin and the audit log display, and the username pattern is ASCII-only so lower() is the whole of the normalization. The migration refuses to run if two existing accounts differ only by case. It can't merge or rename one automatically: both are custodial accounts that may hold funds, so that would be the migration silently deciding who owns what. It names the collisions and leaves them to the operator — the container runs `alembic upgrade head` at startup, so it surfaces as a refusal to start rather than a half-applied schema. Verified both directions against a scratch DB, plus `alembic check` (clean) and the collision guard actually firing. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ab65728bdc
commit
57721355f0
6 files changed
+109
-16
No files matched your search
@@ -40,18 +40,6 @@ remains the last prerequisite for running unattended.
|
||||
|
||||
## High — security
|
||||
|
||||
### B-57 — username matching is case-sensitive while the login throttle key is not
|
||||
|
||||
`app/auth/routes.py:126` (`body.username.lower()`) vs `:132`
|
||||
(`User.username == body.username`).
|
||||
|
||||
Two consequences: `Bob` and `bob` are separate accounts sharing a single rate-limit
|
||||
bucket (one locks the other out), and registration happily accepts near-duplicate
|
||||
usernames, which is an impersonation vector on a custodial system.
|
||||
|
||||
Fix: make username uniqueness case-insensitive (store a normalized form, or a
|
||||
functional unique index) and key the throttle on the same normalized value.
|
||||
|
||||
### B-58 — the registration throttle counts successes as failures and is IP-only
|
||||
|
||||
`app/auth/routes.py:66-71`.
|
||||
|
||||
Reference in new issue
Block a user