Skip to content

fix: report the new address when an email change is rejected as invalid - #2848

Open
vjymisal0 wants to merge 7 commits into
supabase:masterfrom
vjymisal0:fix/email-change-invalid-address-message
Open

vjymisal0 wants to merge 7 commits into
supabase:masterfrom
vjymisal0:fix/email-change-invalid-address-message

Conversation

@vjymisal0

@vjymisal0 vjymisal0 commented Oct 2, 2026 •

Copy link
Copy Markdown

What

Fixes #2847.

When the mailer rejects an address during an email change (PUT /user), the 400 response now names the address the mail validator rejected. This covers the new address, including when an anonymous user links an email, and the current address when secure email change sends to both.

How

The validation mail client retains the rejected recipient alongside the original validation error. sendEmail uses that recipient when returning email_address_invalid. The original validation error remains available through errors.Is, and the response status and error code are unchanged.

Testing

  • Tested all three recipient cases through the template mailer with a local validation service. The new current-address case fails on the previous PR head and passes with the fix.
  • The focused test passed 10 consecutive runs. The mailer suite passed on rerun after an intermittent DNS timeout assertion.
  • gofmt and git diff --check passed.

When the mailer rejects an email change, the 400 response quoted the
user's current email instead of the address being confirmed. For an
anonymous user linking an email for the first time this produced
`Email address "" is invalid`, and for other users it pointed at their
existing address rather than the new one.

Fixes supabase#2847
@vjymisal0
vjymisal0 requested a review from a team as a code owner October 2, 2026 14:39
@montjeffrey

Copy link
Copy Markdown

I ran this against a local server: auth built from the Dockerfile at 10ef107 and at this PR's head 25f95b7, address check on (GOTRUE_MAILER_EMAIL_VALIDATION_EXTENDED=true), secure email change on, a local mail catcher as SMTP.

PUT /user 10ef107 this PR
anonymous user, new address someone@example.com Email address "" is invalid Email address "someone@example.com" is invalid
user at an outlook.com address, new address new@example.com names the current address names the new address
user at current@example.com, new address at outlook.com Email address "current@example.com" is invalid names the new address

All of them are 400 email_address_invalid on both builds.

The third row is the case from your second note, run for real. The current address is the one the check rejects. master names it, and with this change the message names the new address, which is a valid one. I got a user into that state with POST /admin/users and email_confirm: true; I don't know how common such accounts are.

Tests: TestSendEmailChangeInvalidAddressError fails on 10ef107 (both subtests) and passes here. go test -p 1 ./internal/api/... ./internal/mailer/... -count=1: 1,538 results pass on 10ef107 and 1,541 here, and the difference is the new test with its two subtests. One test fails for me on both trees in the same way, TestAuth/TestMaybeLoadUserOrSession/Valid_Session_ID_Claim (a time.Location difference); I did not look into it. TestValidateEmailExtended passed in both runs. No race detector, since the build image has CGO off.

I used an AI assistant (Claude Code) to write the test scripts and help with this write-up. I ran everything on my own machine and checked the output.

@vjymisal0

Copy link
Copy Markdown
Author

Thanks for testing both recipients and sharing the results. Commit 3c417ae carries the rejected recipient through from the mail validator, so the response names the current address when that is the one rejected. It also still names the new address for an anonymous user linking an email. The three cases pass through the template mailer and a local validation service, and the new current-address case fails on the previous PR head.

This branch has not been deployed

No deployments
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.

updateUser({email}) fails with "Email address \"\" is invalid" when linking an email to an anonymous user with no prior email

2 participants