Supabase RLS for AI-built apps: the 10-minute check

By Arif Khan, AIVolve LLC · Updated November 16, 2026

Short answer: Row Level Security (RLS) is what stops one user, or a stranger, from reading everyone else's data in your Supabase database. To check it in about 10 minutes: (1) find any table with RLS off, using the Security Advisor or one SQL query; (2) look for policies that allow everything, like using (true) for anon or authenticated; (3) run the two-account test, where user B tries to see user A's data; (4) make sure the secret (service_role) key is never in your app's browser code; and (5) check the AI-generated mistakes listed below. If all five pass, your basics are in good shape.

You don't need to write code: you'll click through a few screens and paste a couple of queries.

Why this matters for AI-built apps

Your app's public key (the publishable key, or the older anon key) sits in your app's code where anyone can find it, by design. It only reaches what RLS allows. So if a table has RLS off, or a policy that lets everyone in, anyone with that key can read it, and in many cases change or delete it.

AI tools usually set up RLS, but they make predictable mistakes. And Supabase notes that while tables created in its dashboard have RLS on by default, tables created in the SQL editor or "through another tool" need it turned on explicitly.

Where to look

Step 1 (2 min): Find tables with RLS off

Easiest way: open Security Advisor. The finding to worry about most is "Table publicly accessible" (rls_disabled_in_public). Supabase rates it ERROR and says anyone with your project URL "can read, edit, and delete all data in this table." Also look for "Sensitive data publicly accessible" (sensitive_columns_exposed) and "Security policy not enforced" (policy_exists_rls_disabled: a policy exists but RLS is off, so it does nothing).

Double-check with SQL (works in either SQL editor):

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

Any row with rls_on = false is a table to fix. To turn RLS on:

alter table public.your_table enable row level security;

With RLS on and no policies, the public key can't reach the table at all, so the app may stop showing that data until you add policies. That's safer than leaving it open. Or ask Lovable:

"List every table in the public schema and whether row level security is enabled. For any table with RLS off, enable it and add policies so each signed-in user can only select, insert, update and delete their own rows, using (select auth.uid()) = user_id. If a table is meant to be public, tell me why and give anon select only. Show me the SQL before applying it."

Step 2 (3 min): Spot policies that let everyone in

A policy works like a hidden filter on every query. The dangerous ones are always true. Run:

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

Read each row:

using (true) is fine only for data that's genuinely public, like published blog posts, and then only for select.

Step 3 (3 min): The two-account test

  1. Create two test accounts, A and B, using two different emails.
  2. Signed in as A, create something private: a note, an order, a profile detail. Copy the page's address if the item has its own URL.
  3. Open a private browser window and sign in as B.
  4. As B, look for A's item in lists and search, and paste A's item URL into the address bar.
  5. Open developer tools (right-click → Inspect → Network), refresh, and click the requests to /rest/v1/.... Check the responses for any of A's data, even if the page doesn't show it.
  6. Sign out and repeat step 4 as a visitor.

B should see nothing of A's, and the visitor nothing private. If B sees A's data, that table's select policy is wrong.

On your own Supabase project, you can also test as a specific user in the SQL editor. Find user B's ID under Authentication → Users, then run (the rollback undoes everything):

begin;
set local role authenticated;
set local request.jwt.claim.sub = 'USER-B-ID-HERE';
select * from public.your_table;
rollback;

You should only get user B's rows. A plain query in the SQL editor doesn't run as one of your app's users, so don't judge RLS from it.

Step 4 (1 min): Keys in the right place

Key Starts with Where it can go What it can do
Publishable (older name: anon) sb_publishable_ (older: a long eyJ... string) Your app, the browser, mobile apps Only what grants and RLS allow. It acts as anon for visitors and as authenticated once a user signs in.
Secret (older name: service_role) sb_secret_ (older: a long eyJ... string) Only server code, like Edge Functions Everything. It bypasses RLS.

Supabase's rule is blunt: never put a secret key in a browser, a shipped app or source control. Ask your AI tool:

"Search the whole frontend for service_role, sb_secret_, SUPABASE_SERVICE_ROLE_KEY and SUPABASE_SECRET_KEY. Tell me every file where a secret or service role key could reach the browser, and move any such use into an Edge Function."

If a secret key ever reached the browser or your repository, create a new one in Settings → API Keys and retire the old one, following Supabase's steps. Supabase also plans to deprecate the legacy anon and service_role keys by the end of 2026. (On Lovable Cloud, service role keys aren't accessible to you, so this mostly applies to your own Supabase project.)

