Supabase Row-Level Security, explained
Published 21 October 2026 · 7 min read
If you built your app on Supabase, there is one setting that decides whether your users' data is private or quietly available to anyone: Row-Level Security (RLS). Get it right and the database enforces your rules for you. Skip it, and the key sitting in every visitor's browser can be used to read or change rows it should never touch.
This guide explains RLS in plain English, shows you how to turn it on, gives you copy-paste example policies, and walks through the three mistakes that trip up almost every no-code and AI-built app.
Why the key in the browser is not a secret
Supabase gives your app two main keys. The anon key (the "public" or "publishable" key) ships to the browser so your front end can talk to the database. The service-role key is an all-powerful admin key that is meant to live only on a server and bypasses every security rule.
Here is the part people miss: the anon key is public by design. Anyone can open your site, find it in the network requests, and start making their own database calls. It is not a password. The only thing standing between that key and your data is the set of rules you write. Those rules are Row-Level Security.
What Row-Level Security actually does
RLS lets the database check, row by row, whether the current request is allowed to see or change that specific row. Instead of trusting your app's code to filter data correctly, the rule lives in the database and applies to every query, no matter where it comes from.
A policy typically compares the logged-in user's ID to a column on the row. Supabase exposes the current user's ID through the function auth.uid(). So a rule like "you can only read rows where user_id equals your own ID" means that even if someone asks for every row in the table, the database hands back only theirs.
One critical detail: when RLS is turned on but no policy exists, the default is to deny everything. That is the safe default. The danger is the opposite case, where RLS is never turned on at all.
How to enable RLS on a table
In the Supabase dashboard, open Table Editor, select your table, and look for the RLS toggle, or go to Authentication → Policies. You can also do it in the SQL editor:
alter table profiles enable row level security;turns RLS on for theprofilestable.- Once enabled, the table returns nothing until you add at least one policy that grants access.
Do this for every table that holds user or business data, including join tables and anything you created quickly during a build.
Example owner-based policies
These assume a table with a user_id column that stores the owner's ID. They give each user access to only their own rows:
- Read your own rows:
create policy "read own rows" on todos for select using (auth.uid() = user_id); - Update your own rows:
create policy "update own rows" on todos for update using (auth.uid() = user_id) with check (auth.uid() = user_id); - Insert rows as yourself:
create policy "insert own rows" on todos for insert with check (auth.uid() = user_id); - Delete your own rows:
create policy "delete own rows" on todos for delete using (auth.uid() = user_id);
The using clause controls which existing rows a user can see or act on. The with check clause controls what new or updated rows are allowed, which stops someone from writing a row and stamping it with someone else's user_id. Write separate policies for select, insert, update, and delete so each action is deliberate.
The three mistakes that cause data leaks
- Forgetting to enable RLS. A table with RLS off is wide open to anyone holding the anon key, which is everyone who visits your site. This is the single most common cause of exposed data in no-code apps. Supabase warns you about it, but it is easy to click past.
- Policies that are too permissive. A rule like
using (true)grants access to every row to every user. People add these to "just make it work" during development and forget to tighten them. If a policy does not referenceauth.uid()(or your own ownership logic), assume it is giving away too much. - Leaking the service-role key. This key ignores RLS entirely. It must never appear in front-end code, a public repo, a mobile app bundle, or a client-side environment variable. If it leaks, your policies no longer matter. Keep it strictly server-side, and rotate it immediately if you suspect it was exposed.
A quick checklist
- RLS is enabled on every table with real data.
- Every table has explicit policies for select, insert, update, and delete.
- No policy uses
using (true)unless the data is genuinely meant to be public. - The service-role key exists only on your server, never in the browser or a repo.
- You tested as a logged-out visitor and as a second user to confirm you cannot see other people's rows.
Check your app in 30 seconds
Run Faultline's free surface scan on any app in seconds. (Deep data-exposure scanning is live for Base44, with more platforms rolling out.)
Run a free scanFaultline's free surface scan checks any website's TLS, security headers, and DNS/email hygiene, which is a solid first look at your exposure. It does not yet deep-scan Supabase data, so for RLS the best move is the manual checklist above: open each table, confirm RLS is on, and review every policy. Our deep data-exposure engine is live for Base44 today and rolling out to more platforms.
Related: Is Supabase secure? · Is Lovable secure?