critical · M3 · MASVS-AUTH-1 · PTKD-BACKEND-SUPABASE-USER-METADATA-POLICY
Supabase policy trusts user_metadata, which every user can edit
A Row Level Security policy reads user_metadata (auth.jwt() -> 'user_metadata' or auth.users.raw_user_meta_data). Each signed-in user can set their own user_metadata with one call from the app (supabase.auth.updateUser({ data: { role: 'admin' } })), so a policy that grants access on it grants access to anyone who asks.
How it is exploited
The policy says `using ((auth.jwt() -> 'user_metadata' ->> 'role') = 'admin')`. A user opens the app, runs `supabase.auth.updateUser({ data: { role: 'admin' } })` from the console or a proxy, refreshes the session and now passes the admin policy on every row.
Why it matters
Any user becomes admin, another tenant or a paying customer, and reads or changes data the policy was meant to protect.
How to fix it
- Move the field to app_metadata: `update auth.users set raw_app_meta_data = raw_app_meta_data || '{"role":"admin"}' where id = ...` from the server only.
- Change the policy to `(auth.jwt() -> 'app_metadata' ->> 'role') = 'admin'`, or join a roles table the user cannot write.
- Run the Supabase advisor (lint 0015) after the change.
migration
drop policy "admins read all" on public.orders;
create policy "admins read all" on public.orders for select to authenticated
using ((auth.jwt() -> 'app_metadata' ->> 'role') = 'admin');Does your app have this?
PTKD checks your build or your source project for PTKD-BACKEND-SUPABASE-USER-METADATA-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