← Vibe coding database safety

Is your Supabase data public? Check row level security in two minutes

Updated · DBShifts · commands tested on real PostgreSQL, MySQL and MongoDB servers

Short answer

Your app's anon key is meant to be public, so the database decides what it can reach. Any table in the public schema without row level security, any policy that is simply true, and any view that runs with its owner's rights can hand rows to anyone holding that key. Run the three queries below in the SQL editor; every row they return needs fixing before launch.

Key facts

  • The anon (publishable) key is in your JavaScript bundle by design. Anyone can copy it from the browser's network tab.
  • Supabase's Data API runs each request as the anon or authenticated role, so Postgres grants and row level security are the only thing between that key and your rows.
  • A table with RLS on and no policy returns nothing to anon or authenticated: locked, not open.
  • A view runs with its owner's rights unless it is created with security_invoker, so it can show rows the table's own policies hide.
  • The service_role key skips RLS entirely. It belongs on a server, never in the app.
  • In 2025, researchers found many apps made with AI app builders exposing their Supabase tables because RLS was missing or wide open. Check after every schema change, not once.

1. Find tables anyone with the key can read

Open the SQL editor of the project your app uses (for apps built with Lovable or Bolt, the Supabase project they connected). Every table this returns has row level security off.

SQLTables in public with row level security 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
ORDER BY c.relname;

2. Find policies that let everyone in

RLS on is not the same as RLS that means something. A policy whose condition is just true — often added to make an error go away — lets every request through for the commands it covers.

SQLPolicies that let everyone in
SELECT tablename, policyname, roles, cmd, qual, with_check
FROM pg_policies
WHERE schemaname = 'public'
  AND (qual = 'true' OR with_check = 'true')
ORDER BY tablename, policyname;

3. Find views that skip RLS

Views are the quiet leak: by default a view reads the table with its owner's rights, and the owner is not subject to the table's policies. Every view this returns can show rows your policies would hide.

SQLViews that run with their owner's rights (and skip RLS)
SELECT c.relname AS view_name
FROM pg_class c
JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE n.nspname = 'public'
  AND c.relkind = 'v'
  AND NOT EXISTS (
    SELECT 1 FROM unnest(coalesce(c.reloptions, '{}')) AS o
    WHERE o IN ('security_invoker=true', 'security_invoker=on', 'security_invoker=1', 'security_invoker=yes')
  )
ORDER BY c.relname;

4. Fix it: RLS on, and the policy you actually mean

Turn row level security on, then add a policy per command that says who may see which rows — usually the signed-in user's own. For views, make them run as the caller so the table's policies apply.

SQLTurn RLS on and allow each user their own rows
ALTER TABLE public.profiles ENABLE ROW LEVEL SECURITY;

CREATE POLICY "read own profile" ON public.profiles
  FOR SELECT TO authenticated
  USING ((SELECT auth.uid()) = user_id);
SQLMake a view respect the caller's RLS (PostgreSQL 15+)
ALTER VIEW public.order_totals SET (security_invoker = on);

5. Check as the public key would

Switch to the anon role in the SQL editor and query the table. After the fix it should return nothing for anon (or only what you meant to be public).

SQLSee what the public key sees
SET ROLE anon;
SELECT count(*) FROM public.profiles;
RESET ROLE;

6. Keep checking

Supabase's dashboard has a security advisor that flags tables without RLS; read it after each change. An AI app builder can create a table in a second, and a table it creates is as exposed as one you create.

Common mistakes

USING (true) to make an error go away

It turns RLS on and lets everyone through. The error was the protection working.

The service_role key in the app

It skips RLS for everyone who opens the browser's dev tools. Use it only in server code or edge functions.

Forgetting storage

Files in Supabase Storage have their own policies, on storage.objects. A private bucket with an open policy is a public bucket.

Trusting a user_id the client sends

A policy that compares to a column the user can write needs WITH CHECK on insert and update, or users can write rows as someone else.

Checking once at launch

Every new table starts without RLS unless you enable it. Re-run the queries after every migration.

How DBShifts helps

  • When an AI agent needs your Supabase data, Airlock connects it with a scoped token instead of a key: only the tables you allow, personal data masked, row filters per tenant, every request logged.
  • Airlock works with any Postgres, Supabase included; connect it with a read-only role.

Questions people ask

Is the Supabase anon key a secret?

No. It is designed to be public and is in every copy of your frontend. What protects your data is row level security and the grants on each table.

How do I enable row level security in Supabase?

ALTER TABLE public.your_table ENABLE ROW LEVEL SECURITY; then CREATE POLICY for each command you want to allow. With RLS on and no policy, the table returns nothing to the anon and authenticated roles.

Does row level security slow queries down?

A policy is a condition added to every query on the table. Index the columns it uses, and wrap auth.uid() in a SELECT as shown, so it is evaluated once per query instead of once per row.

My app was built with Lovable or Bolt. Where do I run this?

In the SQL editor of the Supabase project the app is connected to. The queries only read the system catalog, so they change nothing.

Let AI read your Supabase data without exposing it

Scoped, masked, logged access for agents. Free to start.

7 guides in this series. See the checklist.