-
Notifications
You must be signed in to change notification settings - Fork 750
fix(signup): return 409 instead of raw 500 on concurrent signup race (fixes #2675) #2712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
deepshekhardas
wants to merge
1
commit into
supabase:master
Choose a base branch
from
deepshekhardas:fix/2675-otp-signup-race
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Severity: MEDIUM
An unauthenticated caller controls the signup email and
X-JWT-AUD; when the audience-scoped lookup misses an email belonging to another audience, the globalusers_email_partial_keyreaches this branch and returnsuser_already_exists. On structured-error API versions, that response exposes cross-audience account existence.Helpful? Add 👍 / 👎
💡 Fix Suggestion
Suggestion: In
signupNewUser, the unique-constraint violation ontx.Create(user)is currently mapped unconditionally to409 user_already_exists. This leaks cross-audience email existence becauseIsDuplicatedEmailfilters by audience and misses a user in a different audience, but the globalusers_email_partial_keyindex still fires.The fix is to add a same-audience confirmation lookup before returning
user_already_exists. After the constraint violation,tx(and the closure'sconn, since they may be the same aborted connection when called from within an outer transaction) cannot be used for subsequent queries. Instead, usea.db— the non-transactional connection held by the API struct — to callmodels.FindUserByEmailAndAudience(a.db, user.GetEmail(), user.Aud). Only return theuser_already_exists409 if a user is confirmed to exist in the SAME audience (a legitimate concurrent race). Otherwise fall through to the existing genericNewInternalServerErroron line 391, which avoids exposing cross-audience account existence to the unauthenticated caller.