Skip to content

Multi-tenant isolation test: 6 leaks reads did not show

View as MarkdownOpen in ClaudeOpen in ChatGPTOpen in Perplexity

The question is copied too. If the chat opens empty, paste it.

On this page
  1. What did the usual checks show?
  2. What did the same user reach by other paths?
  3. Why can’t you trust the status code?
  4. Why does the test need a positive control?
  5. What fixed all six?
  6. How do you run this on your own app?
  7. What can you show a buyer?
  8. My similar case

TL;DR

To prove one client cannot reach another’s data, sign in as a real user of company 1 and attack company 2 through every path, then read the database to see what changed. On a deliberately broken schema, the four checks most people try came back clean while 6 of 14 requests leaked: a child table, the members list, a view, a function, joining the other company, and an insert that returned 403 in one form and went through in another. A status code alone misled me twice. And a test with no positive control passes on an app where nobody can read anything.

“Can client A see client B’s data?” is the question a B2B buyer asks, and “we use row level security” does not answer it. What answers it is a test someone can rerun. I built a small invoicing schema with mistakes I have seen in real apps, then wrote the test that should catch them.

How I tested. Local Supabase stack (CLI 2.109.1) on 3 November 2026, over the REST API, with a real sign-in for each user. User A belongs to company 1. Company 2 holds the target invoices, and A must never reach them. Made-up data. After every write attempt I read the table directly with psql, because the API’s answer is not evidence. The method does not depend on Supabase; only the requests would change on another stack.

What did the usual checks show?

These are the checks I see most often. All four were clean on the broken schema.

Request by user A Result
List invoices 200, own 1 row
Read company 2’s invoice by id 200, 0 rows
Filter by company_id = 2 200, 0 rows
Count company 2’s invoices 0

The invoices read policy was correct, and someone testing only this table would sign off.

What did the same user reach by other paths?

One schema, 14 requests at company 2. User A, a real signed-in member of company 1. Usual read checks on invoices: 4 requests → 0 leaks; Child table, view, function, members, writes: 10 requests → 6 leaks; After the fixes: 14 requests → 0 leaks, own data readable.
Figure 1. My test on a local Supabase stack (CLI 2.109.1), 3 November 2026.
Path Why it leaked Broken schema After the fix
Child table invoice_lines RLS on, policy using (true) 200, 2 rows from both 200, own 1
memberships Read policy using (true) 200, both companies’ users 200, own 1
View invoice_totals Runs with its owner’s rights, skips RLS 200, both companies’ sums 200, own 1
Function get_invoice(21) security definer with no company check 200, B’s invoice 200, 0 rows
Join company 2 Insert checks only user_id = auth.uid() 201, then 3 invoices listed 403
Insert an invoice for company 2 Insert checks only that a user is signed in 201, row in the table 403

The first four are read paths a form-based test never touches. Nothing in the app’s screens calls them with another company’s data, so clicking around cannot find them.

Why can’t you trust the status code?

The last row of that table nearly got past me. My first version of the insert returned 403:

new row violates row-level security policy

That looked like a pass. But the insert policy allowed the row. The error came from return=representation, which asks for the new row back, and A has no read access to a company 2 row. The same insert with return=minimal, the form supabase-js uses unless you add .select(), returned 201, and psql showed the row in company 2’s table.

The opposite error exists too. With a correct policy, A’s update and delete of company 2’s invoice both returned 200 with 0 rows. Reading the table showed the amount unchanged and the invoice still there. So 200 did not mean it worked, and 403 did not mean it failed.

Use the database as the verdict. Run each write attempt, then read the row with a connection that skips RLS and compare.

Why does the test need a positive control?

I ran the same 14 requests with every table grant revoked. Result: 0 leaks out of 14. By that count the schema is perfectly isolated, and also nobody can use the app.

Schema Leaks A reads own data
Broken 6/14 2/2
Fixed 0/14 2/2
All grants revoked 0/14 0/2

Every “A cannot read B” test needs a “A can read A” next to it. Otherwise a missing grant, a typo in a table name or an expired token all look like security. Those are the first two rows of my script, and on the revoked schema they are what failed.

What fixed all six?

create policy m_read on memberships for select to authenticated
  using (company_id in (select my_companies()));

create policy i_ins on invoices for insert to authenticated
  with check (company_id in (select my_companies()));

create policy l_read on invoice_lines for select to authenticated
  using (invoice_id in (select id from invoices));

create view invoice_totals with (security_invoker = true) as
  select company_id, sum(amount) total, count(*) n
  from invoices group by company_id;

create function get_invoice(p int) returns setof invoices
  language sql security invoker set search_path = ''
  as $$ select * from public.invoices where id = p $$;

The join path closed by removing the insert policy on memberships. Adding someone to a company is an invitation flow, so it belongs in server code. my_companies() is a security definer helper returning the signed-in user’s company ids. If a user can belong to several companies, there is one more trap, in a user in two organizations.

How do you run this on your own app?

  1. Create two companies, one user in each, and seed each with one row in every table holding client data.
  2. Get a real session for user A. A test running as postgres or with the secret key skips RLS and proves nothing.
  3. List every path: each table and child table, each view, each function, then search and export endpoints. A query on the catalog is more reliable than memory.
  4. For each one, try reading company 2’s row, and try read, insert, update and delete with company_id pointing at company 2. Try moving your own row across too, and adding yourself to the other company.
  5. After each write, compare the row through a privileged connection.
  6. Run your controls: A must read and write company 1’s rows.
  7. Keep it in CI. A new table with no test should fail the build.

For the read side on Supabase, the free tenant isolation test builds a read-only script from two user ids and shows what each user can read, table by table. Writes stay on your list. The free Supabase security check finds the catalog side of this, such as policies that allow every row and views that bypass RLS. It cannot tell you which company a row belongs to, so it does not replace this test. For checking every role against every permission, the method is in how to test Supabase RLS. On Firebase the same idea applies, with the attacks in Firebase security rules examples.

What can you show a buyer?

The output of this run: the list of paths, the result of each, and the date. That is more than “we have RLS”, and it does not replace a pentest. It says nothing about stolen sessions, logic errors inside a company or the admin tools your own staff use.

Limits. A small schema I wrote, broken on purpose, on a local stack with made-up data. Storage, realtime and edge functions were not part of this run, and they need their own paths on the list. Hosted projects can have different default grants from a local stack, so run it against a copy of your real schema.

If a buyer asks for a penetration test report, what one costs in 2026 is in a separate article.

My similar case

Building a time tracker for an audit firm, I found 4 errors no screen showed, including a confidential client leaking through report totals and tag counts. Every access rule now lives in the database and is tested before each deploy; the full story is in the audit firm case.

If you need a multi-tenant app built with these tests from day one, see SaaS and web app development.

Need to show a client their data is separated? Write to me and we’ll test every path.

Need proof that client data is separated?

Tell me what you have now and what you need. I'll reply with the option I'd pick.

Write to me

© 2026 Denys Zaichenko. Original article: https://madsalt.tech/blog/multi-tenant-isolation-test/