Skip to main content
Sealgap

What is a Service Role Key?

The service role key is a Supabase API key with full access to the data in a project, because requests made with it skip every Row Level Security policy. It exists for trusted code that runs on a server, and it must never be placed in code that reaches a browser.

What the service role key is for

Some work is done on behalf of the whole app and not a single user: sending a nightly summary, handling a payment notification, cleaning up old records. That code needs to read and write rows no matter who owns them. Supabase provides a key for that purpose. It maps to a database role that is allowed to bypass Row Level Security, so none of the access rules written for ordinary users apply to it.

The Supabase documentation on API keys is direct about where it belongs: only in backend components such as servers, Edge Functions and scheduled jobs, and never in a browser, a shipped application or source control.

Service role key and secret key

In newer Supabase projects the same kind of key is called a secret key and starts with sb_secret_. The service role key is the legacy version, a long token that starts with eyJ, and Supabase has announced that it is deprecating the legacy keys by the end of 2026. Supabase refuses the newer secret keys when a request comes from a browser.

How it ends up in the wrong place

The usual route is a shortcut. A request from the app fails because an access rule blocks it, and swapping the public anon key for the service role key makes the error go away. The app works, and nothing on the screen shows that it now ships a master key to every visitor.

Anyone who finds the key in the shipped JavaScript can read, change and delete data across the project, whatever the Row Level Security policies say.

What to do when it has leaked

Removing the key from the code is not enough, because copies of the old code may already exist elsewhere. The key itself has to be replaced. The guidance from Supabase is to rotate a leaked key as soon as the cause of the leak is fixed. In practice that means moving the work that needed the key to a backend function, creating a new key, updating the backend to use it and retiring the old one.

What to check

Search the JavaScript files of the live app for sb_secret_, and compare any long token that starts with eyJ with the keys in the Supabase dashboard. A check that finds no secret key shows that none was in the shipped files on that day. It is worth repeating after every release, since one changed variable is enough to put a key there.

Also known as

service_role key secret key

Free check

See what one of your apps answers.

Certificate, browser protections and keys in public code. No account needed.

See what one of your own apps answers.

The free check looks at an app from the outside: whether it answers, its certificate, its browser protections and keys in its public code.