fix/email inconsistency#385
Conversation
Ayush-Patel-56
left a comment
There was a problem hiding this comment.
The bug fix is correct, but shipping it as-is creates a real PII leak that didn't exist before this PR. Needs the RLS/grant gap closed before merge.
| ALTER TABLE profiles | ||
| ADD COLUMN IF NOT EXISTS email text; |
There was a problem hiding this comment.
profiles is select-using(true) plus anon has table grant select (migration 0021), so this column is world readable via the REST API with no login. Needs its own RLS-locked table or a column grant restriction before merge.
| github_handle: githubHandle, | ||
| avatar_url: avatarUrl ?? null, | ||
| display_name: displayName ?? null, | ||
| email: user.email ?? null, |
There was a problem hiding this comment.
fine once the RLS gap above is closed, just flagging it writes the exposed column.
|
@Ayush-Patel-56 Got it, how should i close the RLS gap
|
|
Separate table. Help-dispatch already reads via service role, which skips RLS regardless of where the column lives, so email never needed to be on a publicly-grantable table in the first place. Column grants on profiles would still fight the existing New table defaults to no anon access (no default-privileges statement in the migrations), so |
|
@pavsoss is attempting to deploy a commit to the codersogs-3057's projects Team on Vercel. A member of the Team first needs to authorize it. |
jakharmonika364
left a comment
There was a problem hiding this comment.
Security design matches what @Ayush-Patel-56 discussed, looks right. Two things before merging: 0022_add_profile_email.sql/0023_profile_emails.sql collide with 0022_ai_pr_detection_setting.sql already on main, needs renumbering (and honestly, squashing into one migration since this PR adds then immediately drops profiles.email itself). Also, can you add a test that mocks profile_emails with a real row and asserts sendHelpDispatchEmail gets called with that address? Nothing currently exercises that path.
Description
Fixes the email inconsistency between Supabase Auth and the application profile model by persisting user email addresses on the
profilestable.Background jobs such as
help-dispatch.tscannot access the active Supabase session and therefore need a reliable way to resolve user email addresses. This change introduces an email field on profiles and keeps it synchronized from the authenticated user session during profile bootstrap.Changes
emailcolumn onprofilesprofiles.emailbootstrapProfileto persistuser.emailfrom the Supabase Auth session during profile creation/updateType of Change
Related Issue
Closes #365
Checklist
npm run dev)