Supabase database

Due diligence on a Lovable app: check the database before you buy, invest or take it over

If you are buying a Lovable-built app, investing in the company behind one, or an agency taking over a client’s app, the question that matters most is whether its Supabase database lets strangers read customer data. You can answer it in under an hour without changing anything: one read-only SQL query lists every table, policy, view, function and storage bucket that a logged-out visitor or any signed-in user can get past. We seeded a database with the seven patterns we see most often in AI-built apps and ran the query on Postgres 17 and 18 on 1 December 2026. It flagged all of them, missed none, and flagged nothing on the properly locked table. Each flag was then confirmed by reading the data as a visitor.

TL;DR

  • About a quarter to a third of public Lovable apps with Supabase send records to visitors who aren’t logged in (our study and Handelsblatt’s, Nov 2026). Assume the app in front of you might be one until a check says otherwise.
  • Ask the seller to run the audit query below in their Supabase SQL editor while you watch, and to paste the output into the data room. It only reads the database’s own settings; it never reads customer rows.
  • Critical lines (RLS off, a read policy that says true) mean customer data is readable today. In our lab a logged-out visitor read every profile and every order.
  • In our lab, every flag was fixed by one migration of ten statements, and the query then returned no rows. Fixing this is usually small. Not knowing about it is what costs you.
  • Also check: keys in the git history, whether the live database matches the migrations in the repo, and who owns the Supabase organisation, the repo and the domain.

Who this is for

Three kinds of people ask us this question. Investors and acquirers, who are about to pay for a company whose product was built in Lovable (or Bolt, Cursor or Claude Code) on Supabase and want to know what they are inheriting. Agencies and freelancers, who are about to take over an app a founder built themselves and don’t want to own a leak they didn’t cause. And founders getting ready for a raise or a sale, who would rather find this themselves than have a buyer find it.

This guide covers the database, because that is where AI-built apps leak most often and where a leak exposes the most people at once. It is not a full security review or legal advice. The query and results come from our own lab run on 1 December 2026, using a test database with fake users, set up with Supabase’s roles. They show the pattern, not any particular app.

What to ask the seller for

  • A 30-minute screen share with the Supabase SQL editor open, or read access to the project if their plan allows it. You don’t need their passwords or their service key, and you shouldn’t accept them.
  • Read access to the GitHub repo, including the supabase/migrations folder that Lovable writes database changes into.
  • The live site’s URL and two test accounts, so you can repeat the two-account test from step 3 yourself.
  • A list of what personal data the app stores: emails, phone numbers, addresses, payments, health or children’s data. That list decides how bad each finding is.

Step 1: run the read-only audit query

The seller pastes this into the SQL editor and runs it. It only uses SELECT on the database’s own settings (the system catalog). It doesn’t read a single customer row and changes nothing. An empty result means none of these patterns were found.

patchlabs-due-diligence.sql (read-only)
-- PatchLabs due-diligence audit for a Supabase (Lovable) database. Read-only: SELECTs on the catalog, changes nothing.
-- Each row is one thing to ask the seller about. Empty result = none of these patterns found.
with
anon_tables as (
  select c.oid, n.nspname, c.relname, c.relrowsecurity, c.relkind
  from pg_class c join pg_namespace n on n.oid = c.relnamespace
  where n.nspname = 'public' and c.relkind in ('r','p','v','m')
    and has_table_privilege('anon', c.oid, 'select')
)
select 'critical' as severity, 'RLS off, readable by anyone with the public key' as issue, nspname||'.'||relname as object
  from anon_tables where relkind in ('r','p') and not relrowsecurity
union all
select case when p.polcmd in ('r','*') then 'critical' else 'high' end,
       'Policy that is always true for '||coalesce(nullif(array_to_string(array(select rolname from pg_roles where oid = any(p.polroles)),','),''),'everyone')
         ||' ('||case p.polcmd when 'r' then 'read' when 'a' then 'insert' when 'w' then 'update' when 'd' then 'delete' else 'all' end||')',
       n.nspname||'.'||c.relname||' : '||p.polname
  from pg_policy p join pg_class c on c.oid = p.polrelid join pg_namespace n on n.oid = c.relnamespace
  where n.nspname in ('public','storage')
    and (pg_get_expr(p.polqual, p.polrelid) = 'true' or pg_get_expr(p.polwithcheck, p.polrelid) = 'true')
    and (p.polroles = '{0}' or p.polroles && array(select oid from pg_roles where rolname in ('anon','authenticated','public')))
