high · M3 · MASVS-AUTH-2 · PTKD-BACKEND-SUPABASE-ROLE-ONLY-POLICY

    Supabase policy that only checks "signed in", not whose row it is

    A Row Level Security policy's condition only asks whether the caller is signed in (auth.role() = 'authenticated', auth.uid() is not null). It does not tie the row to the caller, so every user, including one who just signed up, reaches every row the policy covers.

    How it is exploited

    messages has `for select to authenticated using (auth.role() = 'authenticated')`. An attacker signs up with a throwaway email, takes the session token from the app, and pages through /rest/v1/messages?select=*: everyone's private messages.

    Why it matters

    Every account can read (or change) every other account's data; sign-up is the only barrier.

    How to fix it

    1. Add the owner column to the condition: ((select auth.uid()) = user_id).
    2. For shared data, check membership: exists (select 1 from members m where m.team_id = team_id and m.user_id = (select auth.uid())).
    3. Test with two accounts: B must not see A's rows.

    migration

    drop policy "signed in can read" on public.messages;
    create policy "owner can read" on public.messages
      for select to authenticated using ((select auth.uid()) = user_id);

    Does your app have this?

    PTKD checks your build or your source project for PTKD-BACKEND-SUPABASE-ROLE-ONLY-POLICY and every other check in this knowledge base.

    Scan your app

    References

    Related checks (M3)