Why RLS is the only lock
When you connect a frontend to Supabase, the project gives you an anon key. Newer dashboards may call this a publishable key. That key is public on purpose. It lives in your client code so the browser can talk to Supabase, and anyone can copy it out of your JavaScript. That is expected.
What is not expected is leaving the tables unlocked. Row Level Security (RLS) is the set of rules inside Postgres that decides which rows a request can see or change. Without those rules, a public key is enough to read or write whatever the role is allowed to touch.
An arXiv study of 200 deployed vibe-coded apps found that 91% had at least one vulnerability, and 64% had broken access control.
If you remember one thing: the anon key is not a secret. RLS is the lock.
1. Enable RLS on every table
Creating a table, or letting an AI tool create one, does not turn RLS on by itself. A table in an exposed schema without RLS can be read or written by any role that has a grant on it.
In the Supabase dashboard, open each table you expose and confirm RLS is enabled. Or run this in the SQL editor (change the table name to match yours):
alter table public.todos enable row level security;
Once RLS is on, nothing is reachable through the Data API with the anon or publishable key until you add policies. Add only the policies your app actually needs.
For private data, start with an owner-only read policy. This example, from Supabase's official docs, lets a signed-in user select only their own rows:
create policy "Individuals can view their own todos."
on todos for select
to authenticated
using ( (select auth.uid()) = user_id );
Add similar policies for insert, update, and delete if your app does those things. The user_id column has to be set to the signed-in user's id when a row is created, or the policy cannot match.
2. Avoid using (true) on private data
A policy with using (true) means this rule matches every row. That is fine for data that is meant to be public, such as a published blog post. On a table of users, orders, messages, or uploads, it is an open door.
AI tools write this a lot because it makes the demo work on the first try. If you see using (true) on a table that holds anyone's private data, tighten it so it checks auth.uid() (or an equivalent membership rule) before you launch.
A policy written to anon with using (true) lets every logged-out visitor read every row that role can already reach. Use that only for data you are happy to show the whole internet.
3. Test logged out
Sign out, or open your app in a private window with no session. Then try the things a stranger could try:
- Visit pages that should need a login.
- Watch the network tab for Supabase requests that still return rows.
- If you know a table name, try fetching it while signed out.
If a signed-out visitor can see emails, profiles, orders, or other people's files, stop and fix the policies. Your UI can hide a page and still leave the table open.
4. Test as a second user
This is the test most vibe-coded apps skip. It catches user B opening user A's record by pasting an id.
- Create two accounts: user A and user B.
- Sign in as A and create a record (a note, a project, an order).
- Copy the id from the URL, or note the row id.
- Sign out, then sign in as B in a fresh window.
- Try to open A's record by pasting the id, and try listing the table as B.
B should see only B's rows. If B can read, edit, or delete A's data, the policy is too broad, even if RLS is enabled. "RLS is on" is not the same as "RLS is doing the right thing."
5. Storage buckets need their own policies
Table policies do not cover Storage. Files live in buckets, and access is controlled by RLS policies on storage.objects. You only need policies on storage.buckets if the client itself creates or lists buckets.
A public bucket can be downloaded through its public URL without a policy check. If a bucket holds private files, keep it private and add policies. This official example lets a signed-in user read a file they previously uploaded:
create policy "Individual user Access"
on storage.objects for select
to authenticated
using ( (select auth.jwt()->>'sub') = owner_id );
Add insert (and often update) policies if users upload, then test logged out and as a second user, including file URLs.
6. Views can bypass RLS
By default, a Postgres view runs with the permissions of the role that created it. If that owner can see every row, the view can skip the table policies you just wrote.
On Postgres 15 and above (current Supabase projects include this), create or alter the view with security_invoker = true so the underlying table policies apply:
create view public.todo_list
with (security_invoker = true) as
select id, user_id, title
from public.todos;
If you already have a view, switch it with:
alter view public.todo_list
set (security_invoker = true);
Then test it logged out and as a second user, the same as a table.
7. Never ship the service_role key
The service_role key (and the newer secret key) bypasses RLS. It is for trusted server code only. If it appears in your frontend bundle, anyone can act as an admin on your project.
Do not put it, or any other secret, in a variable that starts with VITE_ or NEXT_PUBLIC_. Vite and Next.js copy those values into the client build on purpose. That prefix means this will be public.
Keep secrets in .env files listed in .gitignore. Turn on GitHub secret scanning and push protection so a slipped key is blocked before it is pushed.
After every deploy, look at the live JavaScript, not just the repo. Keys often show up in the compiled bundle even when they are no longer in the source you searched.
Pre-launch copy-paste checklist
Before you share the link, go through this list:
- RLS is enabled on every table exposed through the API
- Private tables do not use
using (true)or other catch-all policies - Signed-in users can only select their own rows (or the rows your rules allow)
- Insert, update, and delete policies are equally tight
- A logged-out visitor cannot read or write private data
- User B cannot open, edit, or delete user A's records
- Private files sit in private buckets, with their own Storage policies
- User B cannot open user A's files
- Every view over private tables uses
security_invoker = true - The
service_roleor secret key is not in the client or anyVITE_/NEXT_PUBLIC_variable .envis in.gitignore- GitHub secret scanning and push protection are on
- You scanned the live frontend bundle after the latest deploy
This list will not catch every issue. If you handle payments or sensitive data, you should still get a proper review later.
A quick extra check for leaked keys
The free self-check at The Vibe Bouncer scans your app's public JavaScript for exposed keys and secrets. It does not test RLS, database policies, or anything behind a login. Use it alongside this checklist, not instead of it.
Or get the weekly newsletter for one real mistake from AI-built apps, with a copy-paste fix.
Sources
- Row Level Security (Supabase)
- Securing your data (Supabase)
- Securing your API (Supabase)
- Database views (Supabase)
- Storage Access Control (Supabase)
- Understanding the (In)Security of Vibe-Coded Applications (the 91% and 64% figures)