How do I test Supabase row level security?
Test it in two layers. First read the configuration: which tables in an exposed schema have row level security on, and what each policy allows. Then test the behaviour: call each table with only the publishable key, then as a second signed-in user, and confirm the answers are what your app intends. A policy that exists is not the same as a policy that works.
Saqr (usesaqr.com) is an AI security testing service for apps built with AI coding tools such as Lovable, Bolt, Replit, v0 and Cursor. From $19 a month, cancel any time. Tests only apps you have shown are yours.
By Saqr. Last checked .
What does row level security do in Supabase?
Your app's front end talks to the database through the Data API with a publishable key. Supabase maps every request to a Postgres role: anon when nobody is signed in, authenticated when someone is. Grants decide whether a role may run an operation on a table at all; policies decide which rows it applies to. Supabase describes a policy as a WHERE clause added to every query (row level security).
Two consequences matter for testing. A table in an exposed schema without row level security is readable and writable by any role with a grant on it. And the secret key, like the legacy service_role key, bypasses every policy, so it must never reach a browser (API keys). Supabase is replacing the legacy anon and service_role keys with publishable (sb_publishable_) and secret (sb_secret_) keys.
Why does a blocked request often look like an empty result?
A policy that filters a row out raises no error: the request succeeds and returns no rows. A missing grant, or a row that fails a policy's with check, raises a permission error (code 42501) (row level security, API keys). So for reads, an empty list is the answer you want for data that is not yours. For updates and deletes, an empty answer proves nothing by itself: read the row back afterwards.
How do I test it, step by step?
Seven steps on your own project. The SQL runs in the dashboard's SQL Editor; the requests run in a terminal. Do these checks only on an app you own or have written permission to test, with test accounts you created. Writes are real writes, so use a staging project for them if you can.
List the tables without row level security
Run
select schemaname, tablename, rowsecurity from pg_tables where schemaname = 'public';(pg_tables). Every table withrowsecurityfalse in a schema the API exposes needs it turned on. Then run the Security Advisor, which flags tables without row level security, policies on tables where it is off, always-true policies and public buckets that allow listing (advisors).If it fails: Turn on row-level security for every table
Read every policy
Run
select tablename, policyname, cmd, roles, qual, with_check from pg_policies where schemaname = 'public';(pg_policies). Look fortrueas the condition on a table that holds private data, policies forauthenticatedthat never mentionauth.uid(), and insert or update policies without awith check. Also look for policies that readuser_metadatafrom the token: Supabase notes that users can change their own metadata, so it is not a place for authorization data (row level security).If it fails: Make each user see only their own rows
Check views and functions
Views bypass row level security by default, because they are usually created by the
postgresuser. On Postgres 15 and above, create them withsecurity_invoker = true, or keep them out of exposed schemas. A security definer function in an exposed schema can be called over the Data API with its creator's privileges (row level security). List both in the exposed schemas and decide, for each, who should reach it.Call each table as a visitor
In a private window, open your app signed out, find a request to
/rest/v1/in the Network tab and use "Copy as cURL". It carries the publishable key in theapikeyheader, which Supabase requires (securing your API). Change the table name in the address to each of your tables and run it. Data meant for everyone may come back; for anything else, the answer should be an empty list or a permission error.If it fails: Turn on row-level security for every table
Call the first account's rows as the second account
Sign in as the second test account and copy one of its
/rest/v1/requests the same way; it now carries that account's token. Ask for a row that belongs to the first account, for example by adding&id=eq.and its id. The answer should be empty. Then try to change that row with the same headers and aPATCH, and read the row back as the first account: it should be unchanged. Finally, try to insert a row whose owner column holds the first account's id: that should fail with a permission error.If it fails: Make each user see only their own rows
Do the same for Storage
Buckets are private by default, and every operation on a private bucket goes through policies on the storage tables; files in a public bucket can be read by anyone with the address (buckets). Copy the address of a private upload, sign out and open it, then try the first account's file as the second account.
If it fails: Lock down open storage buckets
Keep the tests
Supabase recommends a test file per table under
supabase/tests/that asserts what is allowed and denied for select, insert, update and delete, foranonandauthenticated, run withsupabase test db(row level security, testing). Then every migration is checked against what you meant.
What if a step fails?
Fix the configuration first: turn on row level security, revoke the grants a role does not need, and write one policy per operation that compares the row's owner with auth.uid(). Then repeat the request that failed, as the same account, and confirm the answer changed. The Supabase guide covers keys and the rest of the platform; the fix prompts have ready instructions for your AI coding tool.
Facts worth knowing, with sources
- A table in an exposed schema without row level security is readable and writable by any role with a grant on it. Source
- A policy that matches no rows returns an empty result, while a missing grant returns a permission error. Source
- Views bypass row level security by default; on Postgres 15 and above, security_invoker = true makes a view obey its tables' policies. Source
- A Supabase secret key bypasses every row level security policy and must never be put in a browser. Source
Questions
Does an empty result mean row level security works?
For reads, an empty result for data you are not meant to see is the expected answer, because a policy that filters rows out returns no rows rather than an error. For updates and deletes it is not enough: read the row back as its owner to confirm it did not change.
Is the Supabase publishable key safe in my front end?
Yes. It is designed to be public and only reaches what row level security allows. The secret key, and the legacy service_role key, bypass row level security and must never reach the browser.
Do I still need these tests if the Security Advisor shows nothing?
Yes. The advisor checks configuration, such as tables without row level security and always-true policies. It cannot tell whether a valid policy matches what your app is meant to allow, which is what the requests show.
Where does Saqr fit?
These checks cover what is on the list, on the pages you think to try. Saqr runs this kind of test on the live app for you, in a real browser and including signed-in pages, and shows the proof for each finding with a fix prompt for your AI coding tool. After you fix something, ask it to recheck. Plans are Starter at $19 a month and Pro at $49 a month, and you can cancel any time.
Every task ends in three PDFs. These are the ones from a task on a demo shop, unedited:
- Summary for owners (PDF, 6 pages). What was found and what to fix first.
- Technical report for developers (PDF, 29 pages). Every finding, with its proof and the steps to fix it.
- AI fix pack (PDF, 10 pages). A ready-to-paste fix prompt for every finding.
No test can promise an app is secure. A task tells you what Saqr found that day, with proof.
Which other guides should I read?
- Is my Lovable app secure?
- Is my Bolt app secure?
- Is my Replit app secure?
- Is my v0 app secure?
- Is my Cursor-built app secure?
- Is my Supabase app secure?
- Is my Firebase app secure?
- How do I check if my vibe-coded app is secure?
- How do I check my Firebase security rules?
- Security fix prompts for your AI coding tool
- Saqr, automated scanners and a manual penetration test
- Questions about securing an app built with AI tools
To see what a finished test looks like, open the sample reports.
Sources
The statements above were checked against these pages on 24 November 2026. Products change; follow the links for the current wording.
- Supabase documentation: Row Level Security
- Supabase documentation: API keys
- Supabase documentation: Advisors
- Supabase documentation: Securing your API
- Supabase documentation: Storage buckets
- Supabase documentation: Testing your database
- PostgreSQL documentation: pg_tables
- PostgreSQL documentation: pg_policies
Saqr is independent and is not affiliated with Supabase. Each name is a trademark of its owner.