What is the Supabase service_role key and where can I use it?

Published 2026-11-16, updated 2026-11-29 by Nordik. Written with AI from the sources listed at the end.

Short answerIt is a master key that skips all Row Level Security, so use it only in code that visitors cannot see.

The service_role key, now called the secret key, maps to the database's service_role role and goes around Row Level Security (the database's rules about who may see a record). Supabase's documentation says secret keys must never reach a browser and belong only in server code such as Edge Functions. New secret keys start with sb_secret_; older ones are long strings that start with eyJ.

It usually leaks through a setting named SUPABASE_SERVICE_ROLE_KEY that ends up in browser code. In Next.js, a name starting with NEXT_PUBLIC_ is sent to the browser, so never give this key that prefix. A copied key still works from other tools.

To check, open your app, press F12 and search all files for sb_secret_, service_role and the last ten characters of your own key. If it turns up, Supabase's guide on leaked keys says to fix the cause first, then create a new key, move your app to it and delete or deactivate the old one.

The free scan looks for this key in your published app's scripts. See also six checks for Lovable apps.

Sources

Each source below was accessed on the date shown. Documentation changes over time, so check the source for the current wording.

  • Supabase documentation, API keys, accessed 2026-11-29
  • Supabase documentation, Row Level Security, accessed 2026-11-29
  • Supabase documentation, Rotate leaked API keys, accessed 2026-11-29
  • Next.js documentation, Environment variables, accessed 2026-11-16

See what your live app shows strangers

Paste the link to your app: in under a minute the free scan shows what your live app hands to any visitor, and where to look first. No sign-up, and it never signs in or changes anything.

Run a free scan

Want the code itself read? Order the $49 audit or see a sample report. Your card is held and charged only when your report is delivered. It is not a pentest: the audit is done by AI, and a second AI checks each serious finding.