Step 5 (1 min): The AI-generated mistakes we look for

  1. A policy only for reading. The AI added a select policy and nothing else, so saves fail (Supabase returns 42501 when RLS blocks an insert or update). The tempting "fix" is a for all ... using (true) policy that opens everything. Give each action its own policy. Supabase also notes updates need a matching select policy.
  2. Trusting the user ID the app sends. If the app sends user_id in the request and the policy doesn't check it, anyone can create rows "as" someone else. Insert and update policies need with check ( (select auth.uid()) = user_id ). The same goes for Edge Functions using the secret key: RLS doesn't apply there, so the function has to check who the user is itself.
  3. Views that skip RLS. A database view normally runs with its creator's rights and ignores the policies on the tables underneath. Security Advisor flags it as "View bypasses row-level security" (security_definer_view). On Postgres 15 and later, the fix is alter view public.your_view set (security_invoker = true);.
  4. Roles stored in user metadata. A policy that checks user_metadata (for example role = 'admin') can be beaten, because signed-in users can edit their own user metadata. Security Advisor flags policies that reference it. Store roles in a table or in app_metadata instead. How to lock roles, pro flags and plan fields.
  5. RLS on, no policies. The table is safe but nothing loads. Security Advisor lists it as "No access rules defined." Add the policies the app needs instead of turning RLS off.

A prompt to check all five at once:

"Audit my Supabase RLS. For every table in public: confirm RLS is enabled; list its policies per action (select, insert, update, delete) and their roles; flag any using (true) or with check (true) on non-public data, any policy without a to role, and any for all policy; confirm insert and update policies use with check ((select auth.uid()) = user_id); list every view and whether it has security_invoker = true; flag any policy that reads user_metadata; and list Edge Functions that use the service role key without checking the user. Report findings in plain English before changing anything."

A note on the October 30, 2026 change

From October 30, 2026, Supabase stops automatically granting access to new tables in public on existing projects. A new table then fails with "permission denied for table" until it gets a GRANT. The right fix is grants plus RLS plus policies together, never a blanket grant to anon. See Supabase "permission denied for table" after Oct 30.

How to confirm it's fixed

  1. Security Advisor shows no ERROR-level findings about RLS, exposed tables or views, and you've read every WARN.
  2. The Step 1 query shows rls_on = true for every table.
  3. The Step 2 query shows no true conditions on private data.
  4. The two-account test passes, including as a signed-out visitor.
  5. The key search finds no secret or service role key in frontend code.
  6. Repeat after every big database change your AI tool makes.

FAQ

What is Row Level Security in Supabase?+

RLS is a Postgres feature that adds a rule to every query on a table, deciding which rows each user can read or change. In Supabase, it's what stops someone with your app's public key from reading other users' data.

Is it safe that my Supabase publishable or anon key is visible in my app?+

Yes, as long as RLS is on and your policies are correct. Supabase designed that key to be public. It can only reach what your grants and RLS policies allow, which is why RLS matters so much.

How do I find tables with RLS turned off?+

Open Security Advisor in the Supabase dashboard and look for "Table publicly accessible," or run a query on pg_tables where rowsecurity is false. On Lovable Cloud, use the SQL editor under More → Database → Manage.

Is using (true) in a policy always wrong?+

No, but it means every user the policy covers can do that action on every row. It's fine for a select policy on data that's meant to be public, like published posts. It's wrong on private data such as profiles, orders or messages.

Can I use the service_role key in my frontend if I hide it?+

No. There's no safe way to hide a key in browser code. The service_role or secret key bypasses RLS completely, so it belongs only in server code such as Edge Functions.

Not sure what you found?

If the checks turned up something you don't know how to fix, or you'd like a second pair of eyes, our free App X-ray takes about 2 minutes and needs no code or passwords: you paste a prompt into Lovable, send us the report, and get a plain-English verdict on what works, what only looks done and your biggest risk. An AIVolve developer reviews every X-ray within 1 business day. Get a free X-ray →

Related: Supabase anon key vs service_role key · Supabase "permission denied for table" after Oct 30 · Lovable + Supabase login loop: the real fix · Stripe works in test mode but not live · Security audit prompts for AI-built apps · Supabase view bypasses RLS · Supabase columns users should never edit · Supabase "Database error deleting user" · Alert: customer data readable without a login in Lovable apps · All security alerts

Written by Arif Khan, AIVolve LLC. VibeCoderSOS isn't affiliated with Lovable or Supabase. Settings names, advisor checks and SQL were checked against Supabase's, Lovable's and PostgreSQL's documentation on October 22, 2026, and may change.

Need help?

Start with a free X-ray: 2 minutes, no code or passwords. You'll get a plain-English verdict on what works, what only looks done, and your biggest risk.

Get a free X-ray →