Supabase row level security explained for app builders

Supabase row level security explained for app builders

By Carl Mills - senior cloud, .NET and security engineer • Published 26 November 2026 • Last updated • 7 min read

TL;DR

Supabase row level security explained in one line: it is a set of rules inside your database that decides which rows each visitor can read or change. Your app's publishable (anon) key is public by design, so without RLS anyone who finds it can read and write every table in your public schema. Turn RLS on for every table, then add a policy for each action you actually want to allow.

What row level security does, in plain English

Here is Supabase row level security explained without the jargon: it's a rule book that lives inside your database and is checked on every single request. The rule book says things like "a signed-in user can read their own orders" or "nobody can delete a profile". Supabase describes it as "granular authorization rules that run inside the database", and each rule (a policy) works like an extra filter added to every query.

Why it matters more for Supabase than for a traditional app: in a Lovable, Bolt or v0 app, your browser talks to the database directly. There's often no backend in between checking who is allowed to do what. The key your app uses to connect, the publishable key (called the anon key in older projects), is shipped in your frontend for anyone to read. Supabase's own API keys guide says that's fine, because RLS "decides what this client can reach, so enable it on every table before you deploy".

So the publishable key is like the front door of a block of flats: everyone can walk in. RLS is the lock on each flat. Without it, every flat is open.

What happens when RLS is off

Supabase's documentation is blunt about it: "A table in an exposed schema without RLS is readable and writable by any role with a grant on it." On a standard project, tables in the public schema are granted to the anon role, which is what an unauthenticated visitor uses.

In practice that means anyone can open your site, copy the publishable key from the browser's network tab, and call the Supabase API directly. They can list every customer, change other people's records, or delete the lot. Hiding a button in your UI doesn't stop them, because they never use your UI.

This isn't theoretical. In 2025 a researcher found that apps built on Lovable were exposing data through missing or weak RLS policies. Superblocks' write-up of the incident reports a follow-up scan that found 303 endpoints across 170 projects without proper RLS, with exposed data including emails, phone numbers, payment status and API keys. It was recorded as CVE-2025-48757 (CVSS 9.3, critical), which Lovable disputes on the basis that each customer is responsible for their own policies. The lesson for builders is the same whoever you blame: your tool may not set RLS up correctly, so you have to check.

The 12-point vibe coding launch checklist puts this at the top of the list for the same reason.

How to tell if Supabase RLS is disabled (five minutes)

You don't need to read code for this. Do it in your Supabase dashboard:

  1. Run one query. Open the SQL editor and run:

    select tablename, rowsecurity
    from pg_tables
    where schemaname = 'public';
    

    Every table should show true. Any false is a table open to the internet.

  2. Check the Security Advisor. In the dashboard, the advisor lists public tables without RLS and other common mistakes. Fix every security warning before launch.

  3. Check the policies, not just the switch. RLS turned on with a policy that says "allow everything" is no better than RLS off. In the dashboard, open the policies for each table and read every one. A policy for select that is just true means "anyone can read every row".

  4. Test as a stranger. Open your app in a private browser window, signed out. If you can see data that belongs to a user, so can everyone else.

  5. Look for the secret key in your frontend. Search your code for service_role or sb_secret_. Supabase says the secret key bypasses RLS completely and must never be in a browser, a shipped app or source control. If it's there, move it to the server and rotate it.

The Lovable security checklist and Bolt security checklist cover the platform-specific places to look.

The four Supabase RLS policies most apps need

Most AI-built apps have tables where each row belongs to one user: profiles, orders, notes, projects. For those, you need one policy per action. Here's the pattern from the Supabase docs, for a profiles table with a user_id column:

alter table profiles enable row level security;

create policy "Users can view their own profile"
on profiles for select
to authenticated
using ( (select auth.uid()) = user_id );

create policy "Users can create their own profile"
on profiles for insert
to authenticated
with check ( (select auth.uid()) = user_id );

create policy "Users can update their own profile"
on profiles for update
to authenticated
using ( (select auth.uid()) = user_id )
with check ( (select auth.uid()) = user_id );

create policy "Users can delete their own profile"
on profiles for delete
to authenticated
using ( (select auth.uid()) = user_id );

What each part means:

Part Plain English
for select / insert / update / delete Which action the rule covers. No policy for an action means that action is refused.
to authenticated Only signed-in users. Supabase says to always name the role: a policy without one also applies to signed-out visitors.
auth.uid() The ID of the user making the request.
using (...) Which existing rows the user can see or touch.
with check (...) What a new or changed row must look like. It stops a user creating a row in someone else's name.

Wrapping auth.uid() in (select ...), as every example in the Supabase docs does, lets Postgres work it out once per query instead of once per row. Add an index on user_id too, or large tables get slow.

