Guides / Supabase
Supabase Row Level Security - checklist for AI-built apps
If your app talks to Supabase from the browser, Row Level Security is the only thing protecting your data. A practical RLS checklist with the SQL to fix common gaps.
Apps built with Lovable, Bolt, v0 and similar tools often query Supabase straight from the browser using the public anon (or publishable) key. That key is meant to be public: anyone can find it in your page code. So the only thing standing between a visitor and your data is Row Level Security (RLS).
This checklist covers the gaps we see most in AI-built apps.
1. RLS is enabled on every table
When RLS is off, the public key can read and write the whole table. Turn it on for every table in the public schema:
alter table public.profiles enable row level security;
alter table public.orders enable row level security;
Once RLS is on and there are no policies, nobody can access the table through the API. That's safe; you then add policies for what should be allowed.
2. Each table has policies for what it needs
Write one policy per operation. A common pattern: each user can only see and change their own rows.
create policy "Users read own orders"
on public.orders for select
using (auth.uid() = user_id);
create policy "Users create own orders"
on public.orders for insert
with check (auth.uid() = user_id);
Watch for policies that look fine but aren't:
using (true)makes the table readable by everyone, including visitors who aren't logged in.using (auth.role() = 'authenticated')lets any logged-in user read every row, not just their own.
3. Public tables are public on purpose
Some tables really are public (blog posts, product catalogue). That's fine, but check they hold nothing private: no emails, no internal notes, no draft prices.
4. The service_role key never reaches the browser
The service_role key (and the newer sb_secret_ keys) bypass RLS completely. If an AI tool used one in frontend code to make a "permission denied" error go away, your policies don't matter any more.
- Search your frontend for
service_roleandsb_secret_. - If it was ever shipped, rotate it in Project Settings > API.
- Use it only in server code or Edge Functions.
5. Views and functions don't bypass RLS
By default, views run with the permissions of the user who created them, which can skip RLS. In recent Postgres versions you can make a view respect the caller's permissions:
alter view public.order_summary set (security_invoker = true);
Functions marked security definer also run with elevated rights. Make sure they check auth.uid() themselves.
6. Storage buckets have policies too
Files in Supabase Storage are protected by policies on storage.objects. Private files (invoices, IDs, uploads) belong in a private bucket with policies limiting access to the owner.
7. Test it as a stranger
The real test is to try reading your data without logging in, using only the public key from your site. If a table returns rows it shouldn't, fix the policy.
Quick checklist
- RLS enabled on every table in
public - No
using (true)on tables with private data - Policies scope rows to
auth.uid() - No service_role /
sb_secret_key in frontend code - Views use
security_invoker, andsecurity definerfunctions check the caller - Private buckets for private files
- Tested as a logged-out visitor
Check your site in one minute
Scanora runs these checks for you: leaked keys, open files, headers, SSL, speed and AI-search readiness. Free, no signup.