Supabase view bypasses RLS: security_invoker and revoking anon delete
By Arif Khan, AIVolve LLC · Updated November 11, 2026
"I turned on RLS, but my Supabase view still shows other users' data. Why?"
Short answer: in Postgres, a view runs with its owner's rights by default, not the rights of the person asking. On Supabase the owner is usually postgres, so the view skips the RLS policies on the tables underneath. Simple views can also be written through. If the logged-out anon role still has its old default DELETE grant, someone holding your public key can delete rows through the view. The fix takes four steps. Find every view that runs as its owner. On Postgres 15 and above, set security_invoker = true on each one, or lock it down if you're on an older version. Revoke the write grants that anon and authenticated don't need, on views and tables. Then test the result as a logged-out visitor.
Why this matters right now
On October 23, 2026, a founder posted on X (@MaxHirsch13) that his app had been hacked and 35,000 profiles wiped. In his words: "I bypassed RLS with a view so users could see each other's profiles, and didn't revoke Supabase's default anon permissions, so the public key could delete everyone through it." His post includes a 10-point audit prompt. Two of its points are the core of this guide: make every view security_invoker = true and revoke write grants on views, and revoke delete and truncate from anon on all tables.
On November 2, Crissy Field reported, together with Handelsblatt, on a scan of 159,041 Lovable projects. Of those, 24,664 sent Supabase records to the browser on page load without a login. The researchers say that alone "is not a security issue", because some data is meant to be public. Further read-only checks found tables with email-address records on 7,403 sites. They also say the sample isn't representative, so their figures shouldn't be read as a confirmed leak rate. I think the lesson is still clear: "RLS is on" and "my data is private" are not the same thing. Views and leftover grants are two of the most common reasons.
Why a view skips your RLS
Supabase's docs put it plainly: "Views bypass RLS by default because they are usually created with the postgres user." Postgres runs a view's queries against the underlying tables with the view owner's privileges, and on Supabase "the owner is postgres, which has bypassrls." Your policies can be perfect and the view will still hand out every row.
Writes get through too. The Postgres docs say a simple view is "automatically updatable", meaning Postgres turns an INSERT, UPDATE or DELETE on the view into the same statement on the table. The caller only needs the privilege on the view. The owner's privileges cover the table. So a profiles_view with a DELETE grant for anon can delete from profiles even when profiles has no delete policy at all.
You can see the difference on a throwaway test database. Logged out as anon, a plain delete from public.profiles removed nothing, because RLS was on and there was no delete policy. A delete through an ordinary view over the same table removed every row.
Postgres 15 added the fix: the security_invoker option. With it on, "the policies and permissions of the invoking user are used instead" of the owner's.
Before you start (2 minutes)
- Where to run SQL: in the Supabase dashboard, open SQL Editor. On Lovable Cloud, use More → Database → Manage → SQL editor for the read-only checks, and ask Lovable in chat to make changes as a migration (there's a prompt at the end).
- Check your Postgres version: run
show server_version;. Step 2 depends on it. - Save a restore point. Make sure you have a recent backup, or that your project is on GitHub, before you change grants.
- Know which schemas your API exposes. The queries below use
public. If you've added other schemas under the Data API settings, run them for those schemas too.
Step 1: Find views that run as their owner
A quick list of the views in public:
select viewname from pg_views where schemaname = 'public' order by 1;
Now the useful version. It lists every view and materialized view in public that does not have security_invoker turned on, and shows what the logged-out and signed-in roles can do with it. It only reads the catalog, not your data:
select c.relname as view_name,
case c.relkind when 'v' then 'view' else 'materialized view' end as kind,
pg_get_userbyid(c.relowner) as owner,
coalesce(array_to_string(c.reloptions, ', '), 'none') as options,
has_table_privilege('anon', c.oid, 'select') as anon_can_read,
has_table_privilege('anon', c.oid, 'delete') as anon_can_delete,
has_table_privilege('authenticated', c.oid, 'delete') as signed_in_can_delete
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public'
and c.relkind in ('v', 'm')
and not exists (
select 1 from unnest(coalesce(c.reloptions, '{}')) as o
where o ~* '^security_invoker=(true|on|yes|1)$'
)
order by 1;
How to read it:
- Every row is a view that ignores the RLS of the tables under it. Postgres stores the option the way it was written (
security_invoker=trueorsecurity_invoker=on), which is why the query checks both. anon_can_read= true means a logged-out visitor with your public key can read whatever the view returns.anon_can_deleteorsigned_in_can_delete= true is the dangerous one. If the view is a simple view over one table, deletes pass straight through to that table.- Materialized views can't use RLS at all. They're handled differently in step 2.
Security Advisor (Advisors → Security Advisor in the Supabase dashboard) flags the same problem at ERROR level as "View bypasses row-level security" (security_definer_view).
Step 2: Fix each view
On Postgres 15 and above: turn on security_invoker
alter view public.profiles_view set (security_invoker = true);
Replace profiles_view with your view's name, and run it once per view from step 1. For new views, write it into the create statement: create view public.x with (security_invoker = true) as ....
Then take away the write grants a view almost never needs, and grant back only reads, only to the roles that should have them:
revoke all on public.profiles_view from anon, authenticated;
grant select on public.profiles_view to authenticated;
Skip the grant line if signed-in users don't read this view through the API. Grant select to anon only if logged-out visitors really should see it.
Two things to expect afterwards:
- The view may now return fewer rows. That's the fix working: each user sees what the table's policies allow. If your app needs a public directory (like users seeing each other's profiles), add a select policy on the table that allows exactly that. Or keep the view, give it only the safe columns, and leave only
selecton it as above. Writes are what turned a privacy problem into a wipe. - A "permission denied" (42501) error after the change means the signed-in role has no grant on the underlying table. Since October 30, 2026, new Supabase tables don't get those grants automatically. Here's the safe fix.
On older Postgres: revoke access or move the view
Supabase's docs say that on older versions you should protect views "by revoking access from the anon and authenticated roles, or by putting them in an unexposed schema":
revoke all on public.profiles_view from anon, authenticated;
or
create schema if not exists private;
alter view public.profiles_view set schema private;
A schema that isn't in your Data API's exposed schemas can't be reached with the public key. Your server code (an Edge Function, for example) can still read it.
Materialized views
These can't use RLS. Supabase's advisor fix is to revoke reads from the API roles and serve the data another way:
revoke select on public.some_mat_view from public, anon, authenticated;
Step 3: Revoke delete and truncate where they aren't needed
This is the second half of the incident above, and it applies to your tables, not just views.
Supabase's docs say that on existing projects, "a new table in public starts with every privilege already granted to all three roles". The default grants include select, insert, update, delete, truncate, references, trigger, and (on Postgres 17) maintain. They also note: "Adding policies doesn't take those grants back."
The October 30, 2026 change doesn't clear this up for you. It only covers select, insert, update and delete on new tables, and Supabase says existing tables "keep their current grants". New tables still get truncate, references, trigger and maintain. The docs add that the Data API doesn't use those, "but SQL that runs as anon or authenticated can, such as a database function." TRUNCATE also ignores RLS. The Postgres docs say whole-table operations "such as TRUNCATE and REFERENCES, are not subject to row security."
Check what anon and authenticated can do on every table and view:
select c.relname as name,
case c.relkind when 'v' then 'view' else 'table' end as kind,
has_table_privilege('anon', c.oid, 'insert') as anon_insert,
has_table_privilege('anon', c.oid, 'update') as anon_update,
has_table_privilege('anon', c.oid, 'delete') as anon_delete,
has_table_privilege('anon', c.oid, 'truncate') as anon_truncate,
has_table_privilege('authenticated', c.oid, 'truncate') as signed_in_truncate
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public' and c.relkind in ('r', 'p', 'v')
order by 1;
Revoke what nobody should have. Your app doesn't use TRUNCATE through the API, and logged-out visitors almost never need to delete anything:
revoke truncate on all tables in schema public from anon, authenticated;
revoke delete on all tables in schema public from anon;
In Postgres, "all tables" here includes views. If logged-out visitors never write anything in your app, revoke insert, update from anon too. A waitlist or contact form is the usual exception: keep insert on that one table only.
Stop new tables from getting them back. Grants only change existing objects. Default privileges control what future tables get, and the Postgres docs note that for default privileges, "tables" includes views:
alter default privileges for role postgres in schema public
revoke truncate on tables from anon, authenticated;
alter default privileges for role postgres in schema public
revoke delete on tables from anon;
Supabase's own examples use for role postgres, which covers tables the postgres role creates. To see what's left, run:
select pg_get_userbyid(d.defaclrole) as for_role, n.nspname as schema, d.defaclacl
from pg_default_acl d
left join pg_namespace n on n.oid = d.defaclnamespace
where d.defaclobjtype = 'r';
In the anon=... entry, d means delete and D means truncate. Neither letter should be there now.
Step 4: Test it as a logged-out visitor
Test 1, in the SQL editor (changes nothing). Postgres checks permissions before it looks for rows, so a delete that matches no rows is a safe way to ask "is this allowed?":
begin;
set local role anon;
delete from public.profiles_view where false;
rollback;
permission denied for view profiles_viewis what you want.- A result like "DELETE 0" or "Success. No rows returned" means
anonstill has DELETE on that view. Go back to step 2.
You can test reads the same way: replace the delete line with select count(*) from public.profiles_view;. As anon, you should get 0 rows or a permission error, unless the data is meant to be public.
Test 2, from outside, exactly as a stranger would. In a terminal, using only your project URL and public key (the publishable key, or the older anon key), with no login:
curl "https://YOUR-PROJECT-REF.supabase.co/rest/v1/profiles_view?select=*&limit=3" \
-H "apikey: YOUR_PUBLIC_KEY"
An empty list [] or a permission error means the view is closed to logged-out visitors. If you get real rows that a stranger shouldn't see, it isn't fixed yet. Read tests only, please: never test deletes against your live data.
Then run the two-account test from our RLS check: log in as User B and try to open User A's data through every screen that uses a view.
How to verify you're done
- The step 1 query returns no rows. Any row it does return is a materialized view you've already revoked, or a view you kept on purpose, with only
selectgranted and only safe columns. - Security Advisor shows no "View bypasses row-level security" errors, apart from any you've kept deliberately and understand.
- The step 3 query shows
anon_delete,anon_truncateandsigned_in_truncateas false everywhere. The onlyanon_insertleft is on tables that really take logged-out input. - The default-privileges query shows no
dorDforanon, and noDforauthenticated. - The logged-out delete test gives "permission denied", and the curl test returns nothing private.
- Your app still works for real users. Click through every screen that reads from a view while logged in.
A prompt for Lovable, Cursor or Claude Code
Database security fix for Supabase views and grants. Work in two phases. Phase 1, read-only: list every view and materialized view in the public schema, its owner, whether it has security_invoker = true, and whether anon or authenticated can SELECT, INSERT, UPDATE or DELETE on it. Also list every table where anon has INSERT, UPDATE, DELETE or TRUNCATE, or authenticated has TRUNCATE. Show me the list and change nothing. Phase 2, after I approve: write ONE migration that 1. sets security_invoker = true on every regular view (we are on Postgres 15 or later), 2. revokes all on each view from anon and authenticated, then grants select back only to the roles I name, 3. revokes select on materialized views from public, anon and authenticated, 4. revokes truncate on all tables in schema public from anon and authenticated, and delete from anon, 5. runs alter default privileges for role postgres in schema public so new tables do not get truncate (anon, authenticated) or delete (anon). Do not drop any table, view, policy or data. Show me the migration before applying it.
FAQ
Why does my Supabase view show other users' data when RLS is enabled?+
Because a view runs with its owner's privileges by default, and on Supabase the owner is usually postgres, which bypasses RLS. Set security_invoker = true on the view (Postgres 15 and above) so it uses the policies of the person asking.
What does security_invoker = true do?+
It makes Postgres check the underlying tables with the privileges and RLS policies of the user querying the view, instead of the view's owner. You can turn it on for an existing view with alter view public.your_view set (security_invoker = true).
Can someone delete data through a Supabase view?+
Yes, if the view is a simple view over one table and the anon or authenticated role has DELETE on the view. Postgres passes the delete through to the table using the owner's rights. Revoke write grants on views unless you really need them.
Should I revoke delete and truncate from anon in Supabase?+
In most apps, yes. Revoke truncate from anon and authenticated, and delete from anon, unless a logged-out visitor really needs to delete something. Also change your default privileges so new tables don't get them back. Adding RLS policies doesn't remove grants.
Did Supabase's October 30, 2026 change fix this?+
Not fully. It stopped new tables from automatically getting select, insert, update and delete for the API roles, but existing tables keep their grants and new tables still get truncate, references and trigger. Check your grants with the queries in this guide.
Want a second pair of eyes?
Start with a free X-ray: 2 minutes, no code or passwords. Your AI builder writes a read-only report that includes security red flags, and an AIVolve developer reviews every X-ray within 1 business day. Get a free X-ray →
Related: Supabase RLS for AI-built apps: the 10-minute check · Security audit prompts for AI-built apps · Supabase "permission denied for table" on new tables · Is my Lovable app secure? The 15-minute check · Supabase columns users should never edit
Written by Arif Khan, AIVolve LLC. VibeCoderSOS isn't affiliated with Lovable, Cursor or Supabase. Settings names and SQL were checked against Supabase's documentation on November 4, 2026, and may change.
Need help?
Start with a free X-ray: 2 minutes, no code or passwords. Your AI builder writes a read-only report that includes security red flags, and an AIVolve developer reviews every X-ray within 1 business day.
Get a free X-ray →