critical · M3 · MASVS-AUTH-2 · PTKD-BACKEND-SUPABASE-RLS-OFF

    Supabase table without Row Level Security

    A table in the public schema never gets Row Level Security enabled. Supabase exposes public tables through its REST API, and the anon key in your app is enough to read, change and delete every row.

    How it is exploited

    A vibe-coded app creates public.profiles and public.messages in a migration but never enables RLS. An attacker copies the anon key and project URL from the app, then calls GET https://<ref>.supabase.co/rest/v1/messages?select=* and downloads every user's private messages. A PATCH or DELETE on the same URL changes or wipes them.

    Why it matters

    Complete exposure of user data and loss of integrity: anyone can read, edit or delete every row. This is the most common breach in AI-built apps.

    How to fix it

    1. Add `alter table public.<table> enable row level security;` for every public table in a new migration.
    2. Add policies per operation, keyed on the signed-in user (auth.uid()).
    3. Move tables that the app should never read directly into a private schema.
    4. Run Supabase's Security Advisor (Dashboard → Advisors) and rescan with PTKD.

    migration

    alter table public.messages enable row level security;
    
    create policy "owner can read" on public.messages
      for select to authenticated using ((select auth.uid()) = user_id);
    create policy "owner can write" on public.messages
      for insert to authenticated with check ((select auth.uid()) = user_id);

    Does your app have this?

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

    Scan your app

    References

    Related checks (M3)