Supabase database
“Why can I see everyone’s invoices?” The two-account test
If one customer can see another customer’s invoices, orders or messages, the app is filtering rows in the page, not in the database. You can find out in ten minutes with two test accounts: sign in as the second one and ask for the first one’s records by id. To fix it, every table holding customer data needs row level security on and a policy that compares the row’s owner with the signed-in user, and any server route that uses a secret key must filter by the user itself.
TL;DR
- The builder never sees this bug, because the builder is the only user. It shows up when the first two real customers sign in.
- In the PatchLabs study of 318 rebuilt apps, 32 (10%) leaked personal data only to signed-in users (re-checked 24 Nov 2026). Tests that stay signed out cannot see this group.
- The usual cause is a policy like
using (true)forauthenticated, or RLS left off. One query below lists both. - Server routes that use the secret key skip RLS completely, so they need their own check on who is asking.
- Ask your AI tool to write the two-account test as a test, so the next change cannot quietly undo the fix.
This guide is for founders whose app was built with Lovable, Bolt, Cursor or Claude Code on Supabase, and anyone reviewing such an app for a client. The SQL runs on any Supabase project; we tested every query below on Postgres 17 and 18 against a synthetic invoices table. Run the tests only on an app you own or have permission to test.
Why the builder never sees it
While you build, you are the only user. Every invoice in the database is yours, so a page that lists “all invoices” and a page that lists “my invoices” look the same. The difference appears on the day a second real customer signs in.
AI tools make this more likely in two ways. First, the page often filters with .eq('user_id', user.id), which hides other people’s rows on screen but does nothing to stop a request that leaves the filter out. Second, when a query fails because of RLS, a common quick fix is a policy that lets every signed-in user read every row. The app starts working, and the leak ships with it.
Signed in is not a security boundary. If anyone can create an account, a stranger signs up with a throwaway email and gets the same authenticated role as your paying customers. In our study, 32 of 318 apps (10%) leaked personal data only to signed-in users on our 24 Nov 2026 re-check. They look closed to any scan that stays signed out.
This is how real breaches happen: the credit union case
On 18 November 2026, BleepingComputer reported that member data from about 40 Irish credit unions was exposed through their shared IT provider, Wellington IT. According to the notices the Irish Examiner saw, the attacker signed in with valid credentials, and an automated script then made five million requests between 2 and 4 October that exploited an authorization flaw. The exposed records were saved payees: names, IBANs, account numbers and sort codes. The provider also lacked the activity logs that would show which members were affected.
That is the same bug as in this guide, at scale. Three lessons carry over to any AI-built app:
- Being signed in proved nothing. The attacker had a real login. Your app’s rules must hold for a real, signed-in user who is not the owner of the row.
- Nobody walks five million ids by hand. Once one request leaks, a short script reads every row. One leaking table means all of its rows, not one customer.
- Without logs you cannot tell people what was taken. Before you need them, check how long your plan keeps API logs and whether they show which user asked for what.
The two-account test, in ten minutes
- Create two test accounts, A and B, with emails you control.
- As A, create a record: an invoice, an order, a message, a file. Note its id from the URL or the network tab.
- Sign out, sign in as B, and open the same URL with A’s id. Then try the list page. If you see A’s record, the rule lives in the page, not the database.
- Ask the database directly as B. The page may hide a row the API still returns, so call the API with B’s token:
# Your own project only. Sign in as test user B and keep the access token.
curl -s "https://YOUR-PROJECT.supabase.co/auth/v1/token?grant_type=password" \
-H "apikey: YOUR_PUBLIC_KEY" -H "Content-Type: application/json" \
-d '{"email":"user-b@example.com","password":"TEST_PASSWORD"}'
# As B, ask for every invoice, with no filter.
curl -s "https://YOUR-PROJECT.supabase.co/rest/v1/invoices?select=id,user_id&limit=20" \
-H "apikey: YOUR_PUBLIC_KEY" -H "Authorization: Bearer B_ACCESS_TOKEN"
# Every user_id in the reply should be B's. Any other user_id is a cross-customer leak.Repeat step 4 for every table that holds customer data, not only the one you noticed. Tables are usually created in batches by the same prompt, so if one has the bad policy, its siblings often do too.
Find the policies that never check the user
Run this in the Supabase SQL editor. It lists tables that signed-in users can read where RLS is off, or where a read policy for authenticated never mentions who is asking.
-- Tables a signed-in stranger may read across users
select c.relname as table_name,
case when not c.relrowsecurity then 'RLS off: every signed-in user reads every row'
else 'policy "' || p.policyname || '" never checks the user: ' || coalesce(p.qual, '(no condition)') end as problem
from pg_class c
join pg_namespace n on n.oid = c.relnamespace and n.nspname = 'public'
left join pg_policies p on p.schemaname = 'public' and p.tablename = c.relname
and p.cmd in ('SELECT', 'ALL') and p.permissive = 'PERMISSIVE'
and (p.roles && array['authenticated', 'public']::name[])
where c.relkind in ('r', 'p')
and has_table_privilege('authenticated', c.oid, 'SELECT')
and ( not c.relrowsecurity
or (p.policyname is not null and coalesce(p.qual, 'true') !~* 'auth\.(uid|jwt)\(\)|current_setting') )
order by 1;On our test database it returned the two tables we planted: invoices with a policy whose condition was true, and notes with RLS off. After the fix below it returned nothing.
It is a first pass, not a proof. A policy can mention auth.uid() and still be wrong, for example by comparing it with the wrong column, or by joining a team table that any user can add themselves to. Some tables are meant to be shared, such as a public price list. Read each row it returns and decide. For team apps, see multi-tenant RLS.
Fix it in the database
Replace the open policy with one that ties each row to its owner. Wrapping auth.uid() in a select lets Postgres evaluate it once per query instead of once per row, which Supabase recommends for speed.
drop policy "Authenticated users can view invoices" on public.invoices;
create policy "Users read their own invoices" on public.invoices
for select to authenticated
using ((select auth.uid()) = user_id);
-- A table that had RLS off: turn it on, then add the owner policy.
alter table public.notes enable row level security;
create policy "Users read their own notes" on public.notes
for select to authenticated
using ((select auth.uid()) = user_id);Do the same for insert, update and delete, with with check on insert and update so a user cannot write a row with someone else’s user_id. If your table has no owner column, that is the real fix: add one, fill it, and make it not null.
The trap: server routes with the secret key
RLS only protects requests made with the public key and a user’s token. A server route, API route or Edge Function that creates its client with the secret (service_role) key skips every policy. If that route takes an id from the URL and returns the row, any signed-in user can read any invoice by changing the number.
// Synthetic example. Risky: secret key, and the id comes straight from the URL.
const admin = createClient(SUPABASE_URL, SUPABASE_SECRET_KEY)
const { data } = await admin.from('invoices').select('*').eq('id', params.id).single()
// Safer: check who is asking, then filter by the owner as well as the id.
const { data: { user } } = await userClient.auth.getUser() // client built from the request's session
if (!user) return new Response('Unauthorized', { status: 401 })
const { data: invoice } = await userClient.from('invoices')
.select('*').eq('id', params.id).eq('user_id', user.id).single()Best of all, use a client built from the user’s session for anything a user asks for, so RLS applies, and keep the secret key for jobs no user triggers, like webhooks and cron tasks. If the secret key appears in browser code at all, treat it as leaked: rotate it.
Keep it fixed: make the test part of the app
Fixes made by an AI tool can be undone by the next prompt that hits a permission error. A test stops that. This one runs as user B inside a transaction, counts the rows B can see that belong to someone else, and changes nothing:
begin;
set local role authenticated;
set local request.jwt.claims = '{"sub":"USER_B_UUID","role":"authenticated"}';
select count(*) filter (where user_id <> auth.uid()) as other_users_rows, -- must be 0
count(*) filter (where user_id = auth.uid()) as own_rows -- should be above 0
from public.invoices;
rollback;On our test table it returned 1 other user’s row before the fix and 0 after, while user B still read their own invoice. Checking own_rows matters: a fix that hides everything from everyone passes the first check and breaks the app.
When you prompt your AI tool, ask for this outcome rather than “make it secure”: “For every table with a user_id, write a test that signs in as two different users and proves neither can read, change or delete the other’s rows, and that each can still read their own.”
Questions people ask
My page already filters by the user. Isn’t that enough?
No. The filter runs in the browser, and anyone can send the same request without it, using the public key and their own token. Only the database policy, or a server route that checks the user, decides what comes back.
RLS is on for every table. Am I safe?
Not necessarily. RLS with a policy of using (true) for authenticated lets every signed-in user read every row. Turning RLS on is step one; the policy decides who sees what. The query above finds this case.
Can random ids (UUIDs) protect the records instead?
They make ids hard to guess, but list endpoints and joins hand them out anyway, and an unfiltered request needs no id at all. Treat random ids as a nice extra, not as access control.
A customer told me they saw someone else’s data. What now?
Close the policy first, then work out who could see what and since when. Our first hour after a leak runbook covers logs, timelines and when the reporting clock starts.
Sources
- BleepingComputer: Data breach impacts 40 Irish credit unions in reported IT provider hack (18 Nov 2026, citing notices seen by the Irish Examiner and RTÉ; checked 22 Nov 2026)
- Supabase docs: Row Level Security, including the
(select auth.uid())performance advice (checked 21 Nov 2026) - Supabase docs: API keys, on secret keys bypassing RLS (checked 21 Nov 2026)
- OWASP API Security Top 10: Broken Object Level Authorization, the general name for this bug (checked 21 Nov 2026)
- PatchLabs: the 1-in-4 report, 318 public apps rebuilt from their migrations (Nov 2026)
Related findings
The checks behind this guide, each with example code, a self-check and the fix.
Any signed-in user can read every row
PL-005Always-true policy
PL-008Row level security not enabled
PL-010Service role key in client code
Free check
Check your app for this, free.
Paste your public repo. PatchLabs rebuilds your database from its migrations, tests it as a visitor, a stranger and the owner, reads the code for keys and risky patterns, and hands you the fix.
Written by Manraj Singh Dhillon. Last checked 22 Nov 2026. Code samples are synthetic and run against your own project; nothing here names a real app. Spotted a mistake? Tell us.