Skip to content

feat: return 422 email_exists when an unverified provider email is in use - #2945

Merged
cemalkilic merged 1 commit into
masterfrom
cemalkilic/auth-2094-return-422-email_exists-and-save
Nov 25, 2026
Merged

cemalkilic merged 1 commit into
masterfrom
cemalkilic/auth-2094-return-422-email_exists-and-save

Conversation

@cemalkilic

@cemalkilic cemalkilic commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • It returns 422 email_exists before creating the user. The error rolls back the transaction, so no emailless user is left behind.
  • On the OAuth callback redirect, this maps to error=access_denied&error_code=email_exists. Only this 422 maps that way. Identity linking already returns email_exists as a 400, which keeps mapping to invalid_request.
  • The message is Unverified email with <provider> already belongs to an existing account. Sign in to that account to link <provider>. Clients should branch on error_code.
  • The before-user-created hook is skipped, because no user will be created.

Even with the flag on, today's behavior is kept for:

  • providers in a non-default linking domain (including SSO)
  • providers where email is optional
  • GOTRUE_MAILER_ALLOW_UNVERIFIED_EMAIL_SIGN_INS=true

… 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.
@cemalkilic
cemalkilic requested a review from a team as a code owner November 20, 2026 10:57
@cemalkilic
cemalkilic merged commit deb6d9e into master Nov 25, 2026
13 checks passed
@cemalkilic
cemalkilic deleted the cemalkilic/auth-2094-return-422-email_exists-and-save branch November 25, 2026 13:50
cstockton pushed a commit that referenced this pull request Nov 25, 2026
🤖 I have created a release *beep* *boop*
---


##
[2.199.0](v2.198.0...v2.199.0)
(2026-11-25)


### Features

* add client auth method to custom OAuth providers
([#2934](#2934))
([034e4ec](034e4ec)),
closes [#2932](#2932)
[#2933](#2933)
[#2935](#2935)
[#2936](#2936)
* add experimental config for client assertion signing keys
([#2932](#2932))
([782c2d0](782c2d0)),
closes [#2933](#2933)
[#2934](#2934)
[#2935](#2935)
[#2936](#2936)
* gate private_key_jwt in the custom provider admin API
([#2935](#2935))
([f78a61d](f78a61d)),
closes [#2932](#2932)
[#2933](#2933)
[#2934](#2934)
[#2936](#2936)
* Remove the DB connection pool advisor
([#2955](#2955))
([83865c1](83865c1))
* return 422 email_exists when an unverified provider email is in use
([#2945](#2945))
([deb6d9e](deb6d9e))
* sign and cache private_key_jwt client assertions
([#2933](#2933))
([7d8f364](7d8f364)),
closes [#2932](#2932)
[#2934](#2934)
[#2935](#2935)
[#2936](#2936)
* use client assertions in the custom OIDC token exchange
([#2936](#2936))
([10ef107](10ef107)),
closes [#2932](#2932)
[#2933](#2933)
[#2934](#2934)
[#2935](#2935)


### Bug Fixes

* **deps:** bump otel to v1.47.0 for vulncheck
([#2956](#2956))
([b3ad6af](b3ad6af))
* signup for users with one confirmed identifier
([#2964](#2964))
([2f090c8](2f090c8))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: supabase-releaser[bot] <223506987+supabase-releaser[bot]@users.noreply.github.com>
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.

2 participants