How to check Row Level Security in Supabase before launch
Short answer: before you launch, check three things. First, Row Level Security (RLS) is turned on for every table your app exposes, which on most projects means every table in the public schema. Second, each policy allows only what you meant it to allow, and the table grants match. Third, a test with two separate accounts shows that one user cannot read or change the other user's rows. Supabase's Security Advisor catches many common gaps, but only the two-account test tells you whether the rules match how your app is supposed to work.
This guide is for you if you built an app with an AI tool, the data lives in Supabase, and you are not sure what the generated rules actually do.
Why this matters for an app built with AI tools
Your app's frontend talks to Supabase with a publishable key (older projects call it the anon key). Supabase says this key is safe to expose because anyone can read it from the browser, and it only reaches what RLS allows. That last part is the point: once your code is in the browser, RLS is the rule that decides what a stranger with that key can do.
The Supabase docs are direct about the risk. A table in an exposed schema without RLS "is readable and writable by any role with a grant on it." Their Security Advisor rates this as an error and describes it this way: anyone with your project URL can read, edit and delete the data in that table.
RLS being "on" is not the whole story either. A policy that says using (true) lets every user with that role through, and Supabase notes that adding policies does not remove the table grants that were already there.
Step 1: Run the Security Advisor
Open your project in the Supabase Dashboard and run the Security Advisor. If you use the command line, Supabase documents supabase db advisors for the same checks.
Look first for these findings, which come from Supabase's own lint list:
| Finding | What it means in plain English |
|---|---|
0013_rls_disabled_in_public (ERROR) | A table in public has RLS off. Anyone with the project URL can read and change it. |
0023_sensitive_columns_exposed (ERROR) | Same as above, and the table has columns that look like passwords, tokens or personal identifiers. |
0010_security_definer_view (ERROR) | A view ignores the RLS rules of the tables underneath it. |
0015_rls_references_user_metadata (ERROR) | A policy trusts user_metadata, which users can edit themselves. |
0024_permissive_rls_policy (WARN) | A policy uses an always-true condition such as using (true). |
0007_policy_exists_rls_disabled (INFO) | You wrote a policy, but RLS is off, so the policy does nothing. |
0008_rls_enabled_no_policy (INFO) | RLS is on and no policy exists, so the API returns nothing for that table. |
Supabase also says some findings may be intentional. A public blog table with using (true) for reading can be fine. The advisor does not know which data you meant to be public. You do.
If you built on Lovable, Lovable runs its own database review every time you publish and you can read every policy under More → Database → Manage → Policies. That view is read-only. To change a policy, Lovable asks you to request it in the project chat.
Step 2: List your tables and their RLS status
In the Supabase SQL Editor, this read-only query lists every table in public and whether RLS is on. The rowsecurity column comes from the standard PostgreSQL pg_tables view.
select schemaname, tablename, rowsecurity
from pg_tables
where schemaname = 'public'
order by tablename;Any row with rowsecurity = false needs attention. If your app exposes other schemas through the API, run it for those too.
Step 3: Read what each policy actually allows
This read-only query lists your policies. The columns come from the PostgreSQL pg_policies view.
select tablename, policyname, roles, cmd, qual, with_check
from pg_policies
where schemaname = 'public'
order by tablename, cmd;How to read it without being a database expert:
rolessays who the rule applies to.{anon}means signed-out visitors.{authenticated}means any signed-in user, including someone who just created an account.{public}means the policy did not name a role. Supabase recommends always naming the role withto.cmdis the action:SELECT(read),INSERT,UPDATE,DELETE, orALL.qualis the condition for existing rows. If it readstrueon a table with private data, every user in that role can see every row.with_checkis the condition for new or changed rows. ForUPDATE,usingchecks the existing row andwith checkchecks the changed row. PostgreSQL reuses theusingcondition whenwith checkis omitted; omission alone is not a vulnerability. A missing or overly permissive ownership condition can allow reassignment. Supabase's update example makes ownership explicit in both clauses.- If
qualmentionsuser_metadata, flag it. Supabase warns that users can change that field themselves.
A typical safe pattern for "users can only see their own rows" looks like this in Supabase's docs:
create policy "Users can view their own profile."
on profiles for select
to authenticated
using ( (select auth.uid()) = user_id );Step 4: Check the grants, not only the policies
Supabase runs two checks on every request. Grants decide whether a role can touch a table at all. Policies decide which rows. On many existing projects, new tables in public start with every privilege granted to anon and authenticated, and adding policies does not take those grants back.
This read-only query asks PostgreSQL directly what the two client roles can do on each table and view in public, whoever granted the access. It uses the standard has_table_privilege function.
select c.relname as table_name, r.role,
has_table_privilege(r.role, c.oid, 'SELECT') as can_select,
has_table_privilege(r.role, c.oid, 'INSERT') as can_insert,
has_table_privilege(r.role, c.oid, 'UPDATE') as can_update,
has_table_privilege(r.role, c.oid, 'DELETE') as can_delete,
has_table_privilege(r.role, c.oid, 'TRUNCATE') as can_truncate
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
cross join (values ('anon'), ('authenticated')) as r(role)
where n.nspname = 'public'
and c.relkind in ('r', 'p', 'v', 'm', 'f')
order by 1, 2;If anon can INSERT, UPDATE, DELETE or TRUNCATE on a table that signed-out visitors should never write to, that is worth fixing, even if your policies look right. TRUNCATE deserves special attention: PostgreSQL says operations that apply to the whole table, such as TRUNCATE, are not subject to row security, so a role with that privilege can empty the table even when your policies are perfect.
Step 5: Test with two accounts
This is the step that tells you whether the rules match your app. Do it in a test or staging project with fake data, never with real customer data.
- Create two test users, A and B.
- Sign in as A and create a few records: an order, a note, an uploaded file, whatever your app stores.
- Sign out and sign in as B.
- Try to reach A's records. Open the page that shows a record and change the record ID in the URL to one of A's. Try the same for edit and delete.
- Sign out completely and repeat as a visitor who is not signed in.
Each attempt should fail or show nothing. Write down what you tried and what happened. A hidden button in the interface is not an access rule. The rule has to hold even when someone calls the API directly.
If you or your developer can use the Supabase CLI, Supabase recommends turning these checks into SQL tests that run with supabase test db, using set local role and a test user ID to act as each user. Their RLS guide includes full example test files.
Step 6: Fix with care
If a table has RLS off, the fix Supabase documents is:
alter table public.your_table enable row level security;Two cautions before you run any change:
- Once RLS is on and no policy exists, the API returns no data for that table. Your app may stop showing that data until you add the right policies. Test the change in a staging project or a branch first.
- Server code that uses the secret key (or the older
service_rolekey) skips RLS completely. Supabase and Lovable both say that code must check permissions itself. Fixing RLS does not fix a server function that reads data for the wrong user.
On Lovable, you can describe the rule you want in the project chat, for example "users can only read and edit their own orders", and then repeat Step 5 to confirm the result.
What this check does not cover
RLS protects rows in your database. It does not protect secret keys in your frontend code, server functions that skip authorization, files in public storage buckets, or your login settings. Supabase's production checklist also asks you to turn on email confirmations, protect your own Supabase account with multi-factor authentication, and think about how someone could abuse your service.
FAQ
Is my publishable or anon key a secret?
No. Supabase designs it to be public. It is only safe when RLS is on and the policies are correct, because anyone can use it to send requests to your project.
RLS is on for every table. Am I done?
Not yet. A policy with using (true) or a missing ownership check can still let one user read another user's data. Read the policies (Step 3) and run the two-account test (Step 5).
Does the Security Advisor find everything?
No tool does. Supabase describes the advisors as deterministic checks for common problems and says to review each finding against your intended access model. Lovable's docs also say its scans "cannot guarantee complete security."
I use views. Do they follow RLS?
Not by default. Supabase says views bypass RLS unless you create them with security_invoker = true on Postgres 15 or newer.
Try the Liquid sandbox
If your app also has server code or Edge Functions written in JavaScript or TypeScript, the sandbox can give that code a first look. It does not check RLS policies, which is what this guide is about.
You can paste JavaScript or TypeScript code you own, including JSX and TSX, up to 12,000 bytes and with no real keys or personal data, into the Liquid code review sandbox. It reads the code in your browser without running it and without sending it to a server, with no signup, no upload and no saved history. It checks 8 fixed rules: eval or other dynamic code, shell commands, disabled TLS certificate checks (rejectUnauthorized: false), MD5 or SHA-1 (for information only), and request data reaching a network call, a SQL string, HTML output, or the choice of which database record to load. It reuses the product's single-file AST rules and some credential-like patterns. A match is a lead to review, not proof of a leak, and no match does not mean your code has no secrets. It does not check Supabase RLS, buckets or settings, check dependencies, read a repository or a live site, or confirm a fix. A result is a starting point for review and never approves code for production.
Sources
- Supabase Docs: Row Level Security (checked 2026-10-22).
- Supabase Docs: Advisors (Security Advisor lint list) (checked 2026-10-22).
- Supabase Docs: API keys (checked 2026-10-22).
- Supabase Docs: Production checklist (checked 2026-10-22).
- Supabase Docs: Testing your database (checked 2026-10-22).
- PostgreSQL 18 Docs: pg_tables view (checked 2026-10-22).
- PostgreSQL 18 Docs: pg_policies view (checked 2026-10-22).
- PostgreSQL 18 Docs: Access privilege inquiry functions (has_table_privilege) (checked 2026-10-22).
- PostgreSQL 18 Docs: Row Security Policies (TRUNCATE is not subject to row security) (checked 2026-10-22).
- Lovable Docs: Security best practices for Lovable apps (checked 2026-10-22).
- Lovable Docs: Security overview (Quick scan on publish, no guarantee of complete security) (checked 2026-10-22).
- Lovable Docs: Control who can access your app's data (read-only policies view) (checked 2026-10-22).
- Liquid: /sandbox page (what the sandbox does) (checked 2026-10-22).
- PostgreSQL: CREATE POLICY (checked 2026-11-06).