Your Supabase service_role key is in your frontend. Here's what to do.
Last reviewed November 26, 2026 against the providers' current documentation.
The short version
Treat it as stolen. Create a new Supabase secret key, move every call that needs it to your server, then turn the old key off. Removing it from your code alone doesn't help, because the old key keeps working until you turn it off. Supabase no longer lets you rotate the legacy keys, so the way out is the new key system.
Why it matters
The service_role key (and its newer replacement, the sb_secret_ key) belongs to a database role that skips every Row Level Security policy. Anyone who opens your site can copy it from the JavaScript and read, change or delete every row in every table, including other users' data.
Fix it, in this order
Confirm it's really the service_role key
Supabase's legacy keys are long strings starting witheyJ. The middle part of the key (between the two dots) says which role it is. If it containsservice_role, it's the dangerous one. New-style keys are easier:sb_secret_…is dangerous,sb_publishable_…is fine. Our free check decodes this for you.Create the new keys
In the Supabase dashboard, open Settings → API Keys and select the Publishable and secret API keys tab. Creating them is safe: Supabase says it doesn't revoke your legacy keys, and both systems work at the same time until you switch the old ones off. Supabase is deprecating the legacyanonandservice_rolekeys in early 2027, so you'd have to make this move anyway.Move the work to the server
Find every place your app used the leaked key. Anything that needs admin rights has to run on a server: a Supabase Edge Function, a Next.js API route or server action, or your backend. Put the new secret key in that server's environment variables, never in a variable the browser can read (VITE_…,NEXT_PUBLIC_…,EXPO_PUBLIC_…). A new secret key won't even work from a browser: Supabase checks theUser-Agentand returns 401. Edge Functions can read the new keys fromSUPABASE_SECRET_KEYS. If a database webhook orpg_netcall sends the service_role key asAuthorization: Bearer, send the secret key on theapikeyheader instead; secret keys aren't JWTs, so the Bearer header rejects them.Use the publishable key in the browser
Your frontend should use only the publishable key (sb_publishable_…) or the legacy anon key. Both are designed to be public, as long as Row Level Security is on for your tables.Find every other caller
Supabase has no automatic indicator of what still uses the legacy keys, so check by hand: older versions of a mobile or desktop app already on people's phones, CI/CD and deploy scripts, third-party integrations and webhooks, cron jobs and workers, andpg_netcalls or Database Webhooks in your database.Deploy, then deactivate the legacy keys
Deploy the fixed app and confirm it works. Then, on the same API Keys page, deactivate the legacy keys. Supabase says this step is reversible: if you find a client you missed, you can re-activate them while you fix it. If the leaked key was a newsb_secret_key, replace that one key the same way. Supabase suggests one secret key per backend component so a leak only forces one rotation.Check whether anyone used it
Look at your tables for rows you don't recognize, missing data, or new admin users, and check the API logs in the Supabase dashboard for unusual activity. If you store personal data and see signs of access, you may have legal duties to notify users; ask a lawyer where you operate.
Or ask your AI tool to do it
Paste this into Lovable, Bolt, Cursor, Claude Code or whichever tool built your app. Review what it changes before you deploy.
My Supabase service_role key was exposed in frontend code. Find every place the app uses the service_role or secret key. Move each of those operations into a server-side function (Supabase Edge Function or an API route), read the key from a server-only environment variable, and make the frontend call that function instead. The browser must only use the publishable/anon key. Do not put the key in any VITE_, NEXT_PUBLIC_ or EXPO_PUBLIC_ variable. Then list the tables the frontend reads or writes so I can check their Row Level Security policies.
How this happens
It usually starts with a permission error. The app can't read a table because Row Level Security blocks it, and the quickest fix an AI tool finds is to swap in the key that ignores those rules. It works instantly, so it ships. The real fix was a Row Level Security policy that lets each user see their own rows.
Check that it's really fixed
After you deploy, run the free check. It reads your live site the way an attacker would and tells you if any secret key is still visible.
Topic check: Supabase security check
Test your database, not just your code
The free check can only see your code. The website security report can add database tests: with test accounts you create, it checks whether a stranger or another signed-in user can read data they shouldn't. It also covers up to 30 pages and 40 JavaScript files, exposed files, headers and libraries, with the fix for each finding.
$19 once, including 20 runs over 30 days so you can fix things and check again.

Questions
Is it enough to delete the key from my code and redeploy?
No. Copies of your old JavaScript stay in browser caches, search engine caches and anyone's downloads. The key itself must be turned off in Supabase.
Will my users get logged out?
Switching from the service_role key to a new secret key is designed to avoid downtime, and secret keys aren't the tokens your users log in with. Regenerating the project's legacy JWT secret is a different, bigger step: Supabase says all current API secrets are immediately invalidated and connections using them are severed. Supabase's own advice is to avoid that by migrating to the new API keys.
Can't I just rotate the service_role key?
Not anymore. Supabase's troubleshooting page says it is no longer possible to rotate the legacy anon, service and JWT secrets. Create the new publishable and secret keys, move your app to them, then deactivate the legacy keys.
When do the legacy keys stop working?
Supabase says it is deprecating the legacy anon and service_role keys in early 2027. It doesn't give an exact date, so migrate now rather than wait.
Sources
- Supabase: Understanding API keys
- Supabase: Migrating to the new API keys
- Supabase: Rotating anon, service and JWT secrets