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
- Add the owner column to the condition: ((select auth.uid()) = user_id).
- For shared data, check membership: exists (select 1 from members m where m.team_id = team_id and m.user_id = (select auth.uid())).
- 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 appReferences
Related checks (M3)
- Permissive CORS with credentials
- State-changing request succeeded without authentication
- Weak JWT observed on the wire
- Biometric authentication not bound to a cryptographic key
- Premium access is stored on the phone and trusted (heuristic)
- Firebase rules trust an email address nobody verified
- Firebase security rules open to everyone
- Users can make themselves admin or premium in Firestore