Skip to content
Book a call

8 min readSecurity

Is your Lovable app secure? A Supabase RLS security audit checklist

The checks I run in a Supabase security audit of a Lovable or other AI-built app: row-level security, the service role key, storage, auth and payments.

Updated

A Lovable app is as secure as its Supabase setup. The front end is public by design: anyone can read the code their browser downloads, including your Supabase URL and anon key. What keeps your data safe is row-level security on every table, policies that check who is asking, and secrets that stay on the server. Below are the ten checks I run, in the order I run them.

Most apps I look at from Lovable, Bolt and v0 use Supabase for the database and sign-in. The AI writes the tables and the policies as you prompt, which works well until one policy is wider than it should be. The app still looks fine in the demo, so nothing tells you. The first person to notice is usually someone poking at the network tab.

Why the anon key isn't the problem

Supabase's anon key (called the publishable key in newer projects) is meant to be public. It tells Supabase which project a request is for, and the request then runs as the anon role, or as authenticated once someone signs in. Postgres row-level security (RLS) decides which rows each of those can read or change.

So the question is never "can people see my anon key?" They can. The question is "with that key, what can they do?" If a table in the public schema has RLS switched off, the answer can be: read and change every row, through the API Supabase builds for you.

The service role key (the secret key in newer projects) skips RLS completely. It must never be in front-end code, in a VITE_ variable or in a public repo. If it has been, rotate it today.

The checklist

  1. RLS is on for every tableIn the Supabase dashboard, a table without RLS is marked in the table editor. To see them all at once, run the query below in the SQL editor: every row should say true.
  2. No policy says yes to everyone by accidentA policy with using (true) lets anyone read that table. That is fine for public data like a product list, and a leak for anything personal. Read each policy and ask: who should see these rows?
  3. Policies check who is askingPrivate rows need a policy that compares the row's owner with the signed-in user, like (select auth.uid()) = user_id. Update policies need a with check too, or a user can move a row to someone else.
  4. Users can't make themselves adminIf a role or is_admin column sits on a table users can update, a user can change it. Keep roles in a table only the server can write, or limit which columns an update policy allows.
  5. The service role key only lives on the serverSearch your built JavaScript and your repo for it. My post on API keys in the front end shows how, in five minutes.
  6. Storage buckets aren't public by accidentFiles in a public bucket can be read by anyone with the link. Invoices, ID scans and private uploads belong in a private bucket, with policies on storage.objects like the ones on your tables.
  7. Edge Functions check who is callingSupabase checks the caller’s token by default, but functions deployed with --no-verify-jwt (common for webhooks) have to check everything themselves. Look for those first.
  8. Payments are confirmed on the serverAn order should become "paid" because Stripe told your server so in a signed webhook, never because the browser reached a success page. Check the webhook verifies its signature.
  9. Sign-in settings match the appIn Authentication settings, the redirect URLs should list only your own domains, and email confirmation should be on if your app trusts email addresses.
  10. Supabase's Security Advisor is cleanThe dashboard has a Security Advisor that flags common problems, including tables without RLS. Run it and read every warning; it takes two minutes.
select tablename, rowsecurity
from pg_tables
where schemaname = 'public'
order by rowsecurity, tablename;

A table of private rows, done properly, looks like this. Each user can read and change only their own profile:

alter table public.profiles enable row level security;

create policy "Users read their own profile"
on public.profiles for select
to authenticated
using ((select auth.uid()) = user_id);

create policy "Users update their own profile"
on public.profiles for update
to authenticated
using ((select auth.uid()) = user_id)
with check ((select auth.uid()) = user_id);

Common Supabase security mistakes in Lovable apps

  • A policy that allows everythingWhen a query fails with a permission error, the quickest way for an AI tool to make the error go away is a policy with using (true). The app works again, and the table is open to everyone.
  • Rules for reading, none for writingA select policy is checked, but insert, update and delete have no policy of their own, or one copied from somewhere wider.
  • The owner taken from the requestAn insert that trusts the user_id the browser sends lets anyone create rows as someone else. The with check should compare it with auth.uid().
  • Views that skip the rulesA Postgres view runs with the rights of whoever created it unless it is made with security_invoker = true, so it can show rows the table’s policies would hide. The Security Advisor flags these.
  • Database functions anyone can callA function marked security definer and exposed through the API runs with its owner’s rights. Check what each one can read and change, and who may call it.

An exposed service role key in a Next.js app

