Supabase service_role key exposed? What it means and what to do
Supabase gives every project two kinds of API keys. One is meant to be public. The other bypasses all your security rules. Mixing them up is a serious leak.
anon key vs service_role key
- anon (or publishable) key: safe to ship in the browser if Row Level Security (RLS) is enabled with sensible policies on every table. It only gets what your policies allow.
- service_role (or secret) key: bypasses Row Level Security entirely. Anyone holding it can read, change or delete every row in your database. It must only ever live on a server.
How to tell which key your site ships
Legacy Supabase keys are JWTs (they start with eyJ). Paste the one from your front-end bundle into a JWT decoder and look at the role claim: anon is expected, service_role is a leak. Newer-style secret keys start with sb_secret_ and should never appear in client code. You can also search your public JavaScript for the text service_role.
If the service_role key is exposed
- Rotate it immediately in your Supabase project's API key settings. Update any servers or functions that use it.
- Remove it from client code and from any env var with a public prefix (
NEXT_PUBLIC_,VITE_,REACT_APP_). - Review your data for unexpected changes or deletions, and check your logs.
- Move privileged operations into server routes or Edge Functions that check who the user is first.
Even with the right key: turn on RLS
Shipping the anon key is fine only if RLS is on. A table with RLS disabled is readable (and often writable) by anyone with the anon key. In the Supabase dashboard, confirm RLS is enabled on every table in exposed schemas and that each policy restricts rows to the right user.
Check your site free
The free FlowSnitch Launch Check loads your public pages and JavaScript, looks for leaked keys, a public .env or .git folder, and missing security headers, then gives you a grade and a fix list. Read-only, about 30 seconds, no account needed.