Skip to content

fix: prefer session user for phone_change verification (fixes #2430) - #2718

Open
deepshekhardas wants to merge 1 commit into
supabase:masterfrom
deepshekhardas:fix/2430-phone-change-ambiguous-user
Open

fix: prefer session user for phone_change verification (fixes #2430)#2718
deepshekhardas wants to merge 1 commit into
supabase:masterfrom
deepshekhardas:fix/2430-phone-change-ambiguous-user

Conversation

@deepshekhardas

Copy link
Copy Markdown

fix(verify): prefer session user for phone_change verification (fixes #2430)

phone_change has no unique constraint, so
FindUserByPhoneChangeAndAudience returns an arbitrary first match when
several users have an uncompleted (abandoned) pending phone change for
the same number. Verifying the OTP could then update a different
user's phone than the currently authenticated one.

When a valid session is presented and its user's phone_change matches
the phone being verified, prefer the session user over the ambiguous
lookup. Unauthenticated verification keeps the existing fallback.

@hf hf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

@hf hf changed the title fix(verify): prefer session user for phone_change verification (fixes #2430) fix: prefer session user for phone_change verification (fixes #2430) Sep 4, 2026

@fadymak fadymak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I think the proper fix we want here is to perform the lookup by the token hash in the one_time_tokens table, not the phone.

It would also be helpful to have tests for these changes 🙏

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.

Verifying a previously uncompleted phone may link to incorrect user ID

3 participants