Cenk Kurtoğlu©26

Supabase security · 9 minute read

The Supabase security checklist for Lovable, Bolt, v0 and Cursor apps

An AI app builder will connect Supabase, create tables, generate policies and ship a working login in one session. What it will not do is sit down with your access model and decide who is allowed to read which row. That part is still yours — and the gap between “it works” and “it is closed” is measurable with read-only SQL.

This checklist is the order I use. Every step is a catalog read or a grep; none of them writes, deletes, or needs service_role. Run them against a scratch project first if you are nervous — the queries themselves are safe.

1. Accept that the anon key is public — then check what it opens

The key in your NEXT_PUBLIC_ / VITE_ env is supposed to ship to the browser. The security boundary is not the key; it is what that key is allowed to touch. Probe it: fetch a table you believe is private with only the anon key and see whether rows come back. A populated response is the finding, not the key itself.

2. RLS must be on for every table in public

select n.nspname as schema, c.relname as table
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public'
  and c.relkind = 'r'
  and not c.relrowsecurity
order by 1, 2;

Every row returned is a table with RLS off. With the anon key and the default grants, an RLS-off table in public is readable by anyone who has your project URL.

3. Find permissive policies that read true

select schemaname, tablename, policyname, cmd, roles, qual, with_check
from pg_policies
where schemaname = 'public'
  and (qual = 'true' or with_check = 'true');

USING (true) on a SELECT policy means every row is visible to every role the policy names — usually authenticated, which means every logged-in user of your app. AI-generated schemas often contain one of these so the demo works before the access model is decided.

4. FOR ALL policies without WITH CHECK

select tablename, policyname, cmd
from pg_policies
where schemaname = 'public'
  and cmd = 'ALL'
  and with_check is null;

USING decides which existing rows a statement may touch; WITH CHECK decides which new row the statement may produce. A write policy with only USING lets the caller move a row it owns into a state it should not reach — a different tenant, a different owner, an escalation of a status column.

5. Grants: does anon hold write privileges?

select table_name, privilege_type, grantee
from information_schema.role_table_grants
where table_schema = 'public'
  and grantee in ('anon', 'authenticated')
  and privilege_type in ('INSERT', 'UPDATE', 'DELETE')
order by 1, 3;

RLS can still stop the write, but a grant is a second lock that should not be open by accident. Supabase’s October 30 change also broke existing tables that relied on the old default grants — the same census shows which tables expect a grant that is no longer there.

6. Default privileges: the grants that attach to future tables

select pg_get_userbyid(defaclrole) as creator,
       defaclobjtype as object_type,
       defaclacl as acl
from pg_default_acl;

ALTER DEFAULT PRIVILEGES ... GRANT SELECT ON TABLES TO anon creates no row in role_table_grants and no policy. It sits here and attaches silently when a migration creates the next table. If your builder’s migrations run as one role and your app queries as another, this is where a future leak is configured today.

7. SECURITY DEFINER functions: pin search_path

select p.proname,
       p.prosecdef as security_definer,
       p.proconfig as settings,
       has_function_privilege('anon', p.oid, 'EXECUTE') as anon_can_execute
from pg_proc p
join pg_namespace n on n.oid = p.pronamespace
where n.nspname = 'public'
  and p.prosecdef
order by p.proname;

A definer function runs with the owner’s rights. If proconfig is null, search_path is not pinned and the function can be redirected to a different schema. If anon_can_execute is true and the function touches privileged data, that is the leak path a policy review never sees.

8. Views that read as their owner

select c.relname as view_name, c.reloptions
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public'
  and c.relkind = 'v'
  and not (coalesce(c.reloptions, '{}') @> array['security_invoker=true']);

A normal view evaluates with the view owner’s rights. If that owner owns the base table and the table has no FORCE ROW LEVEL SECURITY, the view can return rows the caller’s policies would hide. security_invoker = true makes the view run as the caller.

9. Storage: public buckets and storage.objects policies

select id, name, public from storage.buckets order by name;

A public bucket serves every object to anyone with the URL, with no RLS involved. For private data, use a private bucket plus signed URLs, and review the storage.objects policies the same way you review table policies — one policy per operation, scoped by owner.

10. Grep the client bundle for the bypass keys

grep -rn "service_role\|sb_secret_\|SUPABASE_SERVICE" \
  --include="*.ts" --include="*.tsx" --include="*.js" \
  --include="*.env*" . | grep -v node_modules

service_role and sb_secret_ bypass RLS by design. They belong in server-only code paths. Any hit that is imported by a client component, or prefixed with NEXT_PUBLIC_ / VITE_, is a full-database key in the browser.

11. Server routes: auth.uid() is null unless you pass the token

An API route that queries Supabase with the anon key and no user JWT runs as anon. auth.uid() is null, your policy filters everything, and the route either returns empty or fails with 42501. Worse: a route that trusts a user_id from the request body instead of the verified JWT becomes an IDOR regardless of how good the policies are.

12. Realtime: table policies do not protect channels

Postgres Changes is filtered by table RLS. Broadcast and Presence on a channel are authorized by policies on realtime.messages, and only for channels created with private: true. A public channel can be joined by anyone holding the anon key. The full mechanics — including the per-connection policy cache — are in Supabase Realtime security: table RLS does not protect your channels.

13. Put a baseline under it

Everything above is a snapshot. The failure mode is not “I never checked”; it is “I checked in March and the schema changed in July”. A nightly read-only diff over the same catalog queries reports only new fingerprints, and fails closed when the credential breaks instead of writing an empty baseline.

Get the free RLS Drift Monitor (13 checks, n8n + SQL) →

Honest limits

These are catalog checks, not proof of a leak. They do not read application rows, do not run as service_role, and do not modify anything. The queries were verified against a local PostgreSQL 17 fixture, not against hosted Supabase projects; hosted defaults and the exact revision your project runs are outside what a public catalog query can tell you. Zero findings does not mean safe — the catalog cannot tell you what your access model should have been. If you want a person to read the results and separate real exposure from noise, that is a fixed-scope review: Supabase RLS Spot Check. Work starts only after payment is secured.

Related: the first 15 minutes of a Supabase security audit · leaked service_role key: the 30-minute rotation runbook · a read-only nightly RLS drift check.

Free entry

If you would rather run these checks yourself

Honest limit: a catalog check is not proof of a leak, and an empty log is not proof the key was never used. Zero findings does not mean safe. If you want a human: $29 self-run kit · $95 spot check (five tables, one working day) · $195 full audit — work starts only after payment is secured.

Template bundle

Review all 20 frontend starters in one bundle

20 editable frontend starters with live demos are $79 — one payment, no subscription.

View the Bundle — $79↗