Test with 2 real users whether one client can read another client’s data
Enter two user ids from your Supabase project. You get a read-only script for your own SQL Editor, and it returns what each user can read, table by table.
Run this in the Supabase SQL Editor
It runs in a read-only transaction, so Postgres refuses any write in it. It counts every table and view except foreign tables and reads up to 5,000 rows of each, so on a large project use a copy of production.
How to read the result
This test only reads. It tries no write, so reads_separated says nothing about whether one client can insert or change another client’s data. Test writes by hand, as the guide below shows.
| Verdict | What it means |
|---|---|
anon_can_read | Anyone with your public key can read rows here, with no sign-in. Fine for a public catalog, a leak for anything else. |
shared_check_it | Both users read the same rows. Fine for a public catalog, a leak if those rows belong to a client. |
view_check_it | Each user gets different rows through this view or foreign table, which proves little. A view with its owner’s rights skips RLS, and a per-user column can hide shared rows. Read its definition by hand. |
capped_check_it | A user reads over 5,000 rows, so the comparison stopped at the limit and shared rows may sit past it. Compare on a smaller copy or by hand. |
test_by_hand | A security definer function that signed-in users can call. It skips RLS, so call it by hand with the other company’s id. |
one_user_sees_nothing | Only one user reads rows here, so nothing is proven yet. Give the other user a row, or check that its policy is not too tight. |
neither_sees_rows | Rows exist, but neither user reads any. These users may own none of them, the policy may rely on a custom access token hook or an MFA level, or it blocks everyone, including real clients. |
empty_seed_it | The table is empty, so the test proves nothing. Add one row per company and run it again. |
no_access | Neither user has a grant on this table. The app cannot read it as a signed-in user at all. |
read_failed | Reading this object failed, for example a foreign table whose server did not answer or a view that tries to write. Check it by hand. |
reads_separated | Each user reads different rows and none in common. This covers reading only: no write was tried. Open a few rows and confirm they belong to that user, because this test cannot tell whose rows they are. |
What this test cannot see
It only reads tables and views in the public schema, as the anon role and as each user’s own role. It builds each user’s claims from their account, so claims from a custom access token hook or an MFA level will not match. Writes, adding yourself to another company, function arguments, Storage, Realtime and Edge Functions need their own attempts. The full list of paths is in the multi-tenant isolation test guide.
The test shows who can read what, not whether your app’s logic is right. If you need an engineer to close what it finds and keep running the product, write to yes@madsalt.tech.
Questions
Why a SQL script and not a login form?
A form would need real passwords, and anyone could point it at someone else’s app. The script needs neither: only the people who already run the project can use it.
Can the script change my data?
Not through this transaction: it switches to read-only before the first read, so Postgres refuses any write in it. A view that calls out over its own connection, with dblink for one, would still act as it does on any read. The script creates two temporary functions, which disappear with the session.
Does a clean result mean one client cannot write into another’s data?
No. The script never tries a write, because a test that writes does not belong on a live database. In my own test, 2 of 6 leaks were writes: joining another company and inserting an invoice into it. Those need their own attempts on a copy.
Is a shared table always a leak?
No. Plans, countries and other public lists are meant to be shared. Go through the flagged tables and ask whether a row belongs to one client.
How is this different from the Supabase security scanner?
The scanner reads settings and policies, so it cannot tell which company a row belongs to. This test reads as two real users and compares what each one gets.