</>RescueMyRepoFree scan

// guide · Supabase RLS · published Nov 16, 2026

Your Supabase RLS is on, but a view leaks every row: fix it with security_invoker

Short answer

A Postgres view runs with its owner's privileges unless you say otherwise, and on Supabase the owner is usually postgres, which bypasses RLS. So a view in the public schema over a protected table can hand every user's rows to anyone with your anon key, even though the table's policies are correct. Find these views with the query below or the Security Advisor (security_definer_view), then run alter view public.your_view set (security_invoker = true); in a new migration and re-test logged out.

Why this happens in AI-built apps

Lovable, Bolt, Cursor and Claude Code reach for a view whenever a page needs joined or trimmed data: a profile directory, a dashboard summary, an “orders with customer name” list. The tables get RLS because every tutorial says so. The view doesn't, because Postgres's default for views is to use the creator's permissions, which Supabase's docs call an unintuitive default kept for backwards compatibility (Supabase lint 0010). Everything works in testing, because the view returns data for everyone, including people who shouldn't see it.

-- The table is locked down...
alter table public.profiles enable row level security;
create policy "own profile" on public.profiles
  for select using ((select auth.uid()) = id);

-- ...but this view, created by a migration (owner: postgres), skips that policy.
create view public.profile_directory as
  select id, full_name, email, phone from public.profiles;
-- Anyone with the anon key: GET /rest/v1/profile_directory  -> every user's email and phone

This is the same failure the November 2026 Lovable research kept finding (data readable on page load without a login), just one layer further in: people check the table, see RLS on, and stop. See Is your Lovable app one of the 7,403? for the table-level checks.

Find risky views in 2 minutes

Fastest: Supabase dashboard → Advisors → Security Advisor, and look for security_definer_view (ERROR), materialized_view_in_api and auth_users_exposed. Or run this in the SQL editor:

-- Supabase SQL editor: public views that run with the owner's privileges
select c.relname as view_name,
       c.reloptions
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public'
  and c.relkind = 'v'
  and coalesce(array_to_string(c.reloptions, ','), '') !~* 'security_invoker=(true|on|1|yes)'
order by 1;

-- Materialized views in public (these can never apply RLS)
select matviewname from pg_matviews where schemaname = 'public';

Every view in the first list that selects from a table with RLS on is a candidate. Views over genuinely public data (a product catalog, published posts) are fine to leave, but say so in a comment so the next AI edit doesn't copy the pattern onto private data.

Test one logged out

Views are exposed through the Data API just like tables. Ask for a few rows with nothing but the public anon key:

# Your OWN project only. The anon key is the public one already in your frontend.
URL=https://YOUR-PROJECT.supabase.co
ANON=your-anon-key

curl -s "$URL/rest/v1/profile_directory?select=*&limit=5" \
  -H "apikey: $ANON" -H "Authorization: Bearer $ANON"

# [] or a permission error = not readable logged out.
# Real user rows = the view is leaking. Fix it, then run this again.

Then sign in as a second test account and repeat the query from your app: you should only ever get that account's own rows (or rows meant to be shared).

The fix

security_invoker makes the view run as the caller, so the RLS policies on the underlying tables apply. It needs Postgres 15 or newer, which current Supabase projects run (Postgres CREATE VIEW docs). Put it in a migration so it survives a reset or a new environment:

-- New migration, e.g. supabase/migrations/20261116_views_security_invoker.sql
alter view public.profile_directory set (security_invoker = true);

-- New views: set it at creation time
create view public.my_orders
  with (security_invoker = true)
as
  select id, total, status from public.orders;

-- Materialized views can't use security_invoker: take them off the API instead
revoke select on public.daily_stats from public, anon, authenticated;

After the switch the view may return fewer rows, or none, for some callers. That is the leak closing. If the page really should show other users' data, make that explicit instead of relying on the view's owner:

-- If the directory SHOULD be public, say exactly which rows are shared...
create policy "listed profiles are visible" on public.profiles
  for select to anon, authenticated
  using (is_listed = true);

-- ...and remember RLS filters rows, not columns. Keep private columns
-- (email, phone) in a separate table with owner-only policies, or use
-- column privileges so API roles can only read the safe ones:
revoke select on public.profiles from anon, authenticated;
grant select (id, username, avatar_url, is_listed) on public.profiles to anon, authenticated;

One more case: a view over auth.users in public exposes every account's email and metadata. Supabase recommends a public.profiles table filled by a trigger, with its own policies (lint 0002). Materialized views can't apply RLS at all, so keep them off the API (lint 0016).

Tell your AI coding tool

Paste this into Lovable, Bolt, Cursor or Claude Code:

Audit every view in this Supabase project for Row Level Security bypass.
1. Find each CREATE VIEW / CREATE MATERIALIZED VIEW in supabase/migrations (and any created in the dashboard: query pg_class where relkind in ('v','m') and the schema is public).
2. For each public view that selects from a table with RLS enabled and does not have security_invoker = true, write a new migration with: alter view <name> set (security_invoker = true);
3. For each materialized view in public, revoke select from public, anon and authenticated unless it is meant to be fully public.
4. If a page relied on the view to show other users' data, add an explicit SELECT policy for exactly the shared rows, and keep private columns (email, phone, address) out of anything anon can read.
5. Never fix a broken page by disabling RLS or by using the service_role key in the browser.
6. Show me the migration and a test: query each view logged out with the anon key and as a second user, and confirm only allowed rows come back.

Check your repo automatically

RescueMyRepo's free scan reads your SQL migrations in order and flags public views that select from RLS-protected tables without security_invoker (high severity when the table looks sensitive, like profiles, users, orders or messages), with a fix prompt for each. It also checks tables with RLS off, using (true) policies, login-only policies, Realtime exposure, leaked keys and unverified Stripe webhooks. It reads code, so views created by hand in the dashboard only show up in the SQL query above.

Scan my repo freePublic GitHub repos · no signup · about a minute

FAQ

Why does my Supabase view ignore RLS?

By default a Postgres view runs its query with the privileges of the view's owner, not the user who queries it. Supabase's own docs call this an unintuitive default kept for backwards compatibility. Views created in the SQL editor or by a migration are usually owned by postgres, which bypasses RLS, so the view returns rows the caller could never read from the table directly.

What does the Security Advisor warning security_definer_view mean?

It is lint 0010 (level ERROR): a view in an API-exposed schema such as public that runs with its owner's privileges. Anyone with your project URL and public anon key can query it through the Data API (supabase-js or /rest/v1) and it does not apply the RLS policies on the tables underneath it.

Will turning on security_invoker break my app?

It can, which is the point: after the switch the view only returns rows the caller's RLS policies allow. If the view fed a page that should show other users' data (a public profile directory, a leaderboard), add an explicit SELECT policy for exactly those rows, or expose only the safe columns through a separate table or function. Test logged out and as a second user before and after.

What about materialized views?

Materialized views can't apply RLS at all, and they can't use security_invoker. If one sits in the public schema and anon or authenticated can select from it, every row is visible (lint 0016). Revoke select from public, anon and authenticated, or move it to a schema that isn't exposed and read it from server code.

Is a view over auth.users safe?

Not by default. A security definer view in public that selects from auth.users exposes every user's email and metadata to API users (lint 0002). Use a public.profiles table filled by a trigger, with its own RLS policies, instead.

Does RescueMyRepo detect this?

Yes. The free scan reads your SQL migrations and flags public views that select from RLS-protected tables without security_invoker. It skips views that later get security_invoker, views revoked from anon and authenticated, and dropped views, and it marks views that filter by auth.uid() or opt out explicitly as review items.

Sources