Skip to content

fix(auth): reject email addresses as usernames on registration (#24)#25

Merged
krazyjakee merged 1 commit into
masterfrom
claude/naughty-bouman-d4c7a9
Jun 8, 2026
Merged

fix(auth): reject email addresses as usernames on registration (#24)#25
krazyjakee merged 1 commit into
masterfrom
claude/naughty-bouman-d4c7a9

Conversation

@krazyjakee

Copy link
Copy Markdown
Contributor

Summary

Closes #24. The registration endpoint only validated username length, so an email address like user@example.com was accepted as a username. Because login looks users up by username (a public identifier), allowing emails is confusing and undesirable.

What changed

  • Added a validate_username helper in src/routes/auth.rs that:
    • Rejects any username containing @400 "username may not be an email address"
    • Restricts the charset to lowercase [a-z0-9_.]
    • Forbids leading/trailing .
  • Wired it into register() after the existing length check.
  • Applied the same rule to the username-update endpoint update_current_user() in src/routes/users.rs (as suggested in the issue).
  • Added tests in tests/e2e.rs covering email-shaped usernames and invalid charsets (uppercase, spaces, leading/trailing dots).

Reviewer notes

  • Length validation (1–32 chars) is unchanged and remains in the callers; the new helper only handles charset/format.
  • Validation runs at registration and username-update time only — it does not affect login lookups, so pre-existing nonconforming usernames continue to work.

Test plan

  • cargo test --test e2e register — all 6 register tests pass (including 2 new ones)
  • cargo check clean

)

Registration only validated username length, so email addresses like
user@example.com were accepted as usernames. Since login looks users up
by username (a public identifier), this is confusing and undesirable.

Add a validate_username helper that rejects any username containing '@',
restricts the charset to lowercase [a-z0-9_.], and forbids leading or
trailing '.'. Applied to both register() and the username-update endpoint.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@krazyjakee krazyjakee merged commit 9409a1c into master Jun 8, 2026
3 checks passed
@krazyjakee krazyjakee deleted the claude/naughty-bouman-d4c7a9 branch June 8, 2026 21:36
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.

Reject email addresses as usernames on registration

1 participant