Supabase RLS: check that every table is locked before real users arrive.
Your app's publishable key sits in the browser for anyone to read. That is by design. What keeps one user out of another user's rows is row level security, and the grants behind it. This guide gives you the SQL to find the gaps, the policy mistakes to look for, and a way to test as two real users. You can do all of it yourself in an afternoon.
First: the key in your browser is not the lock
Supabase says it plainly: the publishable key (the old anon key) is safe to ship because it only reaches what row level security allows. So if a table has RLS off, or a policy that lets everyone in, anyone who copies that key from your site can query the table directly, without using your app at all. Hiding a button or a page in the front end changes nothing. Check your own app, or an app whose owner has asked you to, and run every query below on a copy or with read-only statements first.
What RLS actually does in a Supabase app.
Row level security is a Postgres feature, and Supabase builds on it. Five facts explain almost every gap you will find.
Every request has a role
A request with the publishable key and no signed-in user runs as anon. The same key with a signed-in user runs as authenticated. A secret key (the old service_role key) runs as service_role, which has the BYPASSRLS attribute and skips every policy.
Grants come first, policies second
Postgres checks two things. Grants decide whether a role may select, insert, update or delete on the table at all. Policies decide which rows that applies to. On existing Supabase projects, a new table in public grants every privilege to all three roles, and adding policies does not take those grants back.
RLS on, no policy: nothing gets through
Postgres uses default deny. Once RLS is on and no policy exists, the API returns no rows to the publishable key. That is the safe failure. The dangerous one is the opposite: RLS off, where any role with a grant can read and change every row.
Policies add up with OR
Policies are permissive by default, and Postgres combines permissive policies with OR. One careful policy and one loose policy on the same table means the loose one wins. Restrictive policies combine with AND and can narrow what the permissive ones allow.
Where the table came from matters
Supabase turns RLS on by default for tables created in the Dashboard. Tables created in the SQL Editor, by a migration or by another tool need it enabled explicitly. AI tools usually create tables with SQL, so do not assume.
The owner skips the rules
Table owners normally bypass RLS, and Supabase's guide notes that the postgres role has bypassrls. A query run as postgres shows every row whatever your policies say. Seeing data in the SQL Editor tells you nothing about what a user can see.
The check, in five steps.
Do them in this order. Steps 1 to 3 read the database catalog and change nothing. The queries for each step are in the next section.
Run the Security Advisor
In the Supabase Dashboard, open Advisors, then Security Advisor, or run supabase db advisors. It flags tables in public with RLS off (level ERROR), policies that are always true, RLS with no policy, security definer views and policies that read user_metadata. Write down every finding.
List tables and their RLS state
Query the catalog for every table in the schemas your API exposes, with RLS on or off. Any table with RLS off that holds anything but public data is the first thing to fix.
Read every policy
List the policies with their role, command and expressions. You are looking for true, a check that someone is signed in but not that the row is theirs, and UPDATE or INSERT policies with no WITH CHECK.
Write down who may see what
For each table, one line per rule: a signed-out visitor may read published posts; a signed-in user may read and change only their own orders. Supabase's own testing guide starts here, because a policy can only be judged against a rule.
Test as two users
Create two test accounts. As user A, try to read, change and delete user B's rows, and try to create a row in B's name. Then repeat signed out. Every attempt that should fail must fail.
The SQL for each check.
Paste these into the SQL Editor or psql. They read the Postgres catalog only. Add your other exposed schemas next to public if your API exposes more than one.
This lists every ordinary and partitioned table in public, with RLS and forced RLS. Any row where rls_on is false is open to every role with a grant.
select c.relname as table_name,
c.relrowsecurity as rls_on,
c.relforcerowsecurity as rls_forced
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public'
and c.relkind in ('r', 'p')
order by c.relrowsecurity, c.relname;To fix one: alter table public.orders enable row level security; Then add the policies it needs, or the app stops seeing that table.
The view pg_policies shows each policy's roles, command and expressions. qual is the USING expression, with_check the WITH CHECK expression.
select tablename, policyname, permissive, roles, cmd, qual, with_check
from pg_policies
where schemaname = 'public'
and (qual = 'true' or with_check = 'true')
order by tablename;An always-true policy is fine only on data that is meant to be public, such as published blog posts. On profiles, orders or messages it hands every row to every role the policy names.
A policy can stop signed-out visitors and still let every signed-in user read every other user's rows. List the policies that never compare the row to the user:
select tablename, policyname, roles, cmd, qual, with_check
from pg_policies
where schemaname = 'public'
and coalesce(qual, '') not ilike '%auth.uid()%'
and coalesce(with_check, '') not ilike '%auth.uid()%'
order by tablename;Not every result is wrong: a shared table may check team membership through a function instead. Read each one against the rule you wrote down in step 4.
These are safe but empty for your users. If a feature quietly shows nothing, this is often why, and the temptation is to "fix" it with a true policy. Write a real one instead.
select c.relname as table_name
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public'
and c.relkind in ('r', 'p')
and c.relrowsecurity
and not exists (
select 1 from pg_policies p
where p.schemaname = 'public' and p.tablename = c.relname
); Policies only filter rows for a role that already holds a grant. This shows which write grants anon still has on each table:
select table_name,
has_table_privilege('anon', format('public.%I', table_name), 'insert') as can_insert,
has_table_privilege('anon', format('public.%I', table_name), 'update') as can_update,
has_table_privilege('anon', format('public.%I', table_name), 'delete') as can_delete
from information_schema.tables
where table_schema = 'public' and table_type = 'BASE TABLE';Supabase's guide revokes everything from anon and authenticated, then grants back only what each role needs, in the same migration that enables RLS.
Seven policy mistakes to look for.
Each of these passes a quick glance: RLS is on and a policy exists. All of them are described in Supabase's and Postgres's own documentation.
using (true) policy added to make a feature work during the build, and never replaced. Supabase's Security Advisor has a lint for exactly this, and lists forgotten placeholders and copy-paste from examples among the usual causes. to authenticated using (true), or one that only checks that auth.uid() is not null, lets every user with an account read every row. On an app with open sign-up, anyone can make an account in a minute. Compare the row to the user: using ((select auth.uid()) = user_id). user_id to someone else's. Give INSERT a WITH CHECK, and UPDATE both clauses. Note also that an UPDATE needs a matching SELECT policy to work as expected. raw_user_meta_data can be changed by the signed-in user. A policy that grants admin rights when user_metadata says "admin" lets any user make themselves admin. Store roles in raw_app_meta_data or a table the user cannot write. And remember that a role in the token does not change until the token refreshes. postgres run with its rights and bypass RLS by default, so a view can hand out every row the table's policies hold back. On Postgres 15 and later, create views with security_invoker = true, or keep them out of exposed schemas. search_path = '', and grant execute only to the roles that need it. Test as two users, not as the owner.
Reading policies finds the obvious gaps. Only a test shows what a user can really do. Supabase's testing guide warns that a check on pg_policies can pass while the policy is still wrong.
Inside a transaction, you can act as a role and a user the way a real request does, then roll back so nothing is kept:
begin;
set local role authenticated;
set local request.jwt.claim.sub = '<user A id>';
select * from public.orders; -- A's rows only
update public.orders set note = 'x'
where user_id = '<user B id>'
returning id; -- should return nothing
rollback;Supabase recommends turning this into pgTAP tests under supabase/tests/, one file per table, run with supabase test db.
returning to writes and check what came back. A worked example: CVE-2025-48757.
In 2025 a weak RLS setup in apps generated by Lovable got its own CVE. It shows how the gaps above play out, using only the public record.
What the record says
The NVD entry, published on 30 May 2025, describes an insufficient row level security policy in Lovable through 15 April 2025 that let remote attackers without an account read or write arbitrary tables of generated sites. NVD also records that Lovable disputes it, on the grounds that each customer is responsible for protecting their own app's data.
How it worked
The reporter's write-up describes direct requests to the database endpoints using the public, unprivileged anon key, with no need to go through the app. Tables without fitting policies returned their rows, including personal data and stored API keys for other services, and some accepted writes.
Which checks catch it
Step 2 finds tables with RLS off. Step 3 finds policies that let the anon role read everything. The anon grant query shows where writes were possible. None of this needs access to the app's code.
What it means for your app
Whoever is right about the dispute, the practical answer is the same: the app owner holds the data and carries the risk. A generated app needs its policies read and tested against its own rules before real users sign up, whichever tool wrote it.
Questions about Supabase RLS.
using (true). auth.uid() as (select auth.uid()) so it is evaluated once per statement instead of once per row. Sources
Last checked 17 November 2026. Supabase changes defaults and key types over time, so check the current documentation before you rely on a detail.
Supabase: Row Level Security Grants and policies, roles, views, WITH CHECK, user_metadata, security definer functions, bypassing RLS.
Supabase: Testing RLS policies Rules first, then tests as each role.
Supabase: API keys Publishable and secret keys and the role each one maps to.
Supabase: Securing your API Default privileges, and when RLS is on by default.
Supabase: Advisors The Security Advisor checks named in step 1.
PostgreSQL: Row Security Policies Default deny, owners and BYPASSRLS, OR and AND.
PostgreSQL: pg_policies The columns the SQL checks read.
NVD: CVE-2025-48757 and the reporter's write-up The worked example.
Lovable: Security view What the Quick scan checks, and its limits.
Book a free teardown.
Tell us what your app does and what worries you. With the owner's consent, we spend 20 minutes on its riskiest part, often who can read which data, and tell you what to fix first.