If you don't need an action, leave its policy out. Plenty of apps never let users delete anything, and the safest delete policy is the one you never wrote.

Mistakes that leave data exposed with RLS on

Turning RLS on is the start, not the finish. These are the patterns to look for:

Mistake Why it leaks Fix
A policy of using (true) for select Anyone can read every row Only keep it for genuinely public data, such as a product catalogue
No to role on the policy It applies to signed-out visitors too Add to authenticated
An update policy with no with check A user may be able to move a row to another user Add with check matching using
A view over a protected table Supabase says views bypass RLS by default Create views with security_invoker = true, or don't expose them
Using user-editable profile data to decide roles Users can change their own metadata Store roles in a table only an admin can write
The secret key in an edge function that trusts the caller It bypasses RLS, so the function must check who's calling Check the user's identity in the function before any query

The PostgreSQL documentation adds one more: table owners normally bypass row security. That's why testing in the SQL editor (which runs as an owner) can look fine while the real API behaves differently. Test through your app, signed in as one user and then another.

The worst mistake I've seen is also the simplest: RLS was never switched on for the users table. The app worked perfectly in the browser, so nobody noticed, but the publishable key in the frontend let anyone list every customer's email address and profile. No policy was wrong, because there were no policies at all. That's why the first check above is the switch itself, table by table.

What to do if you find a table with RLS off

If the query in step one shows false on a live app, act in this order:

  1. Turn RLS on for that table now. Your app may break for that table, but data stops leaking. Supabase says that with RLS on and no policies, nothing is returned through the publishable key.
  2. Add the policies your app needs, one action at a time, and test after each.
  3. Rotate keys if the secret key was ever in your frontend or your repository.
  4. Work out what was exposed. Check which tables were open and for how long. If they held personal data, read the ICO's guidance on reporting a personal data breach (UK), or your local regulator's, and decide whether you have to report it.

If the app is already in a mess, AI broke your project. Now what? walks through getting back to a working state, and own your AI-built app covers making sure the Supabase project is in your account, not the tool's.

When to get a second pair of eyes

RLS is easy to get almost right. The query above tells you if the switch is on; it can't tell you whether each policy does what you think. If your app stores payments, health data or anything about children, or you're about to send it to paying customers, have someone who reads SQL check the policies table by table before launch. The OWASP security guide for vibe coders explains why broken access control is the most common serious web app flaw, and what else to check while you're there.

Frequently asked questions

What is row level security in Supabase?

Row level security (RLS) is a Postgres feature that Supabase uses for authorisation. Each table gets policies, which work like an extra WHERE clause added to every query, so a signed-in user only sees or changes the rows the policy allows. The rules run inside the database, so they apply however the request reaches it.

Is it safe to put the Supabase anon key in my frontend?

Yes, but only with RLS on. Supabase's API keys guide says publishable keys are safe to expose in a web page or mobile app, and that RLS decides what that client can reach, so it should be enabled on every table before you deploy. The secret (service_role) key is different: it bypasses RLS and must never be in the browser.

What happens if I enable RLS and add no policies?

Nothing is returned. Supabase's docs say that once RLS is enabled, no data is accessible through the API with a publishable key until you create policies. That's the safe failure: your app looks broken, but no data leaks. Add policies one action at a time until it works again.

How do I check if RLS is turned off on my Supabase tables?

Open the SQL editor in your Supabase dashboard and run: select tablename, rowsecurity from pg_tables where schemaname = 'public'; Any row where rowsecurity is false is a table anyone with your publishable key can read and write. The dashboard's Security Advisor also warns about public tables without RLS.

Does Lovable set up row level security for me?

It may create some policies, but don't assume they're right. CVE-2025-48757 recorded that insufficient RLS policies in Lovable-generated sites up to 15 April 2025 let unauthenticated attackers read or write database tables, a claim Lovable disputes because each customer controls their own policies. Either way, check every table yourself before launch.

Does the service role key respect row level security?

No. Supabase's docs describe the service_role (secret) key as full access that bypasses RLS, which is why it must stay on the server, in an edge function or a backend, and never in the browser, a shipped app or source control.

Sources

  1. Row Level Security - Supabase Docs
  2. API keys - Supabase Docs
  3. CVE-2025-48757 - Intruder CVEmon
  4. Lovable vulnerability explained: how 170+ apps were exposed - Superblocks
  5. Row Security Policies - PostgreSQL Documentation
  6. Report a breach - Information Commissioner's Office
Carl Mills

About the author

Carl runs Sentido Ltd, a UK software consultancy. He has spent his career shipping and running production systems on Azure and .NET, and now helps founders and small businesses get AI-built software safely into production. More about Carl.

Want an engineer to check it before you launch?

The Launch Check is a fixed-price review of an AI-built app: an automated scan plus manual triage, with a Fix-First report.

See the Launch Check