fix(auth): bind session signup to the JWT-verified phone number#132
Merged
ralyodio merged 1 commit intoJul 2, 2026
Merged
Conversation
The session-based branch of POST /api/auth/verify-sms (useSession + auth header) validates the JWT and obtains the verified user, but never compares user.phone to the request-body phoneNumber. Unlike the OTP branch (which binds the phone via verifyOtp), it then persists the client-supplied phoneNumber verbatim as the new user's phone_number. A caller holding any valid Supabase session (their own verified number, or an anonymous session) could therefore complete registration claiming a phone number they never verified (phone spoofing). Enforce that the requested phone matches the JWT-verified phone (compared as bare digits) and reject anonymous/phoneless sessions with 403. Add regression tests for the mismatch and anonymous cases.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The session-based branch of
POST /api/auth/verify-sms(useSession+ auth header) validates the JWT and obtains the verified user, but never comparesuser.phoneto the request-bodyphoneNumber. Unlike the OTP branch (which binds the phone viaverifyOtp), it then persists the client-suppliedphoneNumberverbatim as the new user'sphone_number.So a caller holding any valid Supabase session (their own verified number, or an anonymous session) can complete registration claiming a phone number they never verified — phone spoofing / pre-registration of a target number (see #131).
Fix
Right after
getUsersucceeds, bind the requested phone to the JWT-verified phone (compared as bare digits, so a leading+difference doesn't cause false rejects) and reject anonymous/phoneless sessions:The guard runs before any DB work, so a spoofed/anonymous request is rejected before a user row is created. The OTP branch is unchanged.
Tests
Added
verify-sms/route.test.js(mirroring the existingupload-avatar/route.test.jsmock style): a mismatched phone → 403PHONE_SESSION_MISMATCH, and an anonymous/phoneless session → 403.Fixes #131.