Ship-Ready / Guides

Your RLS is right, but a view hands the rows out anyway.

AI builders love creating views like order_summaries or public_profiles. By default a Postgres view runs with its owner's rights, not the caller's, so it can skip the policies on the table underneath.

Why it happens

Views in the public schema are exposed through the Supabase API like tables. Unless the view is created with security_invoker = true (Postgres 15+), it checks permissions as the role that owns it, usually postgres, which isn't subject to your RLS policies. Supabase's database linter flags this as "Security Definer View".

Find them: one query

select c.relname as view_name
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public' and c.relkind = 'v'
  and not coalesce(c.reloptions::text[] @> array['security_invoker=true'], false);

Run it in the Supabase SQL editor. Every row returned is a view that ignores the caller's RLS. You can also open Advisors → Security Advisor in the dashboard and look for "Security Definer View".

Fix it

alter view public.order_summaries set (security_invoker = true);

Now the view applies the RLS policies of whoever queries it. If a view must never be read by the API at all, revoke it instead:

revoke all on public.order_summaries from anon, authenticated;

In a migration file, create new views with the option from the start: create view public.x with (security_invoker = true) as select ...

Check it worked

Sign in as a second test user and select from the view. You should see only that user's rows. Our second-user test script works on views too: add the view name to its table list.

Related trap: SECURITY DEFINER functions

A function marked security definer in public runs as its owner and can be called through the API with rpc(). If it doesn't check auth.uid() itself, or isn't revoked from anon, it's the same hole. Pin its search_path as well (set search_path = '').

Don't want to check by hand?

The free Ship-Ready quick scan runs locally and flags views without security_invoker, RLS-off tables and using (true) policies in your migrations. The Crew (59-check scan, $39) adds SECURITY DEFINER function checks and fix prompts.

Related: the 10-minute Supabase self-check · test as a second user · is my anon key a problem?