My Supabase service_role key is exposed

The service_role key skips row-level security, so anyone holding it can read, change and delete every row in every table. The anon key is different and is meant to be public.

How to fix it

  1. In Supabase → Project Settings → API, roll the service_role key (a JWT secret rotation) right away. This also changes the anon key, so copy the new one into your app.
  2. Search your code for service_role and for the environment variable that held it, and remove it from anything that runs in the browser.
  3. Use the anon key in the browser. Turn on row-level security for every table, with policies for who may read and write.
  4. Keep the service_role key for server code only: Edge Functions, server routes and scripts.
  5. Redeploy, then scan again.

Common questions

Is the anon key a leak?

No. It's designed to be public. Row-level security policies are what protect your data.

How do I tell them apart?

Decode the JWT: its payload says "role":"anon" or "role":"service_role". The leak check does this for you.

I rotated the key: am I done?

Also check the table editor and your logs for changes you didn't make.

Fixed it? Scan again to confirm.

Scan your app for leaks