Row level security (RLS) decides which rows each request to your Supabase database gets back, and it fails quietly. A read it blocks returns no rows. An update it blocks changes nothing. Neither raises an error, so a policy that's wrong looks exactly like one that's right until someone tests it, or until a stranger reads your customers' data.
For the sample audit on our code audit page, we wrote 37 pgTAP tests for Acme, a demo client portal for small studios that we built in the layout Lovable generates for a Supabase project. Acme wasn't built in Lovable, and it holds no client data: every person in it is made up. For this post we tightened that suite: three tests that counted rows now compare IDs, and three are new, 40 in all. On November 12, 2026 we ran it from scratch on Supabase CLI 3.1.0. 38 of the 40 tests failed against the vulnerable schema, and all 40 passed once the fixes were applied as a migration.
This post walks through that suite, with its own code and output: how to act as a signed-out visitor, a signed-in user and another signed-in user, which pgTAP assertion fits which kind of refusal, how to test storage policies and the secret key, and how to run it all with supabase test db, locally and in CI. We also wrote and ran the techniques the suite doesn't use, plus experiments that show how tests pass for the wrong reason. The schema, the seed, the fix, both test files and the CI workflow make up a runnable example, and every file this post names is in it. Supabase's behaviour is linked to its docs as we read them on November 29, 2026. For what each RLS mistake looks like and how to fix it, see our Lovable security checklist. This post is about proving the fixes work.
The short version
- Put each test file under
supabase/tests/, in one transaction that ends inrollback. - Act as a user with
set local roleandset local request.jwt.claims. Supabase'sauth.uid()reads thesubclaim from it. - Compare the IDs that come back with the IDs that should. A filtered row raises no error, and a count can't tell one user's 20 rows from another's.
- Pair every "can't" test with a "can" test, or a database that refuses everything passes.
- Add the rows and files you test inside the test, so there's something to refuse.
- Test that the secret key still skips RLS where your server code needs it.
- Run new tests against the broken version first, then run
supabase test dbon every pull request, with the CLI version pinned.
How a request reaches your policies
Supabase's API connects to Postgres as a role called authenticator, checks the request's JWT and switches to the role it names: anon when no one is signed in, authenticated when someone is (Postgres roles). The token's role claim names that role, and its sub claim is the user's ID (JWTs). Policies then call auth.uid(). On the local stack we tested, this is its body:
select
coalesce(
nullif(current_setting('request.jwt.claim.sub', true), ''),
(nullif(current_setting('request.jwt.claims', true), '')::jsonb ->> 'sub')
)::uuidSo it reads a database setting, and a test can set that setting itself. Inside a transaction, a test does what the API does: switch to the role, set the claims, and run the query.
The catch is the role a test starts as. supabase test db connects as postgres, and on our local stack, as on Supabase, postgres has the BYPASSRLS attribute:
rolname | rolbypassrls
---------------+--------------
anon | f
authenticated | f
postgres | t
service_role | t
(4 rows)Postgres skips every policy for roles with BYPASSRLS, and usually for a table's owner too (Postgres docs). In Acme's public schema, postgres owns every table. So a test that forgets to switch role sees everything. In our techniques file, the first test confirms that it runs as postgres, and the third that it sees all 68 of Acme's invoices before set role. Supabase's dashboard SQL editor runs your queries as postgres too (Postgres roles), so the same goes for a check you run there.
The shape of a test file
Supabase's RLS guide asks for a test file for every table you secure, asserting allow and deny for each operation, as anon and as authenticated. It says that until the suite passes, you don't know whether the policies do what you intended (Row Level Security). supabase test new invoices_rls creates a stub. On CLI 3.1.0 it printed Created new pgtap test at supabase/tests/invoices_rls_test.sql.
Acme's suite is one file, supabase/tests/database/access-rules.test.sql in the example, with one test per rule. Its first and last lines:
begin;
create extension if not exists pgtap with schema extensions;
select plan(40);
-- Lines 14 to 215 of the file create the helpers and the answer key and add
-- three rows to storage.objects. Lines 217 to 387 are the 40 tests.
reset role;
select * from finish();
rollback;plan(40) tells pgTAP how many tests to expect, and finish() reports the result. Everything runs in one transaction that ends in rollback, so whatever the tests insert, change or delete is undone, and the database is left as it was. The create extension line installs pgTAP if it's missing, for example when the file runs outside the CLI. Under supabase test db, pgTAP was already there, and the line printed extension "pgtap" already exists, skipping.
The suite's tests are grouped by who's asking. The seed has two studios, Alder Studio and Juniper Dev, with fixed user IDs: Maya owns Alder, Leo is its staff, and Sam and Priya are its clients. Tom owns Juniper, and Ana is its client.
| Group | Tests | What they check |
|---|---|---|
| Structure | 4 | RLS is on for every table in public, views run as the caller, and the bucket's settings |
| Signed out | 6 | No invoices, messages, client list or files, no posting, and no call to a function that returns a secret |
| Ana, another studio's client | 4 | She can't read Alder's invoices, list or overwrite its files, or add herself to Alder |
| Sam, Alder's client | 10 | Exactly his own 20 invoices and no other client's, his name but not his role, Maya's profile but not Priya's, no posting as someone else, no way to Priya's PDF |
| Regression case | 2 | Linked to Priya's client record, Sam still counts 20 invoices, and the IDs show they're hers |
| Tom, another studio's owner | 4 | He can't change his own plan, or point his projects and invoices at Alder's |
| Leo, Alder's staff | 3 | Exactly Alder's 60 invoices, and he can't choose an invite's token or expiry |
| A removed client | 1 | After Maya removes Sam, he reads none of his projects, invoices, messages or files |
| The file policy alone | 2 | With a check constraint dropped, the storage policy still keeps each PDF from the wrong client |
| Invites | 4 | Maya invites Ana, the invite works once, and a client invited as staff becomes staff |
Act as each kind of user
Signed out
-- Signed out
set local role anon;
set local request.jwt.claims = '{"role": "anon"}';
select is(tests.visible_rows('select 1 from public.invoices'), 0, 'signed out: no invoices');There's no sub, so auth.uid() returns null. Supabase's guide warns that a policy like using (auth.uid() = user_id) therefore matches nothing for signed-out requests, rather than failing loudly. Our techniques file checks it: signed out: auth.uid() is null passed.
Signed in
-- Ana, a client of Juniper Dev
set local role authenticated;
set local request.jwt.claims = '{"sub": "66666666-6666-4666-8666-666666666666", "role": "authenticated"}';
select is(tests.visible_rows($$select 1 from public.invoices where workspace_id = 'a1de5000-0000-4000-8000-000000000001'$$),
0, 'Ana: none of Alder''s invoices');set local lasts until the transaction ends, so the role and the claims apply to every test after them until the next set local.
Another user
Trying your app with your own account only ever shows you your own rows. Ana, Sam and Leo all have the same role, authenticated. The only thing that keeps Sam out of Priya's invoices is a policy that checks the invoice's client against auth.uid(). So the suite switches users by changing the claims alone, then checks which invoices come back, by ID:
-- Sam, a client of Alder Studio
set local request.jwt.claims = '{"sub": "33333333-3333-4333-8333-333333333333", "role": "authenticated"}';
select set_eq(
'select id from public.invoices',
$$select id from tests.invoice_key where client_id = 'c1000000-0000-4000-8000-000000000001'$$,
'Sam: exactly his own 20 invoices, by ID');
select is_empty(
$$select client_id, number from public.invoices
where client_id is distinct from 'c1000000-0000-4000-8000-000000000001' order by client_id, number$$,
'Sam: no invoice of another client');set_eq runs both queries as the current role and fails if either returns a row the other doesn't, listing those rows. The answer key is a table the suite fills as postgres, before any test switches role, so RLS can't filter it:
create table tests.invoice_key as
select id, workspace_id, client_id from public.invoices;
grant select on tests.invoice_key to anon, authenticated;The second test names the leak when there is one. Against the vulnerable schema, it listed every invoice of another client that Sam could read:
# Failed test 16: "Sam: no invoice of another client"
# Unexpected records:
# (c1000000-0000-4000-8000-000000000002,INV-2026-0021)
# (c1000000-0000-4000-8000-000000000002,INV-2026-0022)
[...]Compare IDs, not counts. Sam and Priya have 20 invoices each, so "Sam sees 20" passes when a bug hands him Priya's 20 instead of his own. The suite's regression case makes that bug on purpose. It links Sam's login to Priya's client record, as a bad backfill might, runs two tests, and swaps the links back:
select is(tests.visible_rows('select 1 from public.invoices'), 20,
'regression case: linked to Priya''s record, Sam still counts 20 invoices');
select set_eq(
'select id from public.invoices',
$$select id from tests.invoice_key where client_id = 'c1000000-0000-4000-8000-000000000002'$$,
'regression case: the IDs show they''re Priya''s 20, not his');Both passed on the fixed schema. The count can't see the bug. The IDs can, so the ID check above fails whenever Sam gets someone else's invoices, however many there are.
request.jwt.claims or request.jwt.claim.sub
The examples in Supabase's RLS guide set request.jwt.claim.sub instead. auth.uid() reads both, as its definition above shows. auth.jwt(), which policies use to read other claims, doesn't. We tested it: with only request.jwt.claim.sub set, auth.uid() returned Sam's ID and auth.jwt() returned null. Supabase's storage examples compare auth.jwt()->>'sub' with a file's owner (Storage access control), so a test that sets only claim.sub against those policies acts as nobody, and every "can't" test passes. Set the whole JSON, with the claims your policies read.
Match the assertion to the refusal
Postgres refuses a request in three ways, and only two of them raise an error. Supabase's API keys page puts it plainly: Postgres checks a table's grants before it applies RLS, a missing grant returns a permission error, and a policy that matches no rows returns an empty result (API keys). Here's each one, from the techniques file we wrote for this post and ran against the fixed database:
| What refuses the request | What Postgres does | Our test | Assert with |
|---|---|---|---|
| A missing grant | Error 42501, permission denied for table invoices | Signed out, reading invoices | throws_ok |
A policy's with check | Error 42501, new row violates row-level security policy for table "messages" | Sam posting a message as Maya | throws_ok |
A policy's using | Nothing. The row is skipped | Sam updating Priya's profile | is_empty on the statement with returning, then a read |
The first two in pgTAP, as a signed-out visitor and as Sam:
select throws_ok(
'select 1 from public.invoices',
'42501', 'permission denied for table invoices',
'signed out: with the grant revoked, reading invoices is an error, not zero rows');
select throws_ok(
$$insert into public.messages (workspace_id, project_id, sender_id, body)
values ('a1de5000-0000-4000-8000-000000000001', md5('alder-project-1')::uuid,
'11111111-1111-4111-8111-111111111111', 'posing as Maya')$$,
'42501', 'new row violates row-level security policy for table "messages"',
'Sam: a message in Maya''s name fails the policy''s check');The third is the one that fools people. As Sam, lives_ok on an update of Priya's profile passed, though the update matched no rows. Supabase's guide is blunt about it: never prove an allowed write with lives_ok. Add returning and check what comes back:
select is_empty(
$$update public.profiles set full_name = 'Changed by Sam' where id = '44444444-4444-4444-8444-444444444444' returning id$$,
'Sam: an update of Priya''s profile matches no rows');
select results_eq(
$$update public.profiles set full_name = 'Sam R.' where id = '33333333-3333-4333-8333-333333333333' returning full_name$$,
array['Sam R.'],
'Sam: changes his own name, and returning shows it');Then switch back to postgres with reset role and read the row you tried to change. In our run, Priya's name was still Priya Shah and all 20 of her invoices were still there after Sam's update and delete.
The suite's two helpers
For its other tests, Acme's suite wraps the counting in two small functions, created in a tests schema inside the transaction:
-- Rows the current role can see. A permission error counts as none, and any
-- other error as -1, so the test fails without stopping the run.
create function tests.visible_rows(query text) returns integer
language plpgsql as $$
declare
n integer;
begin
execute format('select count(*) from (%s) q', query) into n;
return n;
exception
when insufficient_privilege then return 0;
when others then return -1;
end;
$$;Its partner, tests.changed_rows, runs a write, counts the rows it changed, then raises an error to undo the change at once and reads the count back from the error. A refusal from RLS, a grant, a check constraint or a foreign key counts as zero. Both are ordinary functions, not security definer, so they run as whichever role the test has switched to, and the policies apply. The suite grants anon and authenticated usage on the schema and execute on the functions for that reason.
The catch is an error you didn't expect: inside a transaction, one error aborts it, and every test after it fails with it. The helpers turn an unexpected error into -1, so that one test fails and the run carries on. The trade-off is that visible_rows treats a missing grant and a filtered row alike. When the grant itself is part of the fix, as when Acme's fix revoked anon's access to invoices, add a throws_ok as well.
Test storage policies
Supabase Storage keeps each file's metadata in storage.objects, and you control access with RLS policies on that table (Storage access control). So storage policies are tested like any table. Acme's suite checks the bucket's own settings:
select is((select public from storage.buckets where id = 'invoices'), false, 'the invoices bucket is private');That one matters on its own. A public bucket serves its files to anyone with the URL, and Supabase's docs say select policies aren't needed for that. A bucket that's public by mistake serves every file to anyone who has its URL, however good its policies are. The checklist's item 7 has the fix.
Then the policies, as each user:
select is(tests.visible_rows($$select 1 from storage.objects where bucket_id = 'invoices'
and name like 'a1de5000-0000-4000-8000-000000000001/%'$$), 0, 'Ana: can''t list Alder''s invoice files');
select is(tests.changed_rows($$update storage.objects set metadata = metadata where bucket_id = 'invoices'
and name like 'a1de5000-0000-4000-8000-000000000001/%'$$), 0, 'Ana: can''t overwrite Alder''s invoice files');These only prove something if there are files to refuse. A test database in CI usually has none, so the suite adds three rows to storage.objects before any test runs:
insert into storage.objects (bucket_id, name) values
('invoices', 'a1de5000-0000-4000-8000-000000000001/INV-2026-0001.pdf'),
('invoices', 'a1de5000-0000-4000-8000-000000000001/INV-2026-0007.pdf'),
('invoices', 'a1de5000-0000-4000-8000-000000000001/INV-2026-0025.pdf')
on conflict do nothing;In the audit's suite, this insert ended on conflict (bucket_id, name) do nothing. On CLI 3.1.0's local stack, Storage keeps object versions, and its unique indexes on those two columns only cover some rows, so that clause matched none of them. The file stopped at that line with there is no unique or exclusion constraint matching the ON CONFLICT specification, and none of its 37 tests ran. Without the column list, the insert works on both versions.
We tested what happens without the rows. A copy of the suite with those lines removed, run against the vulnerable database, failed 31 tests instead of 38. Seven storage tests passed against a bucket that was public, listable by anyone and writable by any signed-in user, because it was empty. They included signed out: can't list invoice files and both of Ana's tests above.
Supabase's docs say to treat the storage tables as read-only and to upload, move and delete files through the API, because the rows are only metadata (storage schema). The table's shape belongs to Storage, as the version change above shows. The suite's rows never touch a file and vanish with the rollback. Don't insert them anywhere else.
Add a "can" test for files too. In our techniques file, Sam: lists his own two invoice files, not Priya's compares the names he can see with the two that are his. On the vulnerable database it failed at the third row, Priya's INV-2026-0025.pdf.
Test that the secret key skips RLS, on purpose
Supabase's secret keys, and the legacy service_role key, act as the service_role role, which has BYPASSRLS, so no policy applies to them (API keys). That's how your server code, cron jobs and Edge Functions do work no user could. Supabase's RLS guide adds one condition: a secret key bypasses RLS only when the request carries no user access token. With a user's token, the request runs under that user's policies.
Acme's fix took plan changes away from the browser, so only server-side billing code, with the secret key, can change a studio's plan. The suite tests the first half (Tom: can't change his own plan). Our techniques file tests the second, and pins down which roles skip RLS:
select ok((select rolbypassrls from pg_roles where rolname = 'service_role'), 'service_role has BYPASSRLS');
select ok(not (select rolbypassrls from pg_roles where rolname = 'authenticated'), 'authenticated doesn''t');
select ok(not (select rolbypassrls from pg_roles where rolname = 'anon'), 'anon doesn''t');
set local role service_role;
set local request.jwt.claims = '{"role": "service_role"}';
select results_eq('select count(*)::integer from public.invoices', array[68], 'service_role: reads all 68 invoices');
select results_eq(
$$update public.workspaces set plan = 'agency' where id = 'b1de5000-0000-4000-8000-000000000002' returning plan$$,
array['agency'],
'service_role: server-side billing code can still change a plan');All five passed on both schemas. The point isn't that the key is powerful. It's that the paths your server depends on stay open, and the roles your browser uses never gain the same power. Grants still apply to service_role, so a revoke that's too broad breaks your server code with a permission error, and a test like this catches it. The key itself belongs on the server only, which no database test can check. The checklist's item 8 covers where to look.
Four ways a test passes for the wrong reason
Every test above was run against the vulnerable schema before we trusted it. That's what makes the result mean something. Here's what happens otherwise.
- It never switched role. A test that runs as
postgressees all 68 invoices, whatever the policies say. - There was nothing to refuse. Without its three storage rows, the suite let seven storage tests pass against a bucket anyone could list.
- It counted rows. In the regression case, Sam, linked to Priya's client record, still counts 20 invoices. Only the IDs show they're hers.
- It only checked what users can't do. We ran a copy of the suite that drops every policy in
publicandstorageinside its transaction, so RLS refused everything, against the fixed database. 28 of the 40 tests still passed.
The twelve that failed in that last run were the ten that expect someone to see rows or get something done, and two whose own setup needed a write:
# Failed test 15: "Sam: exactly his own 20 invoices, by ID"
# Missing records:
# (401767b8-d267-4e80-8b70-e8caedec72a7)
[...]
# Failed test 19: "Sam: can still change his name"
# have: 0
# want: 1
[...]
# Failed test 25: "regression case: linked to Priya's record, Sam still counts 20 invoices"
# have: 0
# want: 20
[...]
# Looks like you failed 12 tests of 40Two more passed for the wrong reason. Ana: the invite works only once expects an error the second time she uses an invite, and got one because no invite was ever created. A test that expects a refusal passes just as well when the step before it failed, so give that step a test of its own. Here, Maya: invites Ana to Alder as a client failing is what gives it away. And Sam: no invoice of another client passes when Sam sees nothing at all, which is why it sits beside the ID comparison.
Run the example locally
The example is on GitHub at pulore/supabase-rls-pgtap, under the Apache 2.0 licence. You need Docker, and Node.js for npx. We ran Supabase CLI 3.1.0 through npx, so every command names that version and nothing is installed globally. From the example's folder:
npx supabase@3.1.0 db start
npx supabase@3.1.0 db reset --last 1
npx supabase@3.1.0 test dbdb start starts Postgres and applies every migration and the seed. The last migration is the fix, so db reset --last 1 rebuilds the database without it, which gives you the vulnerable schema. Against it, trimmed:
$ npx supabase@3.1.0 test db
Target: local stack (127.0.0.1:54522)
<project>/supabase/tests/database/access-rules.test.sql ....
# Failed test 5: "signed out: no invoices"
# have: 68
# want: 0
# Failed test 11: "Ana: none of Alder's invoices"
# have: 60
# want: 0
# Failed test 18: "Sam: can't make himself an admin"
# have: 1
# want: 0
[...]
# Looks like you failed 38 tests of 40
Failed 38/40 subtests
[...]
Test Summary Report
-------------------
<project>/supabase/tests/database/access-rules.test.sql (Wstat: 0 Tests: 40 Failed: 38)
Failed tests: 1-18, 20-22, 24-40
<project>/supabase/tests/database/rls-techniques.test.sql (Wstat: 0 Tests: 25 Failed: 7)
Failed tests: 5-7, 14, 18, 24-25
Files=2, Tests=65, 0 wallclock secs ( 0.01 usr + 0.00 sys = 0.01 CPU)
Result: FAILThe two suite tests that passed were Sam: can still change his name and Sam: can still see Maya, the studio's owner, "can" tests that a more open schema passes too. Then we applied the last migration, the fix, to the running database:
$ npx supabase@3.1.0 migration up
Target: local stack (127.0.0.1:54522)
Applying migration 20261106090000_0b7d3e52-7c41-4f0e-9d2a-5e8f1c6a4b90.sql...
Local database is up to date.
$ npx supabase@3.1.0 test db
Target: local stack (127.0.0.1:54522)
<project>/supabase/tests/database/access-rules.test.sql .... ok
<project>/supabase/tests/database/rls-techniques.test.sql .. ok
All tests successful.
Files=2, Tests=65, 0 wallclock secs ( 0.01 usr + 0.01 sys = 0.02 CPU)
Result: PASSA full supabase db reset with the fix in place gave the same 65 passes. supabase test db exited with status 1 when tests failed and 0 when they passed, which is what CI needs. To run one file, pass its path: npx supabase@3.1.0 test db supabase/tests/database/rls-techniques.test.sql. On this Mac, with the images already pulled, db start took 4 to 5 seconds, a reset 4 to 5, and each test db 2 to 3, npx's own start-up included. npx supabase@3.1.0 stop --no-backup stops Postgres and deletes its data.
Run them in CI
The example's workflow:
name: Database tests
on:
push:
branches: [main]
pull_request:
permissions:
contents: read
jobs:
db-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: supabase/setup-cli@v3
with:
version: 3.1.0
- run: supabase db start
- run: supabase test dbSupabase's GitHub Actions page uses the same two commands, with setup-cli@v1 and the latest CLI, and its testing overview runs supabase start instead. supabase db start is enough for database tests: it starts only Postgres, then applies the migrations and the seed. We ran the job's two commands locally, in a fresh copy of the example with a new project ID, as a new runner would start. On this Mac, with the images already pulled, the database was ready in 4 seconds, and all 65 tests passed. A new runner has to pull the images first: our first db start on CLI 3.1.0, which pulled three of them, took 88 seconds, retries after the registry's rate limit included. Then the workflow ran on GitHub's runners, on the example's first push on November 12, 2026: all 65 tests passed, and the whole job took about a minute (the run).
Two choices in that file are deliberate. It runs on every push to main and every pull request, so a pull request that loosens a policy shows a failing check before anyone merges it. And it pins the CLI version. The action's README calls setup-cli v1 and v2 legacy, and says v3 installs the CLI from npm: without a version, the one your lockfile pins, or else the latest (setup-cli, read November 29, 2026). A pinned version arrives as a change someone reviews, not as a surprise in a failing build. CLI 3 shows why. It won't load a config.toml that has an [inbucket] section, which projects created before CLI 2.108.0 have (migrating to v3, read November 29, 2026). Acme's config had one. The example renames it [local_smtp] and pins CLI 3.1.0 in its commands and its workflow alike.
Checkers find shapes. Tests know your rules
A checker such as Supabase's Security Advisor, or the CLI's supabase db advisors, flags patterns: tables in public with RLS off, policies that let everyone through, views that skip RLS and public buckets that allow listing (Advisors). Run it. It can't know that Sam may read Maya's profile but not Priya's.
You can still turn the checks you care about into tests, so they run on every change. Acme's suite opens with two of them, the checks from items 1 and 5 of our checklist written as tests: RLS is on for every table in public and every view in public runs as the caller. pgTAP also has assertions for policies themselves (pgTAP):
select policies_are('public', 'invoices',
array['Clients read their own invoices', 'Staff can manage invoices'],
'invoices has exactly these two policies');Permissive policies combine with OR, so one extra policy beside the right ones can open every row. That's checklist item 2. Against the vulnerable schema, this test named it:
# Failed test 24: "invoices has exactly these two policies"
# Extra policies:
# "Enable read access for all users"
# Missing policies:
# "Clients read their own invoices"Supabase's advanced pgTAP guide also describes community helpers, supabase_test_helpers, that create test users and switch between them for you. Its setup installs them from database.dev over the network. We didn't use them: the suite's two helpers and plain set local did the job.
What these tests prove, and what they don't
They prove that, for the users and rows in the seed, at this commit, each read and write the tests try is allowed or refused as written, and that this stays true on every change CI sees. That's the part of security that breaks quietly, and it's cheap to keep: supabase test db ran all 65 tests in 2 to 3 seconds.
They don't prove:
- That the rules are the right ones. Whether Leo should see all 60 of Alder's invoices is a business decision. A test only checks that the code does what someone decided. They don't replace a review of who should see what.
- Anything outside the database. Acme's Edge Function that answered anyone, its weak sign-up settings and the secret key in its JavaScript were findings 8, 12 and 1 of the audit. None of them is a policy, so none of these tests could catch them. The audit caught them with HTTP requests and a check of the built JavaScript instead.
- The API itself. The tests switch role and claims the way the API does. They don't send requests through it, so they don't check which schemas it exposes or how the Storage API serves a public bucket's files.
- Speed. A suite over 68 invoices says nothing about a policy on a million rows. Supabase's guide covers indexing the columns policies filter on and wrapping
auth.uid()in aselect. - Users and rows you didn't write down. Each test covers one person and one case. Add a test when you add a role, a table or a sharing feature.
If your app was built in Lovable, our Lovable security audit is the same audit, for Lovable apps. It isn't a penetration test or a compliance audit.
How we tested
- When and where: November 12, 2026, on a Mac (macOS 27.0.1, arm64) with Docker 29.9.2, against the Supabase CLI's local Postgres. No hosted project was used.
- Versions: Supabase CLI 3.1.0, the latest on npm that day, run through npx with Node.js 26.12.1. Its local database was Postgres 17.11 (image
supabase/postgres17.11.0.018) with pgTAP 1.3.3, the version the image ships, andsupabase db startbuilt the auth and storage schemas with the gotrue v2.197.0 and storage-api v1.90.1 images.supabase test dbran the tests in thepg_prove3.36 image. - Output: every command ran with
--network-id, for a Docker network of our own, and with--agent no, which stops CLI 3.1.0 from switching some commands' output to JSON when a coding agent runs them. The outputs above leave out those flags and Postgres's NOTICE lines,<project>stands for the project folder's path, which CLI 3.1.0 prints in full, and[...]marks lines cut from the middle. - What ran: the example. Its six schema migrations and its fix migration are byte-for-byte the sample audit's, and the fixes went in as that one migration. Its seed leaves out the test users' passwords, which no test uses. Its suite is the audit's, with three count checks turned into ID comparisons and three tests added.
- Results: 38 of 40 failed against the vulnerable schema. All 40 passed after
supabase migration up, again after a fullsupabase db reset, and again in a fresh copy started withsupabase db start, as the CI job would. We ran the whole sequence twice, with the same results. - Re-run: on November 29, 2026 we ran the whole sequence again in a fresh copy, on CLI 3.1.0 and on 3.4.0, the latest on npm that day. Every pass and fail above was the same on both. CLI 3.4.0's local database is Postgres 17.12 (image 17.12.0.002), and its auth and storage images, pgTAP and
auth.uid()are unchanged. - The audit's suite as published stopped at its storage insert on CLI 3.1.0's stack, before any test ran. With only that insert's conflict columns removed, 35 of its 37 tests failed against the vulnerable schema and all 37 passed against the fixed one.
- Written for this post: a 25-test techniques file (
results_eq,is_empty,throws_ok,lives_ok,policies_are, the claim settings andservice_role). 7 of its tests failed on the vulnerable schema, and all 25 passed on the fixed one. Two variants of the suite: without its storage rows (31 failures on the vulnerable schema instead of 38), and with every policy dropped (28 of 40 passed on the fixed schema). - CI: the workflow ran on GitHub's runners on November 12, 2026, on the example's first push. All 65 tests passed (run 43182195060).
- Not run: anything hosted. These tests don't send HTTP requests; the audit's own scripts did that on November 6.
- Docs: Supabase's docs and the Postgres 17 docs on row security, read on November 29, 2026: Row Level Security, API keys, Postgres roles, JWTs, testing overview, GitHub Actions, migrating to CLI v3, pgTAP, advanced pgTAP, Storage access control, storage schema, Advisors and Postgres row security, plus the setup-cli action's README.
Frequently asked questions
How do I test Supabase RLS policies?
Write pgTAP tests in SQL files under supabase/tests/ and run them with supabase test db. Each file opens a transaction, switches to the anon or authenticated role, sets the request's JWT claims, runs the queries a user would and checks what comes back, then rolls back. Test each operation as a signed-out visitor, as the user who owns the rows and as another signed-in user, compare the IDs that come back with the IDs that should, and run new tests against the broken version first to see them fail.
How do I run an RLS test as a specific user?
Inside a transaction, run set local role authenticated; and then set local request.jwt.claims = '{"sub": "USER-ID", "role": "authenticated"}';. Supabase's auth.uid() reads the sub claim, so your policies see that user. To act as another user, change only the claims. Supabase's own examples set request.jwt.claim.sub, which auth.uid() also reads, but auth.jwt() only sees the full JSON, so set that if your policies read other claims.
Why does my RLS test pass when the policy is wrong?
Usually for one of four reasons, all of which we reproduced on November 12, 2026. The test never switched role, so it ran as postgres, which bypasses RLS. The table or bucket had no rows to refuse: without the files it adds itself, 7 of our storage tests passed against a bucket anyone could list. The test counted rows: a user who gets someone else's 20 rows instead of their own 20 still passes a count. Or the tests only check what users can't do: with every policy dropped, 28 of our 40 tests still passed. Seed the rows you test, compare IDs, pair each "can't" with a "can", and run new tests against the broken version first.
Does the service_role key bypass RLS?
Yes. Supabase's secret keys and the legacy service_role key act as the service_role Postgres role, which has the BYPASSRLS attribute, so no policy applies to them. Supabase's RLS guide adds that a secret key bypasses RLS only when the request carries no user access token. Keep it on the server, and test that it still reaches what your server code needs, such as a billing job that changes a customer's plan.
Can I test RLS in the Supabase SQL editor?
For a quick check, yes, but the dashboard runs your queries as postgres, which bypasses RLS. Wrap the check in begin and rollback, and switch the role and claims first, as in item 2 of our Lovable security checklist. For checks that run on every change, put them in a pgTAP file and run supabase test db.
How do I run Supabase database tests in GitHub Actions?
Install the CLI with the supabase/setup-cli action, then run supabase db start and supabase test db. db start starts only Postgres and applies your migrations and seed, and supabase test db exits with an error when a test fails, which fails the job. Pin the CLI version: without one, setup-cli v3 installs the version your lockfile pins or the latest, and CLI 3 won't load a config with an [inbucket] section, which older projects have. We ran the workflow's two commands on CLI 3.1.0 in a fresh copy of our example on November 12, 2026: on a Mac with the images already pulled, the database was ready in 4 seconds and all 65 tests passed. On GitHub's runners, which start without those images, the workflow passed all 65 tests on November 12, 2026, and the whole job took about a minute.
Do RLS tests replace a security review?
No. They prove that the rules you wrote hold for the users and rows in your tests, every time the schema changes. They can't tell you whether those are the right rules for your business, and they don't cover Edge Functions, auth settings, keys in your app's code or files served from public buckets. That's what a review is for.

