Skip to content

fix(db): scope invite codes to studies#831

Open
mohiuddinshahrukh wants to merge 2 commits into
devfrom
fix-cross-study-invite-code-leakage
Open

fix(db): scope invite codes to studies#831
mohiuddinshahrukh wants to merge 2 commits into
devfrom
fix-cross-study-invite-code-leakage

Conversation

@mohiuddinshahrukh
Copy link
Copy Markdown
Collaborator

Description

Invite-code validation could rely on invite_code alone, so enrollment could reference an invite code without the database also enforcing that the code belongs to the same study.

Changes

  • Scope app invite lookup by both code and study_id
  • Add composite unique constraint on study_invite (study_id, code)
  • Replace study_subject.invite_code foreign key with composite (study_id, invite_code) foreign key
  • Add public.is_invite_code_for_study(uuid, text) as a SECURITY DEFINER helper
  • Update restrictive insert policy on study_subject to validate (study_id, invite_code)
  • Revoke function execution from public and anon
  • Mirror DB changes in database/studyu-schema.sql

Testing

  • flutter analyze in app
  • flutter analyze in designer_v2
  • git diff --check
  • Frontend invite-code flow:
    • invalid code rejected
    • valid code accepted
  • Applied migration to local Supabase
  • Transaction-only DB test as postgres:
    • valid (study_id, invite_code) accepted
    • mismatched pair rejected
    • rolled back
  • Authenticated/RLS-level DB test:
    • valid pair accepted under authenticated
    • mismatched pair rejected by policy

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 11, 2026

Visit the preview URL for this PR (updated for commit 76cadfa):

(expires Sat, 23 May 2026 12:34:47 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 2149dad49ed83535217e50d5c18c0c8c90da629b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants