(Note · · 6 min read)
Is your app leaking other people's rows? A row-level security check
A table in Postgres with Row Level Security switched off is readable by anyone holding your project URL and public key. No break-in is needed; the API hands the rows over. This is the most common way an app built quickly leaks its users' data, and it takes about ten minutes to find out whether yours does.
By Md. Habibur Rahman Shohel, full-stack & AI product engineer in Dhaka
Why the default leaks
Supabase exposes every table in the public schema over its REST API. That is the point of it: the frontend talks to the database directly, using a publishable key that ships in the browser and is meant to be public. What stops one person reading another person's rows is not the key. It is Row Level Security, a Postgres feature that filters every query by who is asking.
Create a table without enabling it and there is no filter. The key is public, the table is exposed, and nothing stands between the two. Supabase's own linter rates this an error rather than a warning, and says so plainly: anyone with the project URL can read, edit and delete everything in that table.
Code generated from a prompt is especially prone to it, because the generator writes the table and moves on to the feature. The schema works, the app runs, the demo passes. Nothing fails until a stranger reads the table.
The three checks to run first
Supabase ships a database linter (Security Advisor in the dashboard). Three of its rules catch most of the damage:
- 0013, rls_disabled_in_public: a table reachable over the API with Row Level Security off. Treat every hit as live data loss, not a to-do.
- 0024, permissive_rls_policy: Row Level Security is on, but a policy reads USING (true), which allows every row to everyone. The lock is fitted and left open.
- 0002, auth_users_exposed: a view in an API-exposed schema that reads from auth.users, which hands out the whole user list, email addresses included.
Fix 0013 by enabling Row Level Security and then writing a policy. Enabling it alone denies everything, which is the correct starting point: nothing is readable until you say who may read it. The usual policy ties a row to its owner.
alter table public.invoices enable row level security;
create policy "own invoices"
on public.invoices
for select
using ( auth.uid() = user_id );Two things that quietly go around it
A view does not inherit the policies of the tables beneath it. By default a view runs with its creator's permissions, normally the postgres role, so a view over a protected table can serve rows the table itself would refuse. That is why exposing auth.users through a view is its own lint. Keep a separate profiles table with only the public fields and fill it from a trigger.
The service role key ignores Row Level Security entirely, by design, because server-side jobs need it. It must never reach the browser or the repository. Search your code for it before you ship, and keep it in server environment variables only.
Test as an outsider, not as yourself
Signed in as the person who built the app, everything looks right. The question is what a stranger sees. Query the table with nothing but the public key and no session, then sign in as a second account and ask for the first account's rows by id. If either returns data it should not, the policy is wrong. Both take a minute in the SQL editor's role switcher.
Do this per table, not per app. Leaks are usually one forgotten table beside a dozen correct ones.
Never fix it by turning the lock off
Two shortcuts show up when the advisor lights up red and the app breaks: disable Row Level Security to make the error go away, or add a policy of USING (true) so queries pass again. Both restore the leak and silence the warning that was telling you about it. If a query stops working after you enable it, the query was relying on there being no rule.
The rule underneath
Row Level Security is one way to enforce something more general: separation has to live in one layer that every request passes through, on the server. Policies on the table are a good place for it, because a query cannot skip the table.
The same rule holds when the enforcement sits in application code instead. On Paylio, the payroll SaaS I build, many companies share one Postgres database and every row carries the company it belongs to; the filter lives in one service layer rather than in each of about 1,200 routes, and every request is permission-checked on the server before it is narrowed to the caller's organisation. Different mechanism, same principle: one place to get right, one place to review. Scattering the check across handlers is what produces the forgotten table.
If you are not sure which of your tables are exposed, run the advisor before you read anything else. It is free, it takes a minute, and it tells you whether this is urgent.
Common questions
What happens if Row Level Security is not enabled on a Supabase table?
Anyone with your project URL and publishable key can read, edit and delete every row in it. The key is meant to be public and ships in the browser, so Row Level Security is the only thing separating one person's data from another's. Supabase's linter rates this an error, lint 0013.
How do I check whether my app is leaking rows?
Open the Security Advisor in the Supabase dashboard and look for lints 0013 (Row Level Security off on an exposed table), 0024 (a policy of USING (true), which allows everyone) and 0002 (a view exposing auth.users). Then query a table with only the public key and no session, and as a second account ask for the first account's rows.
Does a view respect Row Level Security?
Not by default. A view runs with its creator's permissions, normally the postgres role, so it can return rows the underlying table would refuse. Do not expose auth.users through a view; keep a separate profiles table with the public fields and fill it from a trigger.
Can I just disable Row Level Security to fix the error?
No. Disabling it, or adding a policy of USING (true), removes the warning and keeps the leak. If a query breaks once Row Level Security is on, that query was depending on there being no rule, and the policy is what needs writing.
Is the service role key safe to use in the frontend?
No. It bypasses Row Level Security by design, so it belongs only in server-side environment variables. Search your codebase and repository for it before shipping.