Short answer
Row level security (RLS) is a Postgres feature that checks every row against rules, called policies, before a query may read or change it. In a Supabase app the browser talks to the database with a public key, so RLS is what keeps one user’s rows away from everyone else. Enable it on every table in the public schema and add a policy per action.
Ask an AI about this page:ChatGPTClaude
On this page
Row level security (RLS) is a Postgres feature that checks every row against rules, called policies, before a query may read, insert, update or delete it. Postgres applies the rules inside the database, so they hold no matter which app, script or API sent the query. When RLS is on and no policy allows an action, the answer is no.
Row level security in an AI-built app
An app built with Lovable, Bolt or a similar tool usually has no server of its own between the browser and the data. The React frontend calls Supabase directly, for example supabase.from("notes").select(), using the project URL and the public anon or publishable key. Anyone can copy both from the site’s JavaScript.
That is fine as long as the database knows who may see which row. Without RLS, a table the public roles can reach is answered in full: every visitor can read every user’s notes. A filter like .eq("user_id", userId) in the frontend does not help, because a caller who copies the key simply leaves it out. RLS moves the check into Postgres, where the caller cannot remove it. Leaving it out is a case of missing authorization (CWE-862 (opens in a new tab)).
How to check your app
Open Advisors → Security Advisor in the Supabase dashboard. Lint 0013 (rls_disabled_in_public) flags tables in the public schema without RLS, and lint 0007 flags tables that have policies while RLS is still off.
You can also list the unprotected tables yourself in the SQL Editor:
select c.relname as table_name
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public'
and c.relkind in ('r', 'p')
and not c.relrowsecurity;Every row it returns is a table the Data API can serve without any row check. The SQL Editor itself runs as an admin role that skips RLS, so to see what a user sees, test as that user (see How to test your RLS policies).
How to fix it
Turn RLS on and add one policy per action. The smallest owner-only setup for a notes table looks like this:
alter table public.notes enable row level security;
create policy "Owners read their notes"
on public.notes for select
to authenticated
using ((select auth.uid()) = user_id);Add matching insert, update and delete policies the same way. The full pattern, with with check and an index on user_id, is in our Supabase row level security guide, and the step-by-step fix for an unprotected table is on Table without RLS.
Frequently asked questions
Is RLS on by default in Supabase?
Not for every table. In Postgres a new table starts with RLS off, and tables created by SQL migrations, which is how AI builders usually create them, only get it if the migration turns it on. Check every table in the public schema.
What happens when RLS is enabled but there is no policy?
Postgres denies by default: no row can be read or changed through the public or signed-in roles. The app looks broken, but the data is safe. Add the policies you need instead of switching RLS off again.
Does the secret or service_role key respect RLS?
No. It maps to the service_role role, which has the BYPASSRLS attribute, so it skips every policy. That is why it must stay on the server.
Sources
- 1.Row Level Security — Supabase Docs
- 2.Row Security Policies — PostgreSQL Documentation
- 3.Performance and Security Advisors — Supabase Docs
- 4.CWE-862: Missing Authorization — MITRE