Skip to content
Supabase RLS

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.

1

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.

2

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.

3

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.

4

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.

5

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.

A 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.
A policy 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).
USING decides which existing rows a user may touch. WITH CHECK decides what the new row may look like. Supabase's example is a user who updates their own row and sets 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.
Anything in 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.
Views created by 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.
A security definer function runs with its owner's rights. Placed in an exposed schema, anyone allowed to execute it can call it over the API and reach data the policies were meant to block. Keep these functions in a private schema, set search_path = '', and grant execute only to the roles that need it.
Because permissive policies combine with OR, a strict "own rows" policy does nothing if a second policy on the same table allows more. The Security Advisor warns about multiple permissive policies. Read every policy on a table together, not one at a time.

Built with Lovable, Bolt or v0 and about to take real users?

Finish and fix covers this check and the rest of what stands between a demo and launch: access rules on every table, secret keys out of the browser, payment webhooks, hosting, backups tested by restoring them, and monitoring. It starts with a free 20-minute teardown, with the owner's consent, and you get a written scope and price before any paid work. From €3,000, excl. VAT.
See Finish and fix

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.

Sign up two test users, A and B, and create a few rows as each one: an order, a message, a profile. Signed in as A, open the browser's developer tools and repeat the app's own requests with B's row IDs. Try to read, change and delete. Then sign out and try again. A correct setup returns nothing or an error every time.

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.

When a USING clause filters a row out, Postgres raises nothing; the statement simply matches zero rows. A missing grant or a failed WITH CHECK raises error 42501. So an update that "worked" without an error may have changed nothing, and a read that returns nothing may be the policy working. Add returning to writes and check what came back.
Each change an AI tool makes can add a table, a view or a function. Lovable runs its Quick scan, which checks database access rules, on every publish, and its own docs say automated scans cannot guarantee complete security. Keep your two-user test and run it again before each release, and take a backup you know restores before any large change: see Supabase backups and a restore drill.

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.

The publishable key (or legacy anon key), yes: Supabase designs it to be public and to reach only what RLS allows. A secret key or legacy service_role key, never. If one has been in front-end code, a public repository or a prompt history, rotate it.
That is default deny: RLS is on and no policy allows the request yet. Add a policy for each operation the app needs, scoped to the right role and the row's owner. Do not fix it with using (true).
It depends on the key. A client created with a secret key bypasses RLS, but Supabase notes that if the request also carries a user's access token, it runs under that user's policies. A function that uses a secret key has to make its own permission checks before it reads or writes.
It can on large tables. Supabase recommends an index on every column a policy filters on, and wrapping auth.uid() as (select auth.uid()) so it is evaluated once per statement instead of once per row.
It is a good first pass, and it checks database access rules on every publish. Lovable's documentation says automated scans cannot guarantee complete security and suggests a professional review for apps with sensitive data. A scan also cannot know your business rules, such as who on a team may see which rows. Webnorly is independent of Lovable and does not speak for it.
RLS is one technical measure among several. It helps you show who can read which data, which is useful readiness evidence. Whether your app meets the law is a legal question, and this guide is not legal advice.
Yes, if you own the app or the owner agrees. It starts with a free 20-minute teardown, and Finish and fix starts at €3,000. See Finish and fix for Lovable apps.

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.

Before real users sign in

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.