Is your Supabase anon key safe in the frontend? Yes. Here's what isn't.
If you've built an app on Supabase with Lovable, Bolt, v0 or Cursor, you've probably opened DevTools, seen a long eyJ... key in your JavaScript, and felt your stomach drop. Good news first: that key is supposed to be there. Here's what it does, and the four things that do leak data in Supabase apps.
The anon key is public by design
| Key | Starts with | Where it belongs |
|---|---|---|
| anon / publishable | eyJ... (role anon) or sb_publishable_ | The browser. Fine to ship. |
| service_role / secret | eyJ... (role service_role) or sb_secret_ | Only on a server. Never in the browser. |
The anon key only identifies your project. What someone can do with it is decided entirely by your Row Level Security (RLS) policies. So the anon key is safe only if RLS is doing its job.
1. Tables with RLS turned off
With RLS off, anyone who copies your anon key can read, and often write, the whole table with one request. Check every table in the SQL editor:
select tablename, rowsecurity
from pg_tables
where schemaname = 'public';
Anything showing false is open. Turn RLS on and add a policy that ties rows to their owner:
alter table public.profiles enable row level security;
create policy "Users read their own profile"
on public.profiles for select
using (auth.uid() = user_id);
Watch out for policies with using (true). They switch RLS on but let everyone through.
2. The service_role key in the browser
The service_role (or sb_secret_) key bypasses RLS completely. AI tools sometimes put it in a VITE_ or NEXT_PUBLIC_ variable to make an admin feature work, and anything with those prefixes is shipped to every visitor. If you find it, rotate it in Supabase (Settings → API) and move the admin work into an Edge Function.
3. Storage buckets
Storage has its own policies on storage.objects, separate from your tables. A public bucket means anyone with a file's URL can download it.
4. Views and functions that skip RLS
- Views run with their creator's rights by default, so a view over a protected table can expose it. On Postgres 15+, create them
with (security_invoker = on). - Functions marked SECURITY DEFINER also run with their owner's rights. If one is callable through the API, make sure it only returns what the caller should see.
The 2-minute check
- In DevTools → Sources on your live app, search for
service_role,sb_secret_,sk-andsk_live. You should find none. - Run the SQL above. Every table should show
true. - Look for
using (true)in your policies. - Check which storage buckets are public.
LeakPatrol checks the outside of your app for leaked keys for free, and once you prove you own the site, it also tests which Supabase tables can be read without logging in.
Check your app in a minute
Free, read-only, no sign-up. Every problem comes with a plain-English fix and a prompt for your AI tool.
Get the 10-point checklist
Every check we run on AI-built apps, with how to do each one yourself. Straight to your inbox.
Plus the odd security tip. Unsubscribe any time.
Questions
Is the Supabase anon key safe to expose?
Yes. The anon (or publishable) key is designed to be public. Your data is protected by Row Level Security policies, so it is only safe if RLS is enabled with correct policies on every table.
What happens if Row Level Security is off in Supabase?
Anyone with your anon key, which is visible in your frontend, can read and often modify every row in that table without logging in.
Can the service_role key be used in the browser?
No. The service_role or sb_secret_ key bypasses all Row Level Security. Keep it on a server or in an Edge Function and rotate it if it was ever exposed.
How do I check if RLS is enabled on all my Supabase tables?
Run select tablename, rowsecurity from pg_tables where schemaname = 'public'; in the SQL editor. Any table showing false has RLS off.
More guides
- Supabase RLS policy generator (free)
- Is this API key safe in my frontend? Free key checker
- Security scan MCP server for Claude Code, Cursor and other AI agents
- Supabase October 30 grants change: what it fixes for your app's security, and what it doesn't
- Supabase "42501 permission denied for table": the safe fix (not GRANT ALL)
- Supabase "new row violates row-level security policy": 5 causes and the safe fix
- Supabase service_role key exposed? What to do in the next hour
- Supabase select returns an empty array but the data is there: the RLS fix
- Supabase "Database error saving new user": find the cause and fix it safely
- Supabase Storage upload: "new row violates row-level security policy" fixed
- Supabase "infinite recursion detected in policy for relation" fixed
- Supabase Edge Function "blocked by CORS policy" fixed
- Supabase "Forbidden use of secret API key in browser" (401) fixed
- Supabase "Legacy API keys are disabled" or "Invalid API key": what it means and the fix
- Supabase login or magic link redirects to localhost:3000 (fixed)
- Is your Supabase storage bucket public? What anyone can see, and the fix
- Where to put your OpenAI API key in a Lovable app (so nobody can copy it)
- Supabase "Function Search Path Mutable" warning: what it means and the one-line fix
- Supabase "email rate limit exceeded" fixed (and "you can only request this after 60 seconds")
- Lovable data exposure study: is your app one of the 24,664?
- Lovable security check: is your Lovable app safe?
- Bolt.new security check: is your Bolt app safe?
- Launch checklist for apps built with Lovable, Bolt and Cursor
- How to check if your API key is exposed on your website
- Are VITE_ env variables secret? How to hide API keys
- Stop users giving themselves your paid plan (Supabase)