viberrr
Scan my site
vibe-coding · October 22, 2026 · 20 min read

Supabase row level security (RLS), explained for vibe coders

Supabase row level security decides whether your users' data is private or public. What RLS is, how to check your tables, the policies you need and how to test them.

Illustration with a sample app, drawn from this article.

Quick answer: Supabase row level security (RLS) is a set of rules inside your database that decide which rows each visitor can read or change. Your app's Supabase key is public, so RLS is what keeps one user's data from another. Turn it on for every table, write one policy per operation, and test it with two accounts.

Supabase row level security is the setting that decides whether your app's data is private or readable by anyone on the internet. If you built your app with an AI tool, the tool may have created your tables with this setting off, or with a rule that lets everyone in.

This guide explains what RLS is in plain words, how to check every table in five minutes, the handful of policies most apps need (with Supabase's own examples), the mistakes that quietly leave data open, and how to test that your rules do what you meant. It's one of the eight checks to run before you launch a vibe-coded app, and the cause of the Lovable and Moltbook cases described there.

What is Supabase row level security?

Row level security is a feature of Postgres, the database underneath Supabase, that attaches rules to a table. Each rule, called a policy, says which rows a given kind of visitor may see or change. Supabase's documentation puts it simply: "Think of a policy as adding a WHERE clause to every query."

So a policy that says "users can view their own todos" turns every request for todos into "todos where the owner is the person asking". The filter is applied by the database itself, so it holds no matter what the app's code forgets to do.

RLS off

Anyone with your public URL can read and write every row in the table.

RLS on

Each user can read only their own rows. The public key is safe to ship.

Without row-level security, the public key reads every row. With a policy, each user reaches only their own.

There are two parts to the check, and it helps to know both. In Supabase's words: "Postgres runs two checks before a client touches a table. Grants decide whether a role can run an operation on the table at all. Policies decide which rows that operation applies to. Set both for every table you expose."

  • Grants answer: may this kind of visitor read, add, change or delete in this table at all?
  • Policies answer: which rows?

Supabase sorts every request into a role. A visitor who isn't signed in is anon. A signed-in user is authenticated. Your policies are written for those two.

Why does RLS matter so much in an AI-built app?

Because of how these apps are often wired: the browser talks straight to Supabase, using a public key that ships to every visitor. That's by design, and Supabase says exactly when it's safe: "Your publishable key is safe to expose with RLS enabled". The other side of it is in its guide to tables: "Until you enable row level security and write a policy, anyone holding your project's publishable key can read and write every row in it."

Everyone holds your publishable key. It's in the page.

Then comes the detail that catches AI-built apps in particular. Whether a new table starts protected depends on how it was created:

How the table was madeRLS when it's created
In the Supabase dashboard's Table EditorOn. "The Table Editor enables row level security for you when you create a table in the Dashboard."
With SQL, a migration or another toolOff until you turn it on. "When you create a table with SQL, enable it yourself."

AI coding tools create tables with SQL. UpGuard's researchers made the same observation in a 2026 study of exposed Supabase apps: tables created programmatically, "which is how coding agents interact with Supabase, do not enable RLS by default". The safe default exists. Your agent may have walked around it.

Same database, two starting points. Check every table instead of assuming.

(A note on names: Supabase is replacing its older anon and service_role keys with "publishable" and "secret" keys, and says it is "deprecating the anon and service_role keys by the end of 2026". A tutorial or an AI tool that talks about the anon key means the publishable one. The rules in this guide are the same for both.)

How often does this go wrong?

Often enough that several teams have measured it. Each of these scanned public apps from the outside, with a stated method.

Who and whenWhat they scannedWhat they found
Matt Palmer, March 20251,645 apps in Lovable's public showcase170 apps (about 10.3%) with inadequate RLS settings; Lovable disputes the resulting CVE
Modern Pentest, January 202671 Y Combinator startups using Supabase20 (28%) exposing personal data through misconfigured databases
Symbiotic Security, June 20261,072 vibe-coded apps using Supabase39 sites with tables fully readable by anyone holding the public key
UpGuard, September 2026About 300,000 domains showing signs of Supabase16,326 databases exposing readable tables

Read those numbers with care. They aren't comparable: each team picked its sample and its test differently. Three are security vendors, and the fourth works at a competitor of the platform he scanned. UpGuard looked for a table named "users", which tilts its results toward personal data, and "readable" isn't always a mistake, because some tables are meant to be public. Modern Pentest started with 107 companies and could analyse 71; its 28% is of the 71.

What they agree on is the direction. Each team that went looking found readable tables in its sample. Supabase's own position, given to TechCrunch after the UpGuard study (which it said it had not seen), is that its projects are "secure by default" and that "customers control how their own projects are configured". Both things are true, which is exactly why the check is yours to run.

Four outside scans, four samples
170
of 1,645 showcase apps
Lovable's showcase, March 2025; Lovable disputes the CVE
20
of 71 startups analysed
Y Combinator companies on Supabase, January 2026
39
of 1,072 vibe-coded apps
Tables readable with the public key, June 2026
16,326
databases with readable tables
From about 300,000 candidate domains, September 2026
Source: Matt Palmer, Modern Pentest, Symbiotic Security and UpGuard; each is linked in the table above. The samples and tests differ, so the numbers don't compare..

How do you check whether your tables are protected?

Three ways, from quickest to most thorough. Do the first two today.

1. Ask the database. Open the SQL Editor in your Supabase dashboard and run this query, which comes from Supabase's own guide:

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

Every table should show true under rowsecurity. Any false is a table with no row rules at all, the state Supabase's Advisor reports as "Table publicly accessible". Then list the policies:

select tablename, policyname, cmd, roles
from pg_policies
where schemaname = 'public'
order by tablename, policyname;

Supabase's advice on reading the result: "Check that every table has at least one policy, and that any table meant to be readable by signed-out visitors lists anon among its roles." If anon appears on a table that holds private data, stop and read that policy.

2. Run the Security Advisor. Supabase ships a set of automatic checks called Advisors. The ones that matter here:

What the Advisor reportsWhat it means
Table publicly accessible"Anyone with your project URL can read, edit, and delete all data in this table because Row-Level Security is not enabled."
Security policy not enforcedA policy exists, but RLS was never switched on for the table, so the policy does nothing
No access rules definedRLS is on with no policies, so nothing can be read through the API. Safe, but your app may be broken
Security policy allows unrestricted accessA policy uses an always-true condition, "which defeats the purpose of having Row-Level Security enabled"
Security policy relies on user-editable dataA policy trusts a value the user can change themselves
View bypasses row-level securityA view is handing out rows the table's policies were meant to withhold

Supabase also emails project owners when a table is created with RLS off, and its Table Editor shows a warning label on such tables. Don't rely on having seen the email.

3. Test from the outside. Checks 1 and 2 tell you rules exist. Only a test tells you they're the right rules. That's its own section below.

How do you turn row level security on?

One line per table:

alter table public.reports enable row level security;

What happens next surprises people, so here it is in advance. The moment RLS is on and no policy exists, the table goes silent. Supabase: "Once RLS is enabled, no data is accessible through the API when using a publishable key, until you create policies." This is Postgres's own rule, from its manual: "If no policy exists for the table, a default-deny policy is used, meaning that no rows are visible or can be modified."

That's the safe failure. Your app will look broken, with empty lists where data used to be, and the temptation is to turn RLS back off. Don't.

Empty lists mean the lock works. Policies are the keys.

Two more things that confuse people at this step:

  • Your queries in the SQL Editor still return everything. The dashboard runs as the database's owner, and "the table's owner and roles with BYPASSRLS aren't subject to policies". Seeing all rows there tells you nothing about what a visitor sees.
  • A blocked read doesn't raise an error. A row filtered out by a policy just isn't there: the request "raises nothing, matches zero rows". A blocked insert, by contrast, fails with error 42501.

Supabase's current guide also has you tidy the grants at the same step, so a role only has the operations it needs:

revoke all on table public.reports from anon, authenticated;

-- Signed-in users manage reports. Signed-out visitors get nothing.
grant select, insert, update, delete on table public.reports to authenticated;

If you want every future table protected automatically, however it's created, Supabase documents an event trigger that enables RLS on each new table. It only covers tables created after you install it: "Existing tables still need RLS enabled manually."

What does a policy look like?

A policy has five parts, and once you can read them you can read any policy your AI tool writes.

create policy "Users can view their own profile."
on profiles for select
to authenticated
using ( (select auth.uid()) = user_id );
PartIn the exampleWhat it says
Name"Users can view their own profile."A label for humans. Make it say what the rule allows
Tableon profilesWhich table the rule protects
Operationfor selectReading. The others are insert, update and delete
Roleto authenticatedWho the rule applies to: signed-in users
Conditionusing ( (select auth.uid()) = user_id )Only rows whose user_id is the person asking

auth.uid() is Supabase's function that "returns the ID of the user making the request". The condition compares it with a column on the row that records who owns it. That one comparison is most of what RLS is.

Once you can read these five parts, you can read any policy your AI tool writes.

Supabase's advice is to "write a separate policy for select, insert, update, and delete", because a single catch-all policy "hides which operation each rule was meant to cover". Here are the other three for the same table, exactly as Supabase gives them.

Adding a row:

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

Changing a row:

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

Deleting a row:

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

What's the difference between using and with check?

using looks at rows that already exist. with check looks at the row as it will be after the change. The Postgres manual: "Existing table rows are checked against the expression specified in USING, while new rows that would be created via INSERT or UPDATE are checked against the expression specified in WITH CHECK."

Operationusingwith check
selectWhich rows you can seeNot allowed
insertNot allowedWhat a new row must look like
updateWhich rows you can changeWhat the row must look like afterwards
deleteWhich rows you can removeNot allowed

The update policy is where this matters. using stops you editing someone else's profile. with check is what, in Supabase's words, "stops a user from reassigning user_id to someone else". If you leave with check out, Postgres reuses the using condition for it, which is safe. The hole opens when with check is written looser than using, such as with check ( true ): then a user can change their own row into one that belongs to someone else.

Which policies does a typical app need?

Most tables in most apps fit one of four shapes. Work out which shape each of your tables is before you ask an AI tool to write anything.

1. Private to its owner. Profiles, settings, notes, orders, uploads. The four policies above. This is the default: if you're unsure, a table is this.

2. Public to read, closed to write. A product catalogue, published posts, announcements. One read policy for everyone and no write policies at all:

create policy "Anyone can read announcements"
on public.announcements for select
to anon, authenticated
using ( true );

using ( true ) means "every row". It's correct here and dangerous anywhere else, which is why the Advisor flags it and asks you to confirm you meant it.

3. Shared between two people. An order has a buyer and a seller; a message has a sender and a recipient. The condition checks both columns:

create policy "Buyers and sellers can view their orders."
on orders for select
to authenticated
using ( (select auth.uid()) in (buyer_id, seller_id) );

4. Shared within a team. A project every member of a workspace can see. The condition asks a membership table whether the person belongs:

create policy "rls_test_select" on test_table
to authenticated
using (
  team_id in (
    select team_id
    from team_user
    where user_id = (select auth.uid()) -- no join
  )
);

That example comes from Supabase's performance guide and has no for clause, so it covers every operation. In your own app, write one policy per operation, as above.

Team policies are where things get subtle. Two tables whose policies read each other never resolve, and Postgres stops with an "infinite recursion detected in policy" error. Supabase's guide shows the fix, a small helper function kept in a private schema. If your app has teams, ask your AI tool to follow that section of the row level security guide to the letter, and test it harder than anything else.

Which mistakes leave data open even with RLS on?

RLS being switched on proves a lock is fitted. It says nothing about who has keys. These are the ways a table stays open with RLS on.

  1. A policy that lets everyone in. using ( true ) on a private table. It makes an error go away, which is how it ends up there. Supabase's linter describes the result: "While RLS appears to be enabled on the table, these permissive policies allow unrestricted access to all rows".
  2. An update policy whose with check is looser than its using. For example with check ( true ). Covered above.
  3. Trusting user_metadata. A policy like "allow if the user's metadata says admin" looks sensible and is wide open. Supabase's warning: "Any signed-in user can add, overwrite, or remove fields in their user_metadata, and Supabase Auth doesn't check the values." Roles and tenant ids belong in app_metadata, which users can't change.
  4. Several policies on one table. They add up; they don't narrow each other. "If any policy allows access, the access is granted." One loose policy left over from an experiment undoes three careful ones.
  5. Views. "Views bypass RLS by default", so a view built on a protected table can hand out every row. On current Postgres the fix is to create the view with security_invoker = true.
  6. Functions that run as the owner. A security definer function "can return rows the caller isn't allowed to read", and "any role can call it by default, including anon".
  7. The secret key in the browser. The secret (or service-role) key bypasses RLS. With it in the page, none of the above matters. See which API keys are safe to expose in the frontend.
  8. Forgetting file storage. Files have their own policies on a table called storage.objects. And a bucket marked Public skips them for downloads: "Anyone with the asset URL can access the file."
  9. Forgetting new tables. RLS is per table. The table your agent adds next Tuesday starts wherever its SQL leaves it.

One quieter trap is worth knowing. When nobody is signed in, auth.uid() returns nothing, and a comparison with nothing is never true. So a policy "will silently fail for unauthenticated users". That fails closed, which is good, but Supabase still recommends naming the role with to authenticated on every policy so the intent is written down and the check doesn't even run for signed-out visitors.

How do you test that your policies work?

The Postgres manual's advice is one line: "it's important to test and ensure that the system is behaving as expected." Supabase is blunter about untested policies: "you don't know whether the policies do what you intended."

Three levels, in order of effort.

The two-account test (ten minutes, no code). Create two accounts in your own app. As account A, make something: a note, an order, a profile. Then sign in as account B and try to reach it, by its address, by changing an id in the address bar, through search, through any list. Then sign out and try again. You should get nothing each time. This catches the failures that matter most, and it works for any stack.

The quickest real test of a policy, and it needs no code.

Asking the database as a visitor (five minutes, a little SQL). In the SQL Editor you normally see everything. You can ask the database to answer as a signed-in user instead, using a pattern from Supabase's docs:

set session role authenticated;
set request.jwt.claims to '{"role":"authenticated", "sub":"USER-ID-HERE"}';

select * from profiles;

set session role postgres;

Put a real user's id in place of USER-ID-HERE. You should see only that user's rows. Swap in a different user's id and you should see a different set. Run it with set session role anon; and a private table should return nothing, or a permission error if you revoked its grants.

Written tests (for apps with real users). Supabase's guide now treats tests as part of setting up a table, not an extra. They live in your project and run with one command, supabase test db, and each test file "asserts allow and deny for select, insert, update, and delete, for anon and authenticated". The docs include a prompt to hand to your AI tool that ends with a rule worth copying into any prompt you write yourself: "Don't change a policy to make a test pass. Tell me which assertion and policy disagree."

That last line names the real risk with an AI tool. Asked to make a failing test pass, it has two options: fix the app, or loosen the rule. Loosening is easier.

Does row level security slow your app down?

It can, on large tables, and the fixes are small. Supabase explains the cost: "Postgres evaluates a policy expression against each candidate row, so the cost scales with the rows a query scans."

Three habits cover the common cases, and they're already in the examples above.

  1. Index the column your policy compares. "Add an index on every column your policies filter on." For a user_id column that's one line: create index on profiles (user_id);
  2. Wrap the function in a select. Writing (select auth.uid()) instead of auth.uid() lets Postgres work the value out once per query "rather than calling the function on each row".
  3. Name the role. to authenticated means the policy doesn't run at all for signed-out visitors.

Supabase's knowledge base publishes timings from tests on a 100,000-row table. Three rows from it:

ChangeBeforeAfter
Add an index on user_id171under 0.1
Wrap auth.uid() in a select1799
Add to authenticated (signed-out visitor querying)170under 0.1

The page labels the first figure in milliseconds and prints the rest without a unit. They're one set of tests on one table, so treat them as the size of the effect, not a promise. The point is that a slow app is never a reason to turn RLS off. It's a reason to add an index.

What doesn't row level security do?

It's one control, and it has edges.

  • It doesn't apply to the secret key, the database owner, or the dashboard. Anything running with those sees everything. That's what they're for, and why the secret key lives only on a server.
  • It doesn't apply to functions. Supabase: "RLS doesn't apply to functions, so grant execute only to the roles that need to call them."
  • It doesn't hide columns. A policy decides which rows. If a user may see their own row, they see all of it, including any column you'd rather the browser never received.
  • It doesn't check that your rules are the right rules. A scanner, such as Supabase's own, can tell you a table has RLS and a policy. Only you know that "members can read invoices" should have said "admins".
  • It doesn't cover live updates of deletions. If you use Supabase Realtime to watch a table, "RLS policies are not applied to DELETE statements".
  • It doesn't replace a check on your server for anything that involves money, limits or someone else's account.

If your app holds health, financial or children's data, have a professional review your policies before launch. The checks here find the common mistakes; they don't certify a design.

What prompt should you give your AI builder?

Something close to this, which follows Supabase's current guidance. Supabase also publishes its own prompt for writing RLS policies, written for AI tools.

For every table in the public schema of my Supabase database:

1. Tell me which of these it is: private to its owner, public to read,
   shared between two users, or shared within a team. Ask me if unsure.
2. Enable row level security. Revoke all grants from anon and authenticated,
   then grant back only the operations each role needs.
3. Write a separate policy for select, insert, update and delete. Name the
   role with "to". Use (select auth.uid()). Give every update policy both
   "using" and "with check".
4. Never use "using (true)" on a table with private data, never read
   user_metadata in a policy, and never turn RLS off to fix an error.
5. Add an index on every column a policy compares.
6. Show me the SQL and explain each policy in one plain sentence before
   applying anything.

Then run the two queries from the checking section, and the two-account test.

The prompt is the request. The test is the proof.

Where does viberrr fit?

A SafeLaunch check doesn't test your tables: it checks your live site from the outside for keys exposed in code anyone can download (a service-role key in the browser, say), open .env and .git files, security headers and HTTPS. Row level security stays yours to check, with the steps above. Our page on the Supabase RLS issue goes through it.

Deciding whether your policies say what your app means is the part this guide keeps returning to: the two-account test, and it's yours. How we verify an app lists what the scan covers and what it doesn't, and vibe coding security covers the rest of the picture.

Frequently asked questions

What is RLS in Supabase?

RLS (row level security) is a Postgres feature that Supabase uses to control which rows each visitor can read or change. You attach policies to a table, and the database applies them to every request, like an extra filter on every query. It's what makes it safe for a browser to talk to your database directly.

Is Supabase RLS enabled by default?

It depends on how the table was created. Supabase's dashboard Table Editor enables RLS on new tables. Tables created with SQL, a migration or another tool don't have it until you enable it, and that is how coding agents work with Supabase. Check every table instead of assuming.

What happens if I enable RLS with no policies?

Nothing can be read or changed through the API with your public key. Postgres applies a default-deny rule when RLS is on and no policy exists. Your app will show empty lists until you add policies. That's the safe state, so add policies instead of turning RLS back off.

Is the Supabase anon key safe to expose?

Yes, if RLS is enabled with correct policies on every table. Supabase says its publishable key (the newer name for the anon key) is "safe to expose with RLS enabled". Without RLS, anyone holding the key can read and write every row. The secret or service-role key is never safe to expose.

What is the difference between using and with check?

using decides which existing rows a policy applies to: the rows you can see, change or delete. with check decides what a new or changed row is allowed to look like. Insert policies use with check, select and delete use using, and update policies should have both.

Does the service role key bypass RLS?

Yes. The secret key, and the older service-role key, authorize requests through a role that bypasses row level security. Use it only in server code for administrative work. If it appears in browser code or a public variable, treat your database as open and replace the key.

How do I test Supabase RLS policies?

Start with two accounts in your own app: create data as one and try to reach it as the other, then signed out. In the SQL Editor you can also run a query as a specific signed-in user by setting the role and the user's id first. For apps with real users, write tests that run with supabase test db.

Does RLS make Supabase slow?

It can on large tables if policies aren't written carefully. Index the column each policy compares, wrap auth.uid() in a select, and name the role with to authenticated. In tests published in Supabase's knowledge base, on a 100,000-row table, adding an index took one query from 171 ms to under 0.1 in the same table.

Sources