Guide
Supabase row level security for Lovable and Bolt apps
If your Lovable or Bolt app uses Supabase, row level security (RLS) is what stops one user from reading or changing another user's data. Tables without RLS in the public schema can usually be read and edited by anyone who has your project URL and public key, which ship inside your app. Open Advisors → Security Advisor in Supabase, look for “RLS Disabled in Public,” and turn RLS on with policies for every table it lists.
What row level security does
Supabase lets your app talk to the database directly from the browser. That is what makes AI app builders so fast, but it means the browser holds a key that can reach your tables. RLS adds rules inside the database, called policies, that decide which rows each request may read, add, change or delete.
Without RLS, every row in the table is fair game. With RLS and a good policy, a signed-in user only gets their own rows, no matter how the request is made.
Why vibe-coded apps often ship without it
Tables you create in Supabase's Table Editor get RLS turned on automatically. Tables created with SQL, which is how AI builders and database migrations usually create them, start with RLS off. The app still works perfectly in a demo, so nothing looks wrong until someone goes looking.
The tools are getting better at this. Lovable now runs a quick security scan when you publish that checks your database access rules. But a scan passing is not the same as your data being protected, so it is worth checking yourself.
How to check your app in 5 minutes
- Open the Security Advisor. In your Supabase project, go to Advisors → Security Advisor. Any table listed under “RLS Disabled in Public” is exposed. Supabase marks this as an error, the most serious level.
- Look at the Table Editor. Supabase shows a warning label on tables that have RLS turned off.
- Or run a quick query in the SQL Editor. Any table showing
falsehas RLS off:select tablename, rowsecurity from pg_tables where schemaname = 'public'; - Check which key your app uses. Your browser code should only contain the publishable key (
sb_publishable_…) or the older anon key. If you find a secret key (sb_secret_…) or the older service_role key anywhere in your frontend code, treat it as leaked: it has full access and ignores RLS entirely.
How to fix it
1. Turn on RLS for each exposed table:
alter table public.notes enable row level security;
Once RLS is on, the table returns nothing to your app until you add policies. That is the safe default, but it means you should do steps 1 and 2 together.
2. Add policies for what your app actually needs. For the most common case, a table where each row belongs to one user through a user_id column:
create policy "Users can read their own notes"
on public.notes for select to authenticated
using ((select auth.uid()) = user_id);
create policy "Users can add their own notes"
on public.notes for insert to authenticated
with check ((select auth.uid()) = user_id);
create policy "Users can update their own notes"
on public.notes for update to authenticated
using ((select auth.uid()) = user_id)
with check ((select auth.uid()) = user_id);
create policy "Users can delete their own notes"
on public.notes for delete to authenticated
using ((select auth.uid()) = user_id);
Replace notes and user_id with your table and column names. Tables shared within a team or organization need different policies, built around membership.
3. Test with two accounts. Sign in as user A and create some data. Sign in as user B and confirm you cannot see or change it. Then run the Security Advisor again.
4. If a secret or service_role key was in your frontend, create a new secret key in Settings → API Keys, move it to server-side code only, and delete the old one.
Mistakes that look secure but aren't
using (true)policies. RLS is technically on, but the policy lets everyone read everything. AI tools sometimes add these to make an error go away.- Missing
with checkon updates. Without it, a user may be able to reassign their row to someone else. - Policies based on user metadata. Users can often edit their own metadata, so never use it to decide who is an admin.
- Views. Views skip RLS by default because they are usually created by the database owner. On Postgres 15 and later, set
security_invokerso the view respects the caller's permissions:alter view public.my_view set (security_invoker = true); - Storage buckets. Files in public buckets are readable by anyone with the link. Keep private files in private buckets with their own policies.
- Turning RLS off “just to test.” It is easy to forget to turn it back on before launch.
Questions
Is the Supabase publishable (anon) key safe to put in my app?
Yes. The publishable key (and the older anon key) is designed to be public and ships in every Supabase browser app. It is only safe when row level security is turned on with sensible policies, because RLS is what limits what that key can do. The secret key (and the older service_role key) must never be in the browser.
Will turning on RLS break my app?
It can. Once RLS is on, the table returns no data to your app until you add policies, so pages may suddenly look empty. Enable RLS and add the policies your app needs in the same change, then test with two different user accounts before you publish.
Does Lovable turn on RLS for me?
Lovable runs a quick security scan when you publish that checks your database access rules, and its own docs say the scans do not replace a thorough security review. Check your tables yourself with the steps above rather than assuming they are protected.
Not sure your policies are right?
Have a senior engineer check your app
Security Advisor checks whether RLS is on, not whether your policies are correct. LaunchGrade reviews your actual database rules and code, explains what we find in plain English and can fix it.
Missing RLS is one of 27 items on our launch readiness checklist for vibe-coded apps.