What is Supabase RLS, and how to check your customers' data isn't exposed
Updated · by the Bologu team
Most apps built with Lovable, Bolt or Cursor use Supabase as their database and let the web page talk to it straight from the browser. That is convenient and can be safe, with one condition: every table must have Row Level Security (RLS) turned on, with correct policies. Without that, anyone who opens your site can read, change or delete every customer’s data.
Why a Supabase key is allowed in your web page
Press F12 on a site that uses Supabase and you’ll see the project URL and a key (the publishable key, or the older anon key). That isn’t a mistake: this key is designed to be public. It only says “this request comes from your app”. The question “which rows may this person see?” is RLS’s job.
Put simply, the key gets you into the building and RLS is the lock on each room. If the rooms aren’t locked, anyone in the building can open all of them.
The other kind of key, the secret key or service_role, bypasses RLS completely. It must only ever live on the server. If you find it in front-end code, treat it as leaked and replace it now (see what to do when an API key leaks).
Common mistakes in AI-built apps
- Tables without RLS: usually tables added later with SQL or a migration the AI wrote, which doesn’t enable RLS automatically.
- Policies open to everyone: such as
using (true), added by the AI “to get the app working”. RLS is on, but it might as well be off. - Policies that only check for a login:
to authenticated using (true)lets anyone who signs up (often for free) see every customer’s data. - Public storage buckets: files users upload, like payment slips or ID cards, can be opened without logging in if you know the file name.
- Roles or credits users can edit: a policy lets users update their whole row, including columns such as
role,is_adminorcredits.
Check it yourself in 5 minutes
1. Look in the Supabase Dashboard
Open the Supabase Dashboard and go to Advisors → Security Advisor. If it reports RLS disabled on tables in the public schema, fix those tables first. In the Table Editor, tables without RLS also carry a warning label.
2. List every table with SQL
Open the SQL Editor and run this. Tables where rowsecurity is false don’t have RLS enabled:
select tablename, rowsecurity
from pg_tables
where schemaname = 'public'
order by rowsecurity, tablename;Then list every policy to spot ones that are just true:
select tablename, policyname, cmd, roles, qual, with_check
from pg_policies
where schemaname = 'public'
order by tablename;3. Try reading as an outsider
Using the key from your own web page, request data from a table without logging in. If you get other people’s data back, so can anyone.
curl "https://<project>.supabase.co/rest/v1/<table>?select=*&limit=5" \
-H "apikey: <publishable key from your web page>"If you get [] (empty) or a permission error, people who aren’t logged in can’t read the table, which is what you want. You still need to check that logged-in users only see their own data.
The fix: enable RLS and show users only their own rows
This example is for a table with a user_id column holding the row’s owner. Change the table name to yours:
alter table public.notes enable row level security;
create policy "owner can read" on public.notes
for select to authenticated
using ((select auth.uid()) = user_id);
create policy "owner can insert" on public.notes
for insert to authenticated
with check ((select auth.uid()) = user_id);
create policy "owner can update" on public.notes
for update to authenticated
using ((select auth.uid()) = user_id)
with check ((select auth.uid()) = user_id);Keep in mind when you ask your AI to fix it:
- Enable RLS on every table in
public. A table with no policies can’t be read through the API at all, which is safer than leaving it open. - Never use
using (true)on personal data. Only use it for data that really is meant for everyone, such as a product list. - Columns like role or credits should only be changed by the server, never through a policy that lets users edit their own row.
- Buckets holding private files must be private, with storage policies that limit each user to their own folder.
- After fixing, open the app with two accounts and check whether one can see the other’s data.
Let Bologu check it
The website scan (free) tells you whether your site talks to Supabase from the browser and which keys are in your pages. The Deep scan actually tries to read every table and bucket as an outsider. The Supabase account audit reads the policies of every table, the Security Advisor results and your Auth settings, then tells you what to fix, with the SQL to do it.
