Enforce username rules on every account-creation path - #2
Closed
jackowayed wants to merge 1 commit into
Closed
jackowayed wants to merge 1 commit into
jackowayed wants to merge 1 commit into
Conversation
jackowayed
force-pushed
the
claude/username-validation-security-coua1g
branch
2 times, most recently
from
August 11, 2026 05:42
f59c3ea to
6b46199
Compare
Username format rules (2-20 chars, [a-zA-Z0-9_] only) were enforced only
by POST /api/auth/username/check, which is advisory. The four paths that
actually insert users — email registration completion, OAuth completion,
and native Apple/Google sign-in — ran only the profanity filter, so a
300-character username containing HTML, newlines, and unicode was
accepted and stored.
Usernames are rendered directly into push notification bodies
("${user.username} sent you an Oy!"), so a stored username is attacker
-controlled lock-screen copy for anyone who receives an Oy.
validateUsername in lib.ts is now the single gate: length, character set,
and profanity. normalizeUsername (previously dead code) trims and
lowercases, matching how usernames are stored and looked up. Both are
applied at each creation path, and the check endpoint now delegates to
the same function so advisory results match what creation accepts.
Also removes fetchUserByUsername, which had no callers.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PvpccXvmDzszQ1fCJnaChX
Co-authored-by: jackowayed <18899+jackowayed@users.noreply.github.com>
jackowayed
force-pushed
the
claude/username-validation-security-coua1g
branch
from
August 11, 2026 16:04
6b46199 to
e686221
Compare
Owner
Author
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 bug
Username format rules — 2-20 characters,
[a-zA-Z0-9_]only — were enforced only byPOST /api/auth/username/check, which is advisory and creates nothing. The four paths that actually insert users ran only the profanity filter:email.ts— email registration completionoauth.tsviatryCreateOAuthUser— OAuth completion and both callback flowsA 300-character username containing HTML, newlines, and unicode was accepted and stored.
That matters because usernames are rendered directly into push notification bodies —
`${user.username} sent you an Oy!`— so a stored username is attacker-controlled lock-screen copy for anyone who receives an Oy. The broadcast feature that just landed onmainadds a second such call site.The fix
validateUsernameinlib.tsis now the single gate for every username reaching the users table: length, character set, then the profanity filter.normalizeUsername(previously dead code) trims and lowercases, matching how usernames are stored and compared viaLOWER(username).It's applied at each creation path. The two OAuth callback flows go through
tryCreateOAuthUser, which now returnsnullfor an invalid username — so instead of creating a user they fall through to the existing choose-username screen. The native routes return a 400 with the specific error.The check endpoint now delegates to the same function, so advisory results and creation results can't drift apart again.
Also removes
fetchUserByUsername, which had no callers.Testing
Red-green: 8 tests written first, all 8 failing against the unpatched code, the rest of the suite passing to confirm the failures were the bug rather than a broken harness.
tests/worker/username.test.ts— unit coverage for normalize, accept, length bounds, and rejection of HTML, newlines, an RTL override, emoji, spaces, hyphens,@, and profanity.email.test.ts/oauth.test.ts— integration tests driving each creation path with a 300-char HTML/newline/emoji username and with"zed\nsent you an Oy!". Each asserts the 400 anddb.users.length === 0/db.sessions.length === 0, so a regression that validates but still inserts would fail.Rebased onto
mainafter phulin#19 merged. Full suite: 108 passing.tsc -bexits 0,biome checkclean.Notes
ChooseUsernameScreen.tsx), so this doesn't tighten anything below what the UI allows.