7 Row Level Security checks before shipping your Lovable/Supabase app

By Luca Gennaro · 16 November 2026

If you built your app with Lovable, Bolt, v0 or Cursor on Supabase, your browser talks to the database directly. The only thing standing between one customer and another customer’s data is a set of database rules called Row Level Security (RLS).

When those rules are missing or too loose, nothing looks broken: every screen works, every test you click through passes. The problem only shows when someone signs in and asks the database for rows that are not theirs. Here are seven checks I run before an app like this goes live. The SQL is minimal and invented for this page; adapt the table names to yours.

1. RLS is on for every table

Supabase exposes the tables in the public schema through its API. A table without RLS can usually be read and changed by anyone who has your public (anon) key, and that key ships inside your frontend. This query lists the tables that still have RLS switched off:

select c.relname as table_name
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public'
  and c.relkind in ('r', 'p')
  and not c.relrowsecurity;

The list should be empty. Switching RLS on with no policies blocks everything, which is safe; then you add back only what each user needs:

alter table public.invoices enable row level security;

2. No policy says “anyone”

AI tools often fix a “permission denied” error with the widest rule that makes it go away:

create policy "read invoices" on public.invoices
for select to authenticated
using (true);

That means every signed-in user can read every invoice, from every company. Search your migrations for using (true), with check (true) and policies that only check auth.uid() is not null. On shared tables, scope each rule to the user’s own company:

create policy "members read their invoices" on public.invoices
for select to authenticated
using (
  org_id in (
    select org_id from public.memberships
    where user_id = auth.uid()
  )
);

Do the same for insert, update and delete, and make sure the with check part stops a user from writing a row into someone else’s company.

3. Roles are enforced in the database, not in the UI

Hiding the “Delete” button from non-admins is good design, but it is not security: anyone can call the API without your interface. Every role rule has to exist in a policy too. A common gap is a profile table that stores the role next to the name:

create policy "users update own profile" on public.profiles
for update to authenticated
using (id = auth.uid());

This lets a user change their own role column to admin. Limit which columns users can write, or keep roles in a table only admins can change:

revoke update on public.profiles from authenticated;
grant update (full_name, avatar_url) on public.profiles to authenticated;

4. Views and grants don’t go around RLS

A view runs with the rights of its owner, usually the same role that owns your tables, and that role is not limited by their RLS. A handy “summary” view over a protected table can quietly show every row to everyone. On PostgreSQL 15 and later, create views so that they respect the caller’s rules:

create view public.invoice_totals
with (security_invoker = true) as
select org_id, sum(amount) as total
from public.invoices
group by org_id;

Also check the grants. Since Supabase’s 2026 change, new tables in public are no longer exposed to the API until you grant access yourself. But tables created before the change keep their old grants, which usually include the anon role, and RLS is then the only barrier. Don’t fix a “permission denied” error with grant all either. For tables only signed-in users should touch, keep anon out as a second line of defence:

revoke all on public.invoices from anon;

5. SECURITY DEFINER functions are locked down

A function marked security definer runs with its owner’s rights and skips RLS. If it sits in the public schema, anyone can usually call it through the API with any argument they like. Before keeping one, ask whether it needs to be a definer function at all; if it does, it should check who is calling, set an empty search_path, and be callable only by the roles that need it:

create or replace function public.org_invoice_count(p_org_id uuid)
returns bigint
language sql
security definer
set search_path = ''
as $$
  select count(*) from public.invoices i
  where i.org_id = p_org_id
    and exists (
      select 1 from public.memberships m
      where m.org_id = p_org_id and m.user_id = auth.uid()
    );
$$;

revoke execute on function public.org_invoice_count(uuid) from public, anon;
grant execute on function public.org_invoice_count(uuid) to authenticated;

Never trust a parameter like p_user_id to say who the caller is: use auth.uid() inside the function.

6. Storage buckets are private and scoped

Files in a public bucket can be downloaded by anyone who has, or guesses, the link, whatever your policies say. Contracts, invoices and ID documents belong in a private bucket, with policies on storage.objects that tie each file to its owner, for example through the first folder in its path:

create policy "members read their org files" on storage.objects
for select to authenticated
using (
  bucket_id = 'documents'
  and (storage.foldername(name))[1] in (
    select org_id::text from public.memberships
    where user_id = auth.uid()
  )
);

Add a matching insert policy, and set a file size limit and the allowed file types on the bucket, so uploads can’t land in someone else’s folder or be anything you did not expect.

7. Only the public key is in the browser

The anon (publishable) key is meant to be public; RLS is what protects you. The service role (secret) key is different: it skips every rule. It must never appear in frontend code, in a VITE_ or NEXT_PUBLIC_ variable, or in your repository history. The same goes for other paid API keys, such as an AI provider’s. Search your code and your built files for them; if one was ever exposed, rotate it, then move the call into a server or edge function.

Test it as a user, not only by reading

Reading policies finds a lot, but the real proof is a test. Run the app locally with the Supabase CLI and your migrations, create two test users in two different companies, sign in as the first one with the anon key and try to read, change and delete the second one’s rows, call every function and download every file. Do this only on your own app, on a local copy, never on someone else’s system. Keep these tests: rerun them after every change the AI makes to your schema.

Want a second pair of eyes?

I do this as a fixed-price security review: a written report for founders first, developers second, starting at $150, and tested fixes if you want them. I work on a local copy built from your code and migrations, with your written permission, and never touch real user data. Everything happens by email, no calls. I am not a certified penetration tester: it is careful, reproducible work, with tests you can rerun yourself. You can read a full review of a demo app in public, check the FAQ, or write to me.