union all
select 'high', 'Policy trusts user_metadata (users can edit it themselves)', n.nspname||'.'||c.relname||' : '||p.polname
  from pg_policy p join pg_class c on c.oid = p.polrelid join pg_namespace n on n.oid = c.relnamespace
  where coalesce(pg_get_expr(p.polqual, p.polrelid),'')||coalesce(pg_get_expr(p.polwithcheck, p.polrelid),'') ~* 'user_metadata'
union all
select 'high', 'View runs with its owner''s rights (no security_invoker), readable by anon', nspname||'.'||relname
  from anon_tables a where relkind in ('v','m')
    and not coalesce((select bool_or(o = 'security_invoker=true' or o = 'security_invoker=on') from pg_class c, unnest(c.reloptions) o where c.oid = a.oid), false)
union all
select 'high', 'SECURITY DEFINER function anyone can call through the API', n.nspname||'.'||p.proname||'('||pg_get_function_identity_arguments(p.oid)||')'
  from pg_proc p join pg_namespace n on n.oid = p.pronamespace
  where n.nspname = 'public' and p.prosecdef and p.prorettype <> 'trigger'::regtype
    and has_function_privilege('anon', p.oid, 'execute')
union all
select 'medium', 'SECURITY DEFINER function without a pinned search_path', n.nspname||'.'||p.proname
  from pg_proc p join pg_namespace n on n.oid = p.pronamespace
  where n.nspname = 'public' and p.prosecdef
    and not coalesce(array_to_string(p.proconfig, ',') ~ 'search_path=', false)
union all
select 'medium', 'Public storage bucket (anyone with a file URL can download)', 'storage.buckets : '||id
  from storage.buckets where public
order by 1, 2, 3;

This is what it printed on our seeded database, which had the seven patterns AI builders most often leave behind, plus one table locked down properly:

lab output, Postgres 17.11 and 18.6, 1 Dec 2026
critical | Policy that is always true for everyone (read) | public.orders : Enable read access for all users
critical | RLS off, readable by anyone with the public key | public.profiles
high     | Policy trusts user_metadata (users can edit it themselves) | public.projects : admins see all
high     | SECURITY DEFINER function anyone can call through the API | public.get_user_email(uid uuid)
high     | View runs with its owner's rights (no security_invoker), readable by anon | public.payment_summary
medium   | Public storage bucket (anyone with a file URL can download) | storage.buckets : avatars
medium   | Public storage bucket (anyone with a file URL can download) | storage.buckets : invoices
medium   | SECURITY DEFINER function without a pinned search_path | public.get_user_email

The properly locked table, notes (RLS on, owner-only policy), didn’t appear. Postgres 17 and 18 gave the same output.

Step 2: read the result

LineWhat it meansFor the deal
critical RLS off, readable by anyoneAnyone with the public key, which ships in the app’s web pages, can read the whole table. PL-008.Ask to fix before closing if the table holds personal data, and ask whether it has ever been open in production (it usually has). This may be a reportable breach.
critical Always-true read policyRLS is on, but a policy such as Supabase’s own template “Enable read access for all users” lets everyone read every row. PL-005.Same as above. Often added by an AI builder to make an error go away.
high Always-true insert, update or deleteAnyone can write, change or delete rows. PL-005.Fix before closing. Ask how they would know if data had been changed.
high Policy trusts user_metadataUsers can edit their own user_metadata, so a rule like “role = admin” in it lets anyone make themselves an admin. Why.Fix before closing. Check every admin feature, not just this table.
high View without security_invokerThe view reads its tables with its creator’s rights, so it skips their RLS. Views guide.Fix before closing if the view shows personal or payment data.
high SECURITY DEFINER function anyone can callCallable with rpc() by a logged-out visitor, and runs with full rights. PL-006.Read the function. If it returns user data or takes a user id as a parameter, treat it as critical.
medium No pinned search_pathA hardening gap in owner-rights functions. Supabase’s own Security Advisor flags it too.Fix list, not a blocker.
medium Public storage bucketAnyone with a file’s URL can download it, with no login. Fine for logos; not fine for invoices, IDs or medical files. Storage guide.Ask what is in each public bucket. A public invoices or documents bucket is critical.

