Does Supabase RLS apply to views? A check for Lovable and Bolt apps
Short answer: not by default. Supabase's own docs say “views bypass RLS by default” and that “a view over a protected table hands out every row its policies were meant to withhold.” So you can turn Row Level Security on for every table and still leak data through one view. Here are four checks.
Free scan: check my app Just your web address. Results in seconds. No signup, no card.
A view is a saved query that looks like a table, for example “orders joined with customer names” for a dashboard. AI builders sometimes add one when you ask for a summary page or a leaderboard. This guide is for Lovable and Bolt apps connected to your own Supabase project. Lovable's docs say its built-in backend is built on Supabase's open-source foundation, and Bolt's default Bolt Database can be claimed in Supabase. If you're on a built-in backend, ask the AI in the chat to run the checks below for you.
1. Know why views skip your rules
In Postgres, a view runs with the permissions of whoever created it, unless you say otherwise. Supabase's docs explain that views are usually created by the postgres user, which can read past RLS. Supabase's Security Advisor calls this “View bypasses row-level security” and rates it an error. The same docs say a view in your public schema is accessible through your project's APIs, so the views you already have are worth a look.
2. Look for flagged views in the Security Advisor
In your Supabase dashboard, open the Security Advisor. Look for these findings:
- View bypasses row-level security (security_definer_view): a view that ignores your table rules.
- User data exposed through a view (auth_users_exposed): a view that reads from
auth.users, where your users' emails live. - Materialized view exposed in API: a stored copy of a query. Supabase notes these can't be protected by RLS at all.
Some findings may be on purpose, such as a public product list. Check each one against what you mean to share.
3. List your views and their setting
In the SQL Editor, run this read-only query. It lists every view and materialized view in your public schema. A normal view that should follow RLS needs security_invoker=true in the options column.
select c.relname as view_name,
case c.relkind when 'v' then 'view' else 'materialized view' end as kind,
c.reloptions as options
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public' and c.relkind in ('v', 'm');
4. Test it as a stranger and as a second user
Open the view's data the same way your app does, once while signed out and once signed in as a second test user. If either can see rows that belong to someone else, the view is leaking. Our two-user check for Lovable apps walks through this step by step.
How to fix it
On Postgres 15 and above, Supabase's docs say to set security_invoker = true, which makes the view obey the RLS policies of the tables underneath it. Postgres lets you change this on an existing view with alter view ... set (security_invoker = true). On older Postgres, revoke access to the view from anon and authenticated, or move it to a schema your API doesn't expose. For a materialized view, revoke select from anon and authenticated, since it can't follow RLS.
After the change, make sure the tables under the view have RLS on with policies that limit rows to the right user. See Lovable: Supabase RLS turned off or Bolt: Supabase RLS turned off.
Fix prompt to paste into the Lovable or Bolt chat
List every view and materialized view in the public schema of my Supabase database, and what each one is used for. For each normal view that shows user data, set security_invoker = true so it follows the RLS policies of its tables, and check those tables have RLS on with policies limited to the signed-in user. For any materialized view, or any view that reads from auth.users, revoke select from anon and authenticated, and replace it with a safe table or view if the app needs it. Don't change views that are meant to be public, like a product list, without asking me. Show me a table of each view and what you changed.
After the AI makes changes, run the Security Advisor again and repeat check 4 with two test accounts. AI fixes can look right and still miss a view.
What PeekLok's scan checks
If your app's public anon key is in your page code, PeekLok's scan tries to read your Supabase tables with it and reports any that return rows. Views your project lists to that key are tried the same way. It may not see every view, and it doesn't test what signed-in users can read through a view, so still run the checks above.
Sources
- Supabase docs: Row Level Security (Views and RLS, Expose a view safely)
- Supabase docs: Advisors (security_definer_view, auth_users_exposed, materialized views)
- PostgreSQL docs: CREATE VIEW (security_invoker)
- PostgreSQL docs: ALTER VIEW
- Lovable docs: Supabase integration
- Bolt docs: Supabase integration
Related
- Lovable: Supabase RLS turned off
- Bolt: Supabase RLS turned off
- Lovable: One customer can see another’s data
- Can anyone call my Supabase database functions? An RPC check for Lovable and Bolt apps
- Can anyone call my Supabase Edge Function? A check for Lovable and Bolt apps
- Are uploaded files in my Lovable app public? A storage bucket check
- Supabase RLS turned off explained
Get a free scan
PeekLok checks your live app for secret keys in the page code, Supabase keys and tables anyone can read with the public key, and five security headers. With two test logins (Supabase login) it also checks whether one user can see the other’s data. Only scan apps you own. First scan free. Weekly re-checks will be $12 US a month once payments open.
