Supabase row level security (RLS) is a set of rules inside your database that decides which rows each user can read, add, change or delete. Apps built with Lovable, Bolt and similar tools often talk to Supabase straight from the browser, so these rules are what keep one customer out of another customer's records. When they are missing or wrong, the public key in your app can reach data it should never see.
What is row level security, in plain words?
Think of each policy as a filter the database adds to every request. A policy on an invoices table might say that a signed-in user can see only the rows where the owner column matches their user ID. Supabase describes RLS as authorization rules that run inside the database, and its row level security guide tells you to enable it on every table in an exposed schema.
A few terms help:
- Policy. A rule for one table that says which rows a role can select, insert, update or delete.
- anon and authenticated. The two roles most requests use. A request from someone who is not signed in runs as anon, and a signed-in user runs as authenticated.
- auth.uid(). A function that returns the ID of the user making the request, or null when no one is signed in.
- using and with check. The using part decides which existing rows a user can see or change. The with check part decides what a new or changed row may look like, which stops a user from handing a row to someone else.
In Postgres, a new table has RLS turned off until someone turns it on. Once it is on and no policies exist, Supabase says no data is reachable through the API with the publishable key. That is a safe starting point. You then open access one role and one operation at a time.
The anon key and the service role key
Supabase gives every project two kinds of keys, and they are not interchangeable. Here is how Supabase's API keys documentation describes them.
| Key | Where it belongs | What limits it |
|---|---|---|
| Publishable key (starts with sb_publishable_; the legacy version is the anon key) | Web pages and mobile or desktop apps | Your RLS policies, and nothing else |
| Secret key (starts with sb_secret_; the legacy version is the service_role key) | Servers, Edge Functions and other backend code | Nothing, because it bypasses every RLS policy |
Supabase says never to put a secret key in a browser, a shipped app or source control. It now rejects secret keys sent from browsers, but it warns that an attacker can still use a leaked key from other tools, so that block does not replace rotation. Supabase also says it is deprecating the legacy anon and service_role keys by the end of 2026, so check which keys your app still uses. For how keys leak and what to do when one does, see Secrets in the Browser.
Why do AI-built apps get RLS wrong?
The AI builds what it is asked for, and the rule about who sees what often goes unsaid. The app works when its builder tries it. The gap shows only when a different user signs in, or when nobody signs in at all. Public cases show the same pattern again and again:
- CVE-2025-48757, scored 9.3 out of 10, describes insufficient row level security in apps generated by Lovable through April 15, 2025, which let unauthenticated attackers read or write database tables, according to the CVE record in the National Vulnerability Database. Lovable disputes it on the ground that each customer is responsible for protecting its own app's data.
- Matt Palmer, who reported it, found 170 of the 1,645 Lovable projects he analyzed affected. He was clear that the exposed public key was not the flaw, since Supabase's anon key is designed to be public, and that the missing rules were, as he explains in his statement on CVE-2025-48757.
- In February 2026, Wiz found that Moltbook, whose founder said he did not write a single line of its code, exposed 1.5 million API tokens and 35,000 email addresses through a Supabase key in client-side code with no RLS behind it, per Wiz's write-up on Moltbook.
- A researcher reported that an exam and grading app showcased on Lovable exposed 18,697 user records because it had no row level security or role-based access, and its login check worked backwards, according to The Register. Lovable said the project included code it did not generate and a database it did not host.
- A November 2026 crawl of 159,041 Lovable projects found 24,664 sites showing Supabase records without any login. The researchers stress that this is not a breach rate and that the sample is not representative, as Techzine reported.
How to write policies that hold
- Map who should reach each table. For every table, write down who may see each row: only its owner, members of the same organization, admins, or the public.
- Turn on RLS everywhere it is exposed. Include tables you think the app no longer uses.
- Write one policy per role and operation. Cover select, insert, update and delete separately. Supabase notes that an update needs a matching select policy to work as expected.
- Avoid policies that allow every row. A rule of using (true) can be right for a public price list. It is wrong for invoices, messages or anything personal.
- Add with check to inserts and updates. Without it, a user can create a row in someone else's name or move their own row to another account.
- Keep roles and paid status out of reach. Supabase warns that raw_user_meta_data can be changed by the signed-in user and is not a good place for authorization data. Its column level security page recommends RLS policies together with a dedicated table for user roles.
- Watch views and functions. Supabase says views bypass RLS by default because they are usually created by the postgres user. In Postgres 15 and later, setting security_invoker = true makes a view obey the policies on its tables. A security definer function runs with its creator's rights and can skip RLS too.
- Filter by organization in multi-tenant apps. If your customers are companies with many users, each policy should check the organization as well as the user.
Two performance habits from Supabase's guide also help. Write (select auth.uid()) instead of auth.uid() inside policies, and add an index on every column your policies filter on.
How do you test RLS policies?
Test from the inside and from the outside. Supabase's own guide says that until your test suite passes, you do not know whether your policies do what you intended. It shows pgTAP tests, run with the supabase test db command, that check allowed and denied reads and writes for both signed-out and signed-in users. It also warns that a test of an allowed write can succeed even when the write matched zero rows, so confirm the row actually changed.
Then test the way an attacker would, through the same API your app uses:
- Create two test accounts and give each a few fake records with names you will recognize.
- Sign in as the first account and request the second account's rows by ID.
- Try to insert or update a row with the second account's user ID in it.
- Send the same requests while signed out.
- For multi-tenant apps, repeat the test across two organizations.
Every one of those requests should fail or come back empty. Use synthetic data only, never real customer records. The full method, including exports, file links and admin routes, is in The Two-Account Test.
What Supabase's security advisors catch, and the caveat
Supabase's advisors flag common problems, including RLS disabled on a public table, a policy that exists while RLS is off, overly permissive policies, an exposed auth.users table, exposed sensitive columns and security definer views. Run them before every launch and after every big change.
Read the results with care. Supabase itself says some findings may be intentional, and that you should check them against your intended schema and access model before you change anything. A permissive read policy is correct for a public catalog and a serious flaw on patient notes. The advisor tells you where to look, and deciding who should see what is still your call. Builder scans have the same limit, since they can confirm a policy exists without knowing your business rules, as we cover in the pre-launch security checklist.
Your next step
Start with the free 2-minute self-check, which asks whether you have tested access with two separate accounts. If your answer is no or not sure, that is the place to begin.
In a Compliance Readiness Review, we read your policies against who should see what, run a two-account access test with fake records, and tie each finding to the SOC 2, HIPAA or PCI DSS requirement it affects, with a ranked plan for the fixes.