high · M3 · MASVS-AUTH-2 · PTKD-BACKEND-SUPABASE-RLS-BYPASS

    Supabase view or function that bypasses Row Level Security

    A view in the public schema runs with its owner's rights (no security_invoker), or a SECURITY DEFINER function is callable by anyone. Either one reads tables as the database owner, skipping every RLS policy you wrote.

    How it is exploited

    RLS protects public.orders, but a convenience view public.order_summary was created for the dashboard. Views run as their owner by default, so GET /rest/v1/order_summary returns every customer's orders to an anonymous caller.

    Why it matters

    RLS is silently skipped for everything reachable through the view or function.

    How to fix it

    1. Recreate views with `with (security_invoker = true)` (Postgres 15+).
    2. For each SECURITY DEFINER function: `revoke execute on function public.f from public, anon;` and grant only to the roles that need it.
    3. Add `set search_path = ''` and fully qualify table names inside the function.
    4. Check Supabase's Security Advisor lints `security_definer_view` and `function_search_path_mutable`.

    migration

    create or replace view public.order_summary with (security_invoker = true) as
      select id, total, user_id from public.orders;
    
    revoke execute on function public.admin_stats() from public, anon;

    Does your app have this?

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

    Scan your app

    References

    Related checks (M3)