Fix a Supabase view that bypasses RLS: security_invoker and revoking anon write grants
Updated · Applies to: Supabase, Lovable, Bolt, v0, Cursor, Replit, Claude Code
TL;DR fix: In Postgres a view runs with its owner's rights, and on Supabase that owner is postgres, which bypasses RLS. So a view over an RLS-protected table can hand out every row, and if anon still has the default write grants on the view, anyone with your public key can also delete through it. Fix: alter view ... set (security_invoker = true) (Postgres 15+), then revoke insert, update, delete, truncate on ... from anon, authenticated for every view, and re-test with only your anon key. If you need a view that shows other users' public fields, expose a narrow SELECT-only view or a separate public table instead of turning RLS off.
Steps
- List every view in public and whether it is safe. Run the audit query below in the SQL editor. For each view it shows whether security_invoker is on, whether anon can select, and whether anon or authenticated holds any write grant. Anything with security_invoker = false and anon_select = true is readable by the whole internet through your public key. Any write grant on a view is almost never needed.
- Revoke write grants on all views. Views rarely need INSERT, UPDATE, DELETE or TRUNCATE from the Data API. Revoke them from anon and authenticated on every view in public. This one step would have stopped the delete-through-the-view attack described below.
- Make views that touch private tables obey RLS. On Postgres 15 and above run alter view public.your_view set (security_invoker = true). The view then runs as the caller, so the RLS policies of the underlying tables apply. Supabase's own docs recommend this and its Security Advisor flags the opposite as 'View bypasses row-level security'.
- If users need to see each other's public fields, expose only those. security_invoker = true means a user sees only the rows their own RLS policy allows, so a 'see everyone's profile' feature stops working. Use a view that selects only safe columns (no email, no user_id if sensitive), keep it SELECT-only for authenticated, and put the real table behind RLS. Or move the public fields into their own table with a select policy and a narrow column list.
- Fix the default grants that cause this for new objects. On projects that still grant everything to anon and authenticated by default, run the alter default privileges statements below so new tables and views no longer get write access automatically. Supabase's Oct 30, 2026 change does this for new tables on existing projects, but views you already created keep the grants they have.
- Retest with only the anon key, then re-run Security Advisor. From a logged-out browser or curl with just your public key, try a GET, a PATCH and a DELETE on each view's /rest/v1/ endpoint. All writes should return a 401 or 403 or a permission error, and reads should return only data you meant to publish. Then run Security Advisor and clear every 'View bypasses row-level security' finding.
What went wrong: one view, one default grant
On October 23, 2026 a builder posted that his Supabase app lost 35,000 profiles overnight. His own explanation: he “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.” He also shared a useful 10-point audit prompt. It is a very common setup, and it takes two ordinary decisions to land there:
- A view over a table that has RLS on, so the app can show other users’ profiles. Postgres views run as their owner, and on Supabase that owner is
postgres, which skips RLS. Supabase’s docs say it plainly: “Views bypass RLS by default because they are usually created with thepostgresuser.” - Default grants on a project that predates the new behavior. Supabase’s docs note that on existing projects a new table in
publicstarts with every privilege granted toanon,authenticatedandservice_role. Postgres default privileges for tables apply to views as well (we checked), so the view gotdeletetoo.
Put together, the public anon key, which is meant to ship in your frontend, can delete through the view as if RLS did not exist. (Supabase’s Oct 30, 2026 change doesn’t help here. It only affects new tables on projects created before May 30, 2026, and objects that already exist keep the grants they have.)
Reproduce it in under a minute
This runs on any Postgres, including a throwaway Supabase project. Use a test project, never production. We ran the same steps on an embedded Postgres 18 to check the output.
-- Test setup: a table with RLS on, and the legacy default grants
alter default privileges in schema public grant all on tables to anon, authenticated, service_role;
create table public.profiles (
id uuid primary key default gen_random_uuid(),
user_id uuid not null,
username text,
email text
);
alter table public.profiles enable row level security;
create policy "own rows" on public.profiles
for select to authenticated using ((select auth.uid()) = user_id);
insert into public.profiles (user_id, username, email) values
(gen_random_uuid(), 'alice', '[email protected]'),
(gen_random_uuid(), 'bob', '[email protected]'),
(gen_random_uuid(), 'carol', '[email protected]');
-- The "feature": let everyone see everyone's profile
create view public.public_profiles as
select id, user_id, username from public.profiles;
Now behave like an attacker holding only your public key (set role anon; in the SQL editor, or a REST call with just the anon key):
set role anon;
select count(*) from public.profiles; -- 0 (RLS works on the table)
select count(*) from public.public_profiles; -- 3 (the view skips RLS)
delete from public.profiles; -- 0 rows deleted (RLS holds)
delete from public.public_profiles; -- DELETE 3 (every row is gone)
reset role;
Over REST the last line is DELETE /rest/v1/public_profiles with the anon key. That is the whole attack.
Audit every view in your project
select
c.relname as view_name,
case c.relkind when 'm' then 'materialized view' else 'view' end as kind,
coalesce('security_invoker=true' = any(c.reloptions), false) as security_invoker,
has_table_privilege('anon', c.oid, 'select') as anon_can_select,
has_table_privilege('anon', c.oid, 'insert,update,delete') as anon_has_write_grant,
has_table_privilege('authenticated', c.oid, 'insert,update,delete') as authed_has_write_grant
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public' and c.relkind in ('v', 'm')
order by 1;
Read the result like this:
security_invoker = falseandanon_can_select = true: anyone with your public key can read through that view, whatever your table policies say.- Any
*_has_write_grant = true: remove it unless you can say why the view needs it. kind = materialized view: RLS can’t protect these at all. Revoke the grants or move them out ofpublic.
The fix, copy-paste
Replace public_profiles with your view. Put it in a migration so it’s reviewable.
-- 1. Views almost never need write access from the Data API
revoke insert, update, delete, truncate, references, trigger
on public.public_profiles from anon, authenticated;
-- 2. Make the view obey the caller's RLS (Postgres 15+)
alter view public.public_profiles set (security_invoker = true);
Re-run the attack:
set role anon;
delete from public.public_profiles; -- ERROR: permission denied for view public_profiles
select count(*) from public.public_profiles; -- 0 (RLS on the base table now applies)
reset role;
To do the same for every view in public at once, use this and review the output before you run it:
-- Revoke write grants on all views in public
select format('revoke insert, update, delete, truncate, references, trigger on public.%I from anon, authenticated;', c.relname)
from pg_class c join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public' and c.relkind = 'v';
-- Switch all views to security_invoker (Postgres 15+). Check each one still does what the app needs.
select format('alter view public.%I set (security_invoker = true);', c.relname)
from pg_class c join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public' and c.relkind = 'v';
But my app needs users to see each other’s profiles
With security_invoker = true, the view only returns rows the caller’s RLS policy allows, so a user would see only their own profile. That is the correct, safe behavior, and it will break the “see everyone” feature. Two safe ways to keep the feature:
Option A: a SELECT-only view of safe columns only (leave it as the owner’s view on purpose, but never expose private fields or write access):
create or replace view public.public_profiles as
select id, username, avatar_url -- no email, no private ids
from public.profiles;
revoke all on public.public_profiles from anon, authenticated;
grant select on public.public_profiles to authenticated; -- not anon, unless logged-out visitors must see it
We tested this too: an authenticated user can read username, nothing else is selectable, and any delete returns permission denied. Supabase’s Security Advisor will still flag the view as bypassing RLS. That finding is expected here, and you should accept it knowingly. The safety comes from the narrow columns and SELECT-only grant.
Option B: put the public fields in their own table with RLS on and an explicit read policy (for select to authenticated using (true) is fine here because the table only holds data meant to be public), kept in sync from profiles with a trigger. This lets the Advisor stay clean.
Stop it happening again
If your project is older than May 30, 2026 and still hands out default grants, run Supabase’s own opt-in statements now rather than waiting. They only change the defaults for future objects:
alter default privileges for role postgres in schema public
revoke select, insert, update, delete on tables from anon, authenticated, service_role;
alter default privileges for role postgres in schema public
revoke usage, select on sequences from anon, authenticated, service_role;
Then every new table or view needs an explicit grant, which makes access a deliberate decision. See Supabase’s Oct 30, 2026 change explained for the safe per-table pattern, and fix USING (true) policies for the other common way RLS gets bypassed. Functions marked security definer skip RLS the same way, and by default your anon key can call them: fix SECURITY DEFINER functions anyone can call. Files have their own version of this problem: fix a public Storage bucket that allows listing.
Prompt for Cursor, Lovable, Bolt or Claude Code
Audit every view and materialized view in the public schema of my Supabase project.
Assume the anon key is public. For each one report: is it security_invoker = true,
can anon or authenticated select it, and do they hold INSERT/UPDATE/DELETE/TRUNCATE.
Then, in one migration: revoke all write privileges on views from anon and authenticated,
set security_invoker = true wherever the view reads RLS-protected tables, and for any view
that must show other users' data, make it SELECT-only with only non-sensitive columns.
Never disable RLS. Show me the SQL and the audit table before running anything.
If something already went wrong: restore from a backup or point-in-time recovery if you have one, rotate your keys, and check the Security Advisor for other “View bypasses row-level security” findings before you re-open the app.
When to get help
Get help if your app has many views or RPC functions created by an AI tool, if you're not sure which views are meant to be public, if you already lost or exposed data and need to rotate keys and restore from backup, or if you need a review before launch.
Want us to look at your app?
VibeCPR Rescue Reports are launching soon: we scan your repo and live app, and a human verifies every critical finding. Join the waitlist for early access and founder pricing. You'll also get Patch Notes, our weekly fixes newsletter.
FAQ
Why does a Supabase view bypass Row Level Security?
Supabase's docs say views bypass RLS by default because they are usually created by the postgres user, which Postgres treats as a security definer view. The view reads the underlying table with the owner's rights, and the owner is not subject to your policies. A view over a protected table can therefore return every row.
What does security_invoker = true do?
On Postgres 15 and above, security_invoker = true makes the view run with the privileges of the person querying it instead of the owner. The RLS policies on the underlying tables then apply to anon and authenticated users. You set it with alter view public.your_view set (security_invoker = true) or when creating the view with (security_invoker = true).
Can the anon key really delete rows through a view?
Yes, if anon has a DELETE grant on the view and the view is simple enough for Postgres to treat as updatable. A simple single-table view is automatically updatable, and writes through it run as the view owner, which skips RLS on the base table. Revoking write grants on the view from anon and authenticated closes that path. We reproduced this on an embedded Postgres 18: with default grants an anon delete through a view removed every row, and after revoking and setting security_invoker the same request failed with permission denied.
Does the Oct 30, 2026 Supabase change fix this?
No. The October 30, 2026 change only affects new tables in the public schema on projects created before May 30, 2026: they will need an explicit GRANT before the Data API can see them. Existing tables and views keep their current grants. A view that already has anon write grants stays dangerous until you revoke them.
What happened in the 35,000 profiles incident?
On October 23, 2026 the builder Max Hirsch (@MaxHirsch13) posted that his app was hacked the night before and 35,000 profiles were wiped. In his words he bypassed RLS with a view so users could see each other's profiles and did not revoke Supabase's default anon permissions, so the public key could delete everyone through it. He published an audit prompt. We link his post as the primary source and have not independently verified anything beyond his own account.
What about materialized views?
Materialized views cannot respect RLS at all and cannot be secured with RLS, per Supabase's Security Advisor docs (lint 0016). If one is reachable by anon or authenticated, every row is visible. Revoke select on it from anon, authenticated and public, or move it out of the exposed schema.
Sources
- Supabase docs: Row Level Security (Views and RLS, Expose a view safely)
- Supabase Advisors: 0010 View bypasses row-level security (security_definer_view)
- Supabase changelog: Tables not exposed to Data and GraphQL API automatically
- Max Hirsch (@MaxHirsch13) on X: 35,000 profiles wiped via a view (Oct 23, 2026)
- PostgreSQL docs: CREATE VIEW (security_invoker)
Related fixes
- AI agent pushed API keys to GitHub? git commit --no-verify skipped your pre-commit hook
- Fix a surprise AI API bill: rate limits and spend caps
- Your app is public to anyone with the link: a share link is not a login
- Triage Bolt's "RLS Policy Always True" warning: when it's fine and how to fix it
- Fix secrets leaked via Claude Code .claude/settings.local.json
- Fix "Your Cloud Firestore database has insecure rules" (Firebase email)
- Login lockout keyed only on email? Rate-limit by IP and account without locking users out
- Fix Lovable "Invalid API key" after rotating Supabase keys (anon, publishable, secret)
- Lovable won't publish because of security findings? What each finding means and how to fix it
- "Sign in with Google" lets anyone in: restrict who can use your app (allowlist, domain check, RLS)
- Fix Stripe sk_live keys left in MCP or agent config
- Fix Stripe webhook "No signatures found matching the expected signature for payload"
- Fix Supabase auth redirecting to localhost after deploy
- Fix Supabase Edge Function "blocked by CORS policy" (preflight)
- Fix Supabase "infinite recursion detected in policy for relation" (42P17) in RLS
- Form says success but no row in Supabase (or Stripe webhook returns 200 but writes nothing)
- Fix "new row violates row-level security policy for table" (Supabase)
- Supabase only returns 1,000 rows? Fix the silent max rows limit in Lovable and Bolt apps
- Fix Supabase "permission denied for table" (42501) on new tables after Oct 30, 2026
- Fix a Supabase public Storage bucket that lets anyone list or download your files
- Supabase Realtime leaking rows or not receiving changes: fix RLS and the publication
- Supabase RLS not working on the server? Your API uses the service_role or secret key
- Fix Supabase RLS policy USING (true) that makes a table publicly readable
- Your app's rules only live in the frontend: move them into Supabase
- Fix a Supabase SECURITY DEFINER function anyone can call through /rest/v1/rpc
- Fix Supabase .single() "JSON object requested, multiple (or no) rows returned" (PGRST116)
- Stop Supabase users from upgrading their own plan or making themselves admin
- Fix "404: NOT_FOUND" on refresh in a React/Vite app on Vercel (vercel.json rewrite)
- Fix "Module not found: Can't resolve" on Vercel (works locally)
- Is my Vite dev server exposed? Check --host / server.host and patch the RCE (GHSA-p4f5-76q4-ffq7)