Repository navigation
feat: return 422 email_exists when an unverified provider email is in use - #2945
Open
cemalkilic wants to merge 1 commit into
Open
cemalkilic wants to merge 1 commit into
cemalkilic wants to merge 1 commit into
Conversation
… use When an external provider reports an unverified email that already belongs to another user, Auth creates a separate user with no email. Behind the new opt-in GOTRUE_EXPERIMENTAL_REJECT_UNVERIFIED_EMAIL_IN_USE_ENABLED flag, the login is refused with 422 email_exists instead, and nothing is saved. The before-user-created hook is skipped because no user will be created. On the OAuth callback redirect this maps to error=access_denied&error_code=email_exists. Today's behavior is kept for non-default linking domains, providers with optional email, and when unverified email sign-ins are allowed.
This branch has not been 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.
What
An external provider can report an unverified email that already belongs to another user. Auth doesn't link the two accounts, since that would allow an account takeover. Instead, it creates a separate user with no email, commits it, and refuses the login with
provider_email_needs_verification. The person ends up with a stray second account.This PR adds an opt-in flag,
GOTRUE_EXPERIMENTAL_REJECT_UNVERIFIED_EMAIL_IN_USE_ENABLED(off by default). With the flag on, Auth refuses this login and saves nothing:422 email_existsbefore creating the user. The error rolls back the transaction, so no emailless user is left behind.error=access_denied&error_code=email_exists. Only this 422 maps that way. Identity linking already returnsemail_existsas a 400, which keeps mapping toinvalid_request.Unverified email with <provider> already belongs to an existing account. Sign in to that account to link <provider>. Clients should branch onerror_code.Even with the flag on, today's behavior is kept for:
GOTRUE_MAILER_ALLOW_UNVERIFIED_EMAIL_SIGN_INS=true