Is it safe to expose the Supabase anon key in my frontend?
What is the difference between the anon key and the service_role key?
- Anon (publishable) key: public by design. It identifies your project. What it can do is decided entirely by your row level security policies.
- The service_role key: a full-access admin key. It skips every row level security rule. Use it only on a server you control, never in the browser.
- Rule of thumb: if the key ships to users' devices, assume every user has it. Your database rules are the only lock.
Why do apps get this wrong?
The anon key being public is not the problem. The problem is a public key combined with missing or loose database rules. A security firm's scan of over 5,600 public vibe-coded apps (about 4,000 of them built with Lovable) found the public key in browser bundles and reported 400+ exposed secrets and 175 instances of personal data.
In the write-up for CVE-2025-48757, researchers found 170 of 1,645 showcase apps on one AI app builder (about 10%) had database rules weak enough to expose data from homepage requests alone.
A note on names, checked 2026-11-27: Supabase now issues publishable keys (sb_publishable_...) and secret keys (sb_secret_...), and says it is deprecating the legacy anon and service_role keys in early 2027. The rule is the same for both generations. The anon or publishable key may ship to the browser. The service_role or secret key may not. Supabase rejects a secret key used from a browser with a 401, which the legacy service_role key does not do.
How do you check your own app in 5 minutes?
- In the Supabase dashboard of your own project, open the table editor. Any table marked as unrestricted, or with RLS disabled, is readable, and usually writable, with the anon key.
- Read each policy. A condition of just true, or a rule for all authenticated users with no owner check, is effectively public.
- Search your live site's JavaScript (browser developer tools, Sources tab) for the service_role key. If you find it, rotate it now: see our guide on leaked keys.
- Open a private window and confirm a signed-out visitor sees no private data.
1. Run the free local check
npx caelo .
Caelo is a free, open source (MIT) command line tool and MCP server from Irth Labs that checks the files of an AI-built app for exposed API keys, Supabase and Firebase misconfigurations and .env files with real values. It runs on your machine, uploads nothing and uses no AI model. Each finding comes with a plain-English fix.
2. Act on a finding
Follow the fix in your report and run Caelo again. If Git could commit an untracked file containing secrets, preview a US$19 quick fix for that file.
For findings that need an engineer, Irth Labs offers a US$490 App Health Check. You receive a written report within 48 hours and a fixed repair quote. The fee counts toward the repair if you proceed.
Questions
Should I hide the anon key in an environment variable?
You can keep it in an environment variable for tidiness, but it still ships to the browser. Hiding it does not protect anything. Row level security does.
Can someone abuse my anon key even with RLS on?
They can call your API with it, like your own app does. With correct policies they only reach what a normal visitor could. Add rate limits and email confirmation on sign-up to reduce abuse.
I committed the service_role key to GitHub. Is deleting the commit enough?
No. Rotate the key first, because anyone may already have copied it. Then clean the history. Our leaked-key guide has the steps.
Does this apply to the new publishable and secret keys?
Yes. The publishable key replaces the anon key and is public; the secret key replaces the service_role key and must stay on the server.