In Next.js apps the service role key leaks in two ways. Either it is in a variable named NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY, which the build copies into the browser code, or an admin client made with it sits in a file that a client component imports. Keep the admin client in its own file, mark that file server-only, and the build fails if it ever ends up in the browser:

// lib/supabase/admin.ts
import "server-only"; // the build fails if a client component imports this file
import { createClient } from "@supabase/supabase-js";

export const supabaseAdmin = createClient(
  process.env.NEXT_PUBLIC_SUPABASE_URL!,
  process.env.SUPABASE_SERVICE_ROLE_KEY!, // no NEXT_PUBLIC_ prefix, so it never reaches the browser
  { auth: { persistSession: false } },
);

If the key has been public, rotate it before anything else. Projects on the newer API keys can swap a secret key on its own; on the older JWT keys, rotating means a new JWT secret, which also signs every user out, so plan the moment.

Test it the way a stranger would

Reading policies is good. Trying them is better. Make two test accounts on your live app. Sign in as the first, open your browser's developer tools, and watch the Network tab while you use the app. Find a request to /rest/v1/, copy it, and change it to ask for the second account's rows, or remove the filter altogether.

Then try it with no account at all. The request below asks for every profile using only the public key, which is exactly what anyone on the internet can do:

curl 'https://YOUR-PROJECT.supabase.co/rest/v1/profiles?select=*' \
  -H "apikey: YOUR_ANON_KEY" \
  -H "Authorization: Bearer YOUR_ANON_KEY"

If that returns other people's rows, the policy is too wide. Only ever do this on your own app.

A production readiness checklist for Supabase

Security is most of it, but not all. Before launch I also check:

  • Backups match what you can afford to lose; point-in-time recovery if a day of data is too much.
  • Indexes on the columns your policies filter by, like user_id, so the rules don’t slow every query.
  • Connection pooling for serverless functions, so a busy hour doesn’t run out of connections.
  • Your own email provider for sign-in emails; the built-in one is limited and meant for testing.
  • A staging project with the same schema, and every database change kept as a migration file in git.

If you find a hole

  1. Switch on RLS and add the narrowest policy that keeps the app working. Test again with both accounts.
  2. Rotate any secret key that was exposed, in the project’s API settings, and update it wherever the server uses it.
  3. Look through Supabase's logs for reads you can't explain.
  4. If personal data may have been seen by someone who shouldn’t have it, get advice the same day. In the UK and EU, some breaches have to be reported within 72 hours.

None of these checks is hard, but each is easy to miss when the app already looks finished. If you’d like someone else to go through them, this is the core of my code audit, and you can see what the report looks like in this sample.

Questions people ask

Is Lovable secure?
Lovable is a tool; how secure your app is depends on the database rules and keys in your project. A Supabase app can be properly secure, but only if every table has row-level security with policies that match who should see what. Check it, don't assume it.
Is it safe that my Supabase anon key is visible in the browser?
Yes. It's designed to be public, as long as row-level security is on for every table and the policies are right. The key to protect is the service role (secret) key, which skips row-level security.
How do I check if RLS is enabled in Supabase?
The table editor marks tables without it, and the Security Advisor in the dashboard lists them. For the full picture, run select tablename, rowsecurity from pg_tables where schemaname = 'public' in the SQL editor.
Do automated security scans replace an audit?
They catch common problems fast, like a table without row-level security, so run them. What they can't judge is whether a policy matches your business, for example whether one team should see another team's invoices. That needs someone to read the rules against how the app is meant to work.
What does a Supabase security audit include?
Row-level security and policies on every table, read against who should see what and tested from outside the app; views and database functions; storage buckets; where every key lives; Edge Functions; sign-in settings; and payment webhooks. Mine also covers the rest of the app around it.
What should I do if my Supabase service role key was exposed?
Rotate it straight away in the project's API settings, update it wherever your server uses it, and look through the logs for reads and writes you can't explain. Then move every use of it to server-only code.

Reply within a day

Want more calls and bookings?

Tell me about your business on WhatsApp, or send a few lines. I reply within a day with honest next steps, even if I'm not the right fit.

Free 30-minute call · No commitment · Reply within a day

Pick a time on my Cal.com page. Calls are on Google Meet. Or email me.

  1. Step 1

    You message me on WhatsApp

    A few lines is enough.

  2. Step 2

    I reply within a day

    I ask questions or share a first view.

  3. Step 3

    A free 30-minute call

    Then a written quote.