Is your Supabase data public? A two-minute RLS check

Updated · by Zane

Why this matters for apps made with AI tools

An app built with Supabase talks to the database straight from the browser. It does that with the anon key, which newer projects call the publishable key. Anyone who opens your site can find that key in the page code. That is how it is meant to work. It is not a leak.

So the key cannot be what protects your data. Row level security does. RLS is a set of rules on each table that says who can see or change which rows. If a table has no RLS, the public key is enough to read, edit and delete the whole table. AI builders do not always switch RLS on when they create a new table. I would assume nothing and check.

Top: with row level security on and no open policy, the public anon key gets nothing from a private table, and the check returns []. Middle: with RLS off, or a policy written as using (true), the same key can read, change and delete every row. Bottom: the anon key is public on purpose, while the service role (secret) key skips every RLS rule, so it must never appear in frontend code or a VITE_ variable.

The two-minute check

Only do this on your own project.

1. Look at the tables

Open the Supabase Dashboard, then Table Editor. Look next to each table name for a marker saying RLS is not enabled. Any table with user data and that marker is open.

2. Run Security Advisor

Open Supabase Dashboard, then Advisors, then Security Advisor. It lists tables without RLS and policies that are too loose. Read every line.

3. Ask for the data yourself

This is the test that settles it. In a terminal on your own computer, request a table that holds user data, using your project address and your anon key, while not logged in:

Terminal
curl "https://<project-ref>.supabase.co/rest/v1/profiles?select=*" \
  -H "apikey: <anon key>" \
  -H "Authorization: Bearer <anon key>"

If you get back rows that belong to other people, that table is public. If you get [], an empty list, the table is protected from anonymous visitors. Try each table that holds anything private.

RLS can be on and still not protect you

Two patterns make RLS close to useless. Look for them when you read your policies:

  • A policy written as using (true). That says every row is allowed.
  • A select policy opened to the anon role on a table that holds private data.

You can see policies in the Supabase Dashboard, then Authentication, then Policies.

Fix it

For each table, switch RLS on, then write policies for who may see which rows. This is what the correct shape looks like in my demo project, where each user can read only their own profile row:

From the demo project's profiles table
alter table public.profiles enable row level security;

create policy "profiles_select_own" on public.profiles
  for select to authenticated
  using (auth.uid() = id);

If users should read and write their own rows on another table, a policy like this does it. Swap in your own table and column names:

Users own their rows
alter table public.notes enable row level security;

create policy "notes_own_rows" on public.notes
  for all to authenticated
  using (auth.uid() = user_id)
  with check (auth.uid() = user_id);

If some content really is public, such as published posts, give it its own read-only policy. Do not open the whole table:

Public read for published rows only
create policy "posts_public_read" on public.posts
  for select to anon, authenticated
  using (published = true);

Turning RLS on with no policy denies everything to the frontend. Parts of your app will then show no data, or their updates will change 0 rows with no error. That is expected, and the cure is adding the right policy. I explain that case in Supabase update returns no error but nothing changes. Do not fall back to using (true) to get things working.

Three places people forget

  • Storage. Check whether each bucket is public, and whether it has storage policies. A public bucket serves its files to anyone with the link.
  • The service role key. It is called the secret key in new projects. It skips every RLS rule. If it appears in frontend code, or in a variable starting with VITE_, the whole database is effectively public. The Vite build copies those variables into the page, which is also why a missing one gives a blank page, as in Blank white page after publishing your AI-built app. If you ever find the key there, rotate it in the Supabase dashboard right away.
  • Functions and views. A database function or view can run with more power than the person calling it. Check that they do not hand back rows the caller should not see.

If you find data was exposed

  1. Turn RLS on first. That stops the exposure.
  2. Add policies so the app works again.
  3. Rotate any secret key that might have been visible.
  4. Work out what was exposed and for how long. Whether you must tell your users depends on where you and they are. I cannot give legal advice here, so ask someone who can.

Check that the fix worked

Run the same request as before. Not logged in, it should return nothing for private tables. Then log in to your app as yourself and confirm your own data still loads and saves. Both results need to be right. A locked-down table that breaks your app is not finished.

Payments carry the same kind of risk. A plan column that users can edit themselves lets anyone upgrade for free. The fix for stuck upgrades is in Stripe payment succeeded but the user is still on the Free plan.

FAQ

My anon key is visible in the browser. Have I been hacked?

No. That key is public by design. Every visitor's browser needs it to talk to your database, so it will always be visible. What matters is whether each table has row level security with sensible policies behind it.

I turned on RLS and now my app shows nothing.

That is expected. RLS with no policies denies everything to the frontend. Add a policy for who may read or write which rows. Updates that quietly change 0 rows have the same cause, and I cover them in the guide linked above.

Does Lovable's or Supabase's security scan make this unnecessary?

A scan can spot tables with RLS switched off. It cannot know whether your policies match your business rules. Running the request yourself once, from outside the app, is still worth two minutes.

Checklist

Still stuck?

Send me the app link and what's broken. The first look is free and you get a fixed quote before I touch anything.

Related guides