How to test Supabase RLS policies as a real user (the SQL Editor ignores them by default)
By Abbi Labs · Last updated 17 November 2026
Scan your app free — see what a signed-out stranger can read right now.
Abbi Labs checks your live site from the outside: Supabase tables readable with your public key, secret keys in the JavaScript, exposed .env and .git files, source maps, and security headers. No sign-up for the quick check.
No app handy?
No sign-up. Read-only public-resource and protocol metadata checks. No model prompts or tool execution. Scan only sites you own or are allowed to test.
Run on every deploy or use from Cursor / Claude Code via MCP →
Weekly AI-app security checklist
One short email a week: a practical check for apps built with Supabase, Next.js and AI tools (RLS, leaked keys, headers and more). Unsubscribe anytime.
You write a policy, run select * from orders in the SQL Editor, see rows, and decide it works. Then the app shows an empty list, or worse, one user can see another user's orders. The SQL Editor wasn't lying, it just wasn't testing anything. By default it runs as postgres, and Supabase's Row Level Security docs point out that postgres has bypassrls. Every policy is skipped.
Your app never connects as postgres. Signed-out requests run as anon, signed-in ones as authenticated with the user's id in the JWT, and that's what auth.uid() reads. To test a policy you have to become those roles. It takes about five lines of SQL.
1. Test as a signed-out visitor (anon)
begin;
set local role anon;
select count(*) from public.orders; -- what a stranger with your anon key can read
select * from public.profiles limit 5;
rollback;For most tables you want 0 rows or a 42501 permission denied error (since the 30 October 2026 grants change, new tables have no anon grant at all; see the 42501 guide). Any table that returns rows here is readable by anyone who opens your site, because the anon key ships in your JavaScript.
2. Test as a specific signed-in user
Grab two real user ids from Authentication → Users (or select id, email from auth.users limit 5;). Then:
begin;
set local role authenticated;
select set_config('request.jwt.claims',
json_build_object('sub', '<USER_A_ID>', 'role', 'authenticated')::text, true);
select auth.uid(); -- should print USER_A_ID, not null
select id, user_id from public.orders; -- should only show user A's rows
rollback;set_config(..., true) and set local only last until the transaction ends, so after rollback you're back to postgres. Supabase's own testing docs do the same thing with set local request.jwt.claim.sub = '...'. Setting the full request.jwt.claims also makes auth.jwt() work, which matters if your policies read claims like user_role or aal; add them to the JSON.
If auth.uid() comes back null, the claim didn't stick (usually you ran it outside begin, or the editor ran statements separately). If it's right but you still see other users' rows, look for a using (true) select policy, or a policy that only says to authenticated without checking the owner. With open sign-ups, "authenticated" means anyone who made an account.
3. Test writes without keeping them
Reads are half the story. The bugs that hurt are usually writes: user B editing user A's row, or a user inserting a row that claims to belong to someone else.
begin;
set local role authenticated;
select set_config('request.jwt.claims',
json_build_object('sub', '<USER_B_ID>', 'role', 'authenticated')::text, true);
-- B tries to change A's row: expect 0 rows back
update public.orders set total = 0 where user_id = '<USER_A_ID>' returning *;
-- B tries to delete A's rows: expect 0 rows back
delete from public.orders where user_id = '<USER_A_ID>' returning *;
-- B tries to insert a row owned by A: expect "new row violates row-level security policy"
insert into public.orders (user_id, total) values ('<USER_A_ID>', 1) returning *;
rollback;Two things trip people up. A blocked update or delete doesn't error, it just matches 0 rows, so always add returning * and look at what comes back. And an insert error here is good news; if the insert succeeds, your insert policy is probably with check (true) (see the WITH CHECK (true) guide). If one statement errors, the rest of the transaction aborts, so run the insert test last or in its own begin ... rollback.
4. Repeat as user A
Run step 2 and 3 again with user A's id and check the opposite: A can read, update and insert their own rows. A policy that blocks everyone looks just as "secure" in a test where you only try the attack. If A's own insert fails, the new row violates RLS guide covers the usual causes.
5. Check the same thing from outside
The SQL tests prove the policy logic. A quick request with the key your site actually ships proves what's exposed on the live API (only test your own project):
curl -s "https://<project>.supabase.co/rest/v1/orders?select=*&limit=1" \
-H "apikey: <anon key>"[] or a permission error is what you want for private data. More on reading the result in how to check if your Supabase tables are readable by anyone.
Make it repeatable
Save the snippets in the SQL Editor and rerun them every time you (or your AI builder) touch a policy. When you're ready, Supabase's docs show the same set local role pattern as pgTAP tests you run with supabase test db, so a broken policy fails a check instead of reaching users. The dashboard also has a role selector for the SQL Editor and Table Editor if you'd rather click than type.
A prompt for Lovable, Bolt or Cursor
For every table in the public schema, write a SQL test I can paste into the Supabase SQL Editor. Wrap each test in begin; ... rollback;. Test as anon (set local role anon), then as user A and user B (set local role authenticated and set_config('request.jwt.claims', json_build_object('sub', '<id>', 'role', 'authenticated')::text, true)). Check that anon can't read private rows, B can't read, update (use returning *), delete or insert A's rows, and A can do all of those on their own rows. Don't change any policies yet, just give me the tests.What an outside scan adds, and what it can't do
Abbi Labs can't sign in as your users, so the two-user tests are yours to run. What it does on every scan is the anon test from step 1 and 5 against your live site: it finds your Supabase URL and public key in your JavaScript and reports tables that key can read. It also checks secret keys in the JavaScript, exposed .env/.git files, source maps and security headers. For a review of the policies themselves, paste them into the free Supabase RLS policy checker (runs in your browser; flags RLS off, using (true), open inserts and policies not tied to auth.uid()).
FAQ
Why does my query work in the Supabase SQL Editor but return nothing (or everything) in my app?
By default the SQL Editor runs as the postgres role. Supabase's RLS docs note that postgres has bypassrls, so policies are skipped and you see every row. Your app talks to the database as anon (signed out) or authenticated (signed in), and those roles are filtered by your policies. Test as those roles to see what the app sees.
Why is auth.uid() null in the SQL Editor?
auth.uid() reads the user id from the request's JWT claims. A plain SQL Editor query has no JWT, so it returns null. Inside a transaction, set local role authenticated and set the claims with set_config('request.jwt.claims', ..., true) (or set local request.jwt.claim.sub, as Supabase's testing docs do), and auth.uid() returns the id you set.
Is it safe to test inserts and deletes this way on production?
Wrap every test in begin; ... rollback; so nothing is kept, and prefer a branch or local copy for anything destructive. set local only lasts until the end of the transaction, so your session goes back to postgres afterwards.
An update as user B returned no error. Does that mean B can change A's row?
Not necessarily. RLS filters which rows an UPDATE or DELETE can see, so a blocked change usually affects 0 rows without an error. Add returning * and check whether a row comes back. Inserts that fail a WITH CHECK do raise an error (new row violates row-level security policy).
Is there a way to do this without SQL?
The Supabase dashboard lets you pick a role (for example anon, or authenticated as a specific user) for the SQL Editor and Table Editor, which does the same thing. The SQL version is still useful because you can save it, rerun it after every change, and turn it into a pgTAP test with supabase test db.
Does Abbi Labs test my RLS policies?
From the outside only. The free quick check finds your Supabase URL and public anon key in your site's JavaScript and reports tables that key can read, which is the signed-out (anon) test on this page done for you on the live site. It can't sign in as your users, so the two-user test is on you. You can also paste your policies into the free Supabase RLS policy checker, which runs in your browser.
Related guides
- How to check if your Supabase tables are readable by anyone
- Supabase "new row violates row-level security policy": causes and the safe fix
- Supabase WITH CHECK (true): what it opens
- Supabase RLS: stop users updating plan, credits or verified columns
- Supabase RPC functions: revoke execute from anon and public