Skip to content

fix(api): return correct hashed token for email_change_new in adminGenerateLink#2550

Open
Jualhosting wants to merge 3 commits into
supabase:masterfrom
Jualhosting:fix-email-change-new-token-mismatch
Open

fix(api): return correct hashed token for email_change_new in adminGenerateLink#2550
Jualhosting wants to merge 3 commits into
supabase:masterfrom
Jualhosting:fix-email-change-new-token-mismatch

Conversation

@Jualhosting
Copy link
Copy Markdown

@Jualhosting Jualhosting commented May 28, 2026

Summary

This PR fixes a bug in \�dminGenerateLink\ where generating an action link for type \email_change_new\ returns a \hashed_token\ property derived from the user's old/current email instead of the new email.

Details

When an admin generates an email change link for \email_change_new\ via the \�dminGenerateLink\ handler:

  1. The token hash stored in the database (\user.EmailChangeTokenNew) is correctly computed using the new email address (\params.NewEmail) and OTP.
  2. However, the \HashedToken\ returned in the API JSON response was always assigned \hashedToken, which is computed using the old/current email address (\params.Email) and OTP.

Because of this discrepancy, client applications and SDKs (such as \�dmin.generateLink) receive a hashed token that is incompatible with the one persisted in the database, causing verification or link validation to fail during the change confirmation step.

Fix

  • Dynamically set the returned \HashedToken\ in \GenerateLinkResponse\ to \user.EmailChangeTokenNew\ when \params.Type\ is \mail.EmailChangeNewVerification.
  • Updated the unit tests in \internal/api/mail_test.go\ to assert this correct, unified behavior.

Assistance Disclosure

Just a quick heads-up: I used Antigravity (a Gemini-based AI coding assistant) to help track down and patch this hashed token bug. I've thoroughly reviewed and tested the fix to make sure everything is correct.

Resolves supabase#2534 by adding a fallback mechanism in ParseIDToken.
When go-jose throws unsupported elliptic curve error, the fallback
manually fetches the JWKS and verifies the secp256k1 signature
using go-ethereum/golang-jwt ECDSA implementation.
@Jualhosting Jualhosting requested a review from a team as a code owner May 28, 2026 03:32
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.

1 participant