The query is a first pass. It doesn’t catch policies that are wrong but not literally true, for example one that checks the wrong column, or a filter the app adds in the browser instead of the database. That is what step 3 and a lab check are for.

Step 3: prove each flag with a logged-out read

A flag in the catalog is a strong signal, not proof. Proof is reading the data as a stranger. In our lab, with the seller’s public key and no login:

lab output, 1 Dec 2026
as a logged-out visitor:
  profiles rows read: 2          (RLS off)
  orders rows read: 2            (using (true))
  payment_summary rows read: 1   (view without security_invoker)
  get_user_email(bob): bob@example.com
  notes rows read: 0             (locked properly, not flagged)
as a signed-in stranger who set user_metadata.role = admin on their own account:
  projects rows read: 1          (another user's private project)

Repeat this on the live app only with the seller’s written permission, using the two test accounts you asked for: sign in as account A, create something private, sign in as account B and try to read it. The two-account test walks through it in the browser. Don’t test against real customers’ data.

Step 4: the repo, the keys and the drift

  • Keys in the git history. Search the whole history, not just the current files, for service_role, sk_live_, SUPABASE_SERVICE_ROLE_KEY and AI provider keys. A secret that was ever committed to a public repo must be treated as leaked and rotated. Our key rotation guide has the commands. The service key in browser code is critical: it skips every RLS rule.
  • Does the live database match the repo? AI builders and people fixing things in the dashboard change the live database directly, so supabase/migrations can describe a database that no longer exists. Run the audit query on the live project (step 1) and run the free RLS check on the repo. If they disagree, the repo isn’t the source of truth, and the next migration someone runs could undo a fix.
  • Server code. List the Edge Functions and check that each one verifies the caller before using the service key. Edge Functions guide.

The open-source patchlabs-cli runs the repo side of this on your machine, so a private repo never has to leave the data room: uvx --from git+https://github.com/manra399/patchlabs-cli patchlabs scan .

Step 5: who owns what

A clean database is no use if you can’t take control of it. Before closing, write down who holds each of these and how it moves to you:

  • The Supabase organisation that owns the project. Supabase can transfer a project between organisations; check its billing plan and who else is a member.
  • The Lovable workspace or other builder account the app is edited from, and whether the builder still has access to the Supabase project or GitHub repo after the handover.
  • The GitHub repo, the domain and DNS, the email sender (custom SMTP), and the Stripe account and its webhooks.
  • Every API key in the app’s secrets. Plan to rotate all of them on the day you take over.

What fixing it costs

In our lab, all eight flags were cleared by one migration of ten statements. After it the query returned no rows, and a logged-out visitor read 0 profiles, 0 orders and 0 payment rows:

supabase/migrations/…_due_diligence_fixes.sql (lab example)
alter table public.profiles enable row level security;
create policy "own profile" on public.profiles
  for select to authenticated using (id = (select auth.uid()));
drop policy "Enable read access for all users" on public.orders;
create policy "own orders" on public.orders
  for select to authenticated using (user_id = (select auth.uid()));
drop policy "admins see all" on public.projects;
create policy "admins see all" on public.projects
  for select to authenticated using ((auth.jwt()->'app_metadata'->>'role') = 'admin');
alter view public.payment_summary set (security_invoker = true);
revoke execute on function public.get_user_email(uuid) from public, anon, authenticated;
alter function public.get_user_email(uuid) set search_path = '';
update storage.buckets set public = false;
lab output after the fix, 1 Dec 2026
audit query: (no rows)
anon reads after fix: profiles=0 orders=0 payment_summary=0

The lab made both buckets private. A bucket of logos or avatars can stay public on purpose; it will keep showing as a medium line, which is fine once you know what is in it.

In a real app, each owner-only policy has to match how the app actually reads that table, and every screen needs testing as its owner afterwards. That is where most of the time goes. The database work is rarely the expensive part. What costs money is a leak found after closing, when the users affected and the notification duties are yours.

Sources

The checks behind this guide, each with example code, a self-check and the fix.

Free check

Check your app for this, free.

Paste your public repo. PatchLabs rebuilds your database from its migrations, tests it as a visitor, a stranger and the owner, reads the code for keys and risky patterns, and hands you the fix.

First app free, fixes includedNever touches your database

Written by Manraj Singh Dhillon. Last checked 1 Dec 2026. Code samples are synthetic and run against your own project; nothing here names a real app. Spotted a mistake? Tell us.