// From Lovable, Bolt or Replit to production
How do you secure the Supabase database behind a Lovable app?
Enable row-level security (RLS) on every table in the public schema, write policies that compare (select auth.uid()) with the row owner for reads and writes, keep the secret key out of the browser, make private storage buckets private, and check who calls each edge function. Lovable's pre-publish scan flags missing RLS, but it cannot prove your policies are correct.
Want it done for you? Vibe-code to Production: from €1,500, fixed quote in 24h →

By Gabriel Cazaciuc, Founder & lead developer, Netcraft Digital
Last updated
Key facts
- RLS on, no policies
- No data reachable with the publishable key
- Source: Supabase docs, Nov 2026
- Secret / service_role key
- Bypasses RLS; backend only
- Source: Supabase docs, Nov 2026
- Legacy anon and service_role keys
- Being deprecated in early 2027
- Source: Supabase docs, Nov 2026
- Lovable security checks
- Do not block publishing by default and “can't guarantee that your app is secure”
- Source: Lovable docs, Nov 2026
- Security fixes with us
- From €1,500, 3–4 days, written report
- Source: Our fixed-price offer, Nov 2026
Why is a Lovable + Supabase app open by default?
Because the browser talks to the database directly. A Lovable app ships the Supabase URL and the publishable (or legacy anon) key in its JavaScript, and that key can query any table through Supabase's API. The only thing that limits what it returns is row-level security.
Lovable's built-in backend runs on Supabase, and Lovable's pre-publish checks flag tables without RLS. The problems that remain are subtler: a table added in a hurry, a policy loosened to make an error go away, a column the user can edit that decides what they are allowed to do.
How can I test my own app in five minutes?
Do what an attacker would do: take the key from your site and ask the API for a whole table, without logging in. Open your published app, find the Supabase URL and key in the browser's network tab, then run:
curl "https://YOUR-PROJECT.supabase.co/rest/v1/profiles?select=*" \
-H "apikey: YOUR_PUBLISHABLE_KEY"Repeat for every table. Any table that returns other people's rows is a leak. Then log in as one test user, copy the access token, add it as an Authorization: Bearer header, and check that you only get that user's rows.
What does a correct RLS policy look like?
One policy per action, each checking the owner, with a WITH CHECK on inserts and updates so users cannot write rows in someone else's name. Wrap auth.uid() in a select, as Supabase recommends, so it runs once per query instead of once per row.
alter table public.projects enable row level security;
create policy "read own projects" on public.projects
for select to authenticated
using ((select auth.uid()) = user_id);
create policy "create own projects" on public.projects
for insert to authenticated
with check ((select auth.uid()) = user_id);
create policy "update own projects" on public.projects
for update to authenticated
using ((select auth.uid()) = user_id)
with check ((select auth.uid()) = user_id);
create policy "delete own projects" on public.projects
for delete to authenticated
using ((select auth.uid()) = user_id);Which mistakes does the Lovable scan not catch?
The scan checks whether RLS is on and whether a rule lets everyone in. It does not know what your app is supposed to allow. These are the patterns we look for by hand:
| Pattern | Why it leaks | Fix |
|---|---|---|
| using (true) for the authenticated role | Every logged-in user reads every row; sign-up is free, so this is the same as public | Compare with the owner or an organization membership |
| Role or plan column on the profiles table, with an “update own profile” policy | Users set role = 'admin' or plan = 'pro' on their own row | Move role and plan to a table users cannot write, or limit updatable columns |
| Policies that read user_metadata | Users can change their own user_metadata | Use app_metadata or a table for authorization data |
| Views over protected tables | Views bypass RLS by default | Create them with security_invoker = true (Postgres 15+) |
| SECURITY DEFINER functions in the public schema | Callable through /rest/v1/rpc and they skip RLS | Move them to a private schema or check auth.uid() inside |
| Edge functions using the secret key | The secret key bypasses RLS, so the function must check the caller itself | Verify the user's token and ownership in the function |
| Public storage bucket for invoices, IDs or uploads | Anyone with the URL can download the file | Private bucket with storage policies and signed URLs |
The second row is easy to miss in apps with paid plans: the plan is stored on the user's own profile, and the profile policy lets the user update their row. With the browser console, they can upgrade themselves for free.
Which Supabase key goes where?
The publishable key goes in the browser; the secret key only on a server or in an edge function. If a secret key was ever committed to the repo or pasted into the frontend, rotate it.
| Key | Format | Where it belongs | Bypasses RLS |
|---|---|---|---|
| Publishable | sb_publishable_… | Browser, mobile app | No |
| Secret | sb_secret_… | Server, edge functions, jobs | Yes |
| anon (legacy) | Long-lived JWT | Browser (replace with publishable) | No |
| service_role (legacy) | Long-lived JWT | Server only (replace with secret) | Yes |
Supabase is deprecating the legacy anon and service_role keys in early 2027. Switching to the new keys is a good moment to search the codebase for any place the elevated key is used.
What is the full checklist before launch?
Lovable + Supabase security checklist
- RLS enabled on every table in the public schema (check More → Database → Manage → Policies in Lovable, or the Supabase dashboard)
- Every table has explicit select, insert, update and delete policies, or the action is intentionally denied
- Inserts and updates have WITH CHECK on the owner column
- No policy uses true for authenticated users on private data
- Role, plan, credits and payment status cannot be written by the user
- No authorization decisions read user_metadata
- Views use security_invoker = true or are not exposed
- No SECURITY DEFINER functions in exposed schemas without their own checks
- Secret key only in server code and edge function secrets; none in the repo
- Private buckets are private; files served with signed URLs
- Each edge function verifies the caller and what they are allowed to touch
- The curl test above returns nothing for anonymous users on private tables
Run the list again after every large prompt. An AI fix for an unrelated error can drop a policy or widen it, and nothing in the preview will look different. For the risks outside the database (exposed API keys, payments, AI cost abuse), see vibe coding security risks.
How do you do this without Supabase?
Our own products run on Next.js, Payload and Postgres without Supabase. The browser never talks to the database; every read and write goes through server code that checks the session first. That is the same rule RLS enforces, placed in a different layer. If your app is moving to your own hosting, either model works, as long as it is applied to every table.
Security is the first item on the production checklist for AI-built apps. If payments are next, read how to add Stripe to a Lovable app, or ask a Lovable developer to review the code.
