Is the Supabase anon key safe to expose in my app?
- The anon key (also called publishable key) ships inside every Supabase web app. It's designed to be public.
- With it, anyone can query your database directly, outside your app. Row Level Security decides what they get.
- The service_role (secret) key is the opposite: it skips all rules and must never be in the browser.
What a stranger can do with your anon key
Your app's code is downloaded by every visitor, so the anon key and your project address are visible to anyone who looks. With those two values, a person can talk to your database without using your app at all: list tables your policies allow, read rows, insert rows, call database functions, and download files from public buckets.
That's by design. Supabase expects every table to be protected by Row Level Security, so the key only opens what your policies allow. The problem is tables where RLS is off or too open: for them, the public key is effectively a master key.
# What anyone can run with your public values (replace the placeholders): curl 'https://YOUR-PROJECT.supabase.co/rest/v1/profiles?select=*' \ -H 'apikey: YOUR_ANON_KEY' # If this returns rows, a stranger can read that table without signing in.
The key that must never be public
The service_role key (secret key) skips Row Level Security entirely. If it appears in your front-end code, in a VITE_ or NEXT_PUBLIC_ variable, or in a file the browser downloads, anyone can read and change everything. Rotate it immediately in the Supabase dashboard and move whatever needs it to a server function.
How to check it yourself
- In the Supabase SQL editor, list your tables and whether RLS is on: select tablename, rowsecurity from pg_tables where schemaname = 'public';
- For each table, run the curl above with your anon key (signed out, no user token). Tables with private data should return an empty list or an error.
- Search your project for service_role, the secret key, and any variable starting with VITE_ or NEXT_PUBLIC_ that holds a key. None of them should be the service role key.
- In Storage, check which buckets are public. Only files meant for anyone (logos, public images) should be there.
Prompt to fix it
Fix prompt
Make the app safe with a public anon key. Enable Row Level Security on every table in the public schema. For tables that hold private data, allow no access to the anon role and only allow signed-in users to read and change their own rows (user_id = auth.uid()). Keep public read access only on tables that are really public, and say which ones. Make sure the service_role key is never used in front-end code or in variables exposed to the browser; move any code that needs it to a server function. Make private storage buckets non-public. List every change.
Want us to run this test for you?
The US$9 crash test without code signs in as two test users on your live app and checks this for you: data between users, private pages and the API behind them, free vs. paid plans, and what your public Supabase key opens. You get the evidence and a fix prompt for each issue.
Related guides
- Can users see each other's data in my Supabase app?
- Service role key in the browser: how to find it and fix it
- Lovable admin page accessible without login: hiding it isn't locking it
Updated 2026-11-24