Day 3 of 24

Keep the Supabase service role key on the server

One key skips every access rule you wrote. Make sure the browser never sees it.

What goes wrong

Only code that runs on your server should ever see the service role key. Newer Supabase projects call it the secret key, and Supabase is retiring the old service_role and anon keys by the end of 2026. The key skips every access rule, so anyone who finds it can read and change every row.

How to check

  1. Ask your developer where in the code the service role or secret key is used.
  2. Confirm every one of those places runs on a server or in an Edge Function, never in a page.
  3. Open your live app, view the page source and loaded scripts, and search for the key.
  4. Check that the variable holding it has no public prefix such as NEXT_PUBLIC_ or VITE_.

How to fix

Move every call that needs the key into a server route or Edge Function that checks who is asking. If the key was ever exposed, create a new secret key in the dashboard, switch the app to it, then delete the old one. For a leaked legacy service_role key, Supabase also says to revoke the legacy JWT secret.

What good looks like: A search of the live site finds no trace of the key, and only server files read it.

Source: Supabase: Understanding API keys

Rather have someone run this check for you?

Have your Supabase rules tested
Keep the Supabase service role key on the server | Valletta