Repository navigation
Description
Bug report
- I confirm this is a bug with Supabase, not with my own application.
- I confirm I have searched the Docs, GitHub Discussions, and Discord.
Describe the bug
Calling supabase.auth.updateUser({ email }) on an anonymous session that has never had an email fails with a validation error, even though the target address is a perfectly valid, well-formed email:
AuthApiError: Email address "" is invalid
code: email_address_invalid, status: 400
Note the quoted address in the error is an empty string, not the address that was actually passed in the request. This happens with GOTRUE_MAILER_AUTOCONFIRM off (the secure/default config), i.e. the normal "send a real confirmation email" path - not the (separately reported, also concerning) autoconfirm-bypass path in #41125 / #29350.
Root cause (traced in this repo)
internal/api/mail.go, sendEmailChange() calls sendEmail() without setting recipientEmail:
err := a.sendEmail(r, tx, u, sendEmailParams{
emailActionType: mail.EmailChangeVerification,
otp: otpCurrent,
otpNew: otpNew,
tokenHashWithPrefix: u.EmailChangeTokenNew,
})Inside sendEmail():
recipientEmail := params.recipientEmail
if recipientEmail == "" {
recipientEmail = u.GetEmail()
}For a normal user changing their email, u.GetEmail() returns their current (non-empty) address, so this fallback happens to work. For an anonymous user linking an email for the first time, u.GetEmail() is "" - there is no current email - so recipientEmail stays empty. That empty string is what then gets validated/used downstream (the mail.EmailChangeVerification branch), and validation correctly rejects "" - just for the wrong reason. The actual target address (u.EmailChange, set correctly a few lines earlier in the same function) is never what gets checked or notified.
To Reproduce
- Project with
GOTRUE_MAILER_AUTOCONFIRM=false(default/secure setting) and anonymous sign-ins enabled. const { data } = await supabase.auth.signInAnonymously()await supabase.auth.updateUser({ email: 'someone@example.com' })using that session's own access token.- Observe
AuthApiError: Email address "" is invalid(email_address_invalid), regardless of how well-formed the target address is.
Expected behavior
The email-change confirmation should be sent to the new address (u.EmailChange), and validation should run against that address - not silently fall back to the (empty, for an anonymous user) current email.
Impact
This blocks the standard "upgrade an anonymous/guest session to a permanent account via email" flow entirely for any user who hasn't already got an email set - which is the normal case for anonymous auth. The only way to avoid it currently is enabling GOTRUE_MAILER_AUTOCONFIRM, which reopens the issue described in #41125 / #29350 (email silently confirmed with no OTP).
System information
- Environment: production (hosted)
- Version of supabase-js: 2.117.0
- Auth server version: current production (hosted project, not self-hosted)
Additional context
Related: #41125, #29350 - both about anonymous-user email linking, but describing the opposite failure mode (silent bypass rather than a spurious validation error). This may be an edge case in the same general code area (anonymous-user + email-change) that wasn't covered by whatever fix/change produced the current sendEmail/recipientEmail fallback behavior.
Activity
montjeffrey commentedon Nov 20, 2026
I can reproduce this on
master(10ef107). The request is rejected because of the address in the example, not because the user is anonymous. What is wrong is the address in the error message.Smallest request (auth built from the
Dockerfileat10ef107, Postgres 15,GOTRUE_EXTERNAL_ANONYMOUS_USERS_ENABLED=true,GOTRUE_MAILER_EMAIL_VALIDATION_EXTENDED=true):The new address decides the result:
PUT /userwithGOTRUE_MAILER_EMAIL_VALIDATION_EXTENDED10ef107someone@example.comtrueEmail address "" is invalidoutlook.comtrueemail_changeis savedsomeone@example.comfalseexample.comis on the blocked host list of the address check (validateclient.go#L53). The mail itself is addressed tou.EmailChange. The empty string only appears in the message, which printsrecipientEmail, and that falls back to the user's current address (mail.go#L768-L771,#L925-L928). So adding an email to an anonymous user works onmasterwhen the address passes the check.A user who already has an address gets the same kind of wrong message: changing from an
outlook.comaddress tonew@example.comreturnsEmail address "<the current address>" is invalid.#2848 changes the message to name the new address. I ran the same requests against its head (
25f95b7, which already contains10ef107): the first row returnsEmail address "someone@example.com" is invalid, the other two rows are unchanged. Its testTestSendEmailChangeInvalidAddressErrorfails on10ef107(2 of 2 subtests: it gets""and the current address where it expects the new one) and passes with the change.Not tested: a hosted project, the validation service URL, the Send Email hook, PKCE, supabase-js (I sent the HTTP requests directly, with a local mail catcher as the SMTP server).
@lh-lena, does the update go through for you with an address on a real mail domain?
I used an AI assistant (Claude Code) to read the code, write the test scripts and help with this write-up. I ran everything on my own machine and checked the output.