Repository navigation
fix(auth): normalize sign-in email domains and require exact stored email match - #4341
Merged
Merged
Conversation
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Member
Author
|
hey @greptileai, please re-review the PR |
Member
Author
|
@greptileai please re-review the latest commit. |
This branch was successfully deployed
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.
Sign-in email identifiers are now always plain ASCII, and every account lookup by email confirms the row it gets back has exactly the requested address.
flowchart LR A[typed email] --> B["normalizeSignInEmail<br/>NFKC, lowercase,<br/>domainToASCII"] B -- not printable ASCII --> X[400 / sign-in error] B --> C[code sent to normalized address] C --> D["getUserByEmail"] D --> E{"stored email<br/>(lowercased) ==<br/>requested?"} E -- yes --> F[session for that account] E -- no --> G["null: next-auth creates<br/>an account for the address"]packages/database/auth/domain-utils.ts:15:normalizeSignInEmailconverts the domain withdomainToASCII(punycode for internationalized domains) and returnsnullunless the whole address is printable ASCII, so a non-ASCII local part is refused before any code is sent.apps/web/app/api/mobile/[...route]/route.ts:576and:629: mobile request and verify usenormalizeSignInEmail, the same identifier the web flow, the OTP rate limits and next-auth already use, and return 400 when it isnull.packages/database/auth/drizzle-adapter.ts:isSameStoredEmailcompares the storedusers.email, lowercased, with the requested address.getUserByEmailreturnsnullwhen they differ. For a punycode domain it also tries the Unicode spelling of the same domain, so accounts stored before this change keep signing in to the same account. That second query only runs forxn--domains.createUserthrows instead of reusing an existing row with a different address. On the SSO path,ON DUPLICATE KEY UPDATEkeeps the stored email (email = email) and the re-selected row is checked.useVerificationTokenonly claims a token whose stored identifier equals the requested one.apps/web/app/api/auth/[...nextauth]/route.ts: an email callback whoseemaildoes not normalize redirects to theVerificationerror before next-auth runs.Behaviour notes:
apps/web/__tests__/unit/email-sign-in-stored-email.test.tsdrives the realauthOptions()andDrizzleAdapterthrough next-auth's email request and callback against an in-memory database that comparesusers.emailthe wayutf8mb4_0900_ai_cidoes.

Confidence Score: 5/5
The PR appears safe to merge, with no new blocking issues found.Summary
Email sign-in now uses ASCII addresses and checks that saved email addresses match before accepting an account. The latest update only makes invisible characters explicit in two test strings, without changing their values.
Both earlier findings are addressed. No new issues found.
Reviews (6) · Last reviewed commit: "test(web): write invisible characters in..." · Reviewed by Greptile