Duvaxa

7 min read · Updated 2 Nov 2026

Supabase service role key exposed: what to do in the next hour

In short: A Supabase service role key in your front end lets anyone read, change and delete every table, ignoring row-level security. How to confirm it, rotate it, check what happened and stop it happening again.

Free tool: AI-built app leak check →

Supabase gives every project two kinds of key. The public one (the anon key, or a newer publishable key) is meant to be in your app: everything it can do is limited by your row-level security (RLS) policies. The service role key, or a newer secret key, is the opposite. It bypasses RLS completely and is meant only for servers. If it ends up in JavaScript that a browser downloads, anyone who opens your site can copy it and do anything to your database. Apps built quickly with AI builders like Lovable, Bolt and v0 ship it more often than you'd think, usually because a query failed under RLS and the service key "fixed" it.

1. Confirm which key is exposed

Open your site, view the page source and the JavaScript files it loads, and search for eyJ (the start of a JWT) or sb_secret_. A JWT key is three base64 parts separated by dots; decode the middle part and look at the role field.

  • "role": "anon" is the public key. It's expected in the browser; your RLS policies are what protect you.
  • "role": "service_role" is the secret key. Treat it as compromised from the moment it was deployed.
  • A key starting sb_secret_ is a secret key in Supabase's newer key format, and is just as dangerous.

Our free check does this for you: it reads your app the way a browser does, decodes any Supabase JWT it finds and reports the role, without ever using the key.

2. Rotate it now

How you rotate depends on the key format.

  • Newer secret keys (sb_secret_...): create a new secret key in Project Settings, API Keys, move your server code to it, then delete the leaked one. Other keys and user sessions aren't affected.
  • Legacy JWT keys: the service role key can only be changed by rotating the project's JWT secret. That also changes the anon key and signs out every user, so update your app's anon key in the same deploy and plan for users logging in again. If you can, move to the newer key format at the same time.

Don't wait until you've found out whether it was used. Rotation is the only thing that stops further use.

3. Get the key out of the front end

The key was in the browser because browser code was doing something only a server should. Move that work behind a server: a Supabase Edge Function, an API route, or a database function called with the public key and protected by RLS.

  • In Vite apps, any variable starting VITE_ is bundled into the browser code. In Next.js, the same is true of NEXT_PUBLIC_. A service key must never have either prefix.
  • Search the repository for the key's name as well as its value, and remove it from the history if the repository is public.

4. Check what happened while it was public

  • In the Supabase dashboard, use the logs for the API gateway and the database to look for requests you don't recognise, especially from IP addresses that aren't yours, and bulk reads or deletes.
  • Compare row counts and recent changes in important tables with what you expect. Check the auth users table for accounts you didn't create.
  • If data was changed or deleted, restore from a backup or point-in-time recovery if your plan has it.
  • If personal data could have been read, you may have to notify people or a regulator, depending on where your users are. Write down what you found and when.

5. Make sure the public key is safe on its own

Once the service key is gone, the public key is the only thing in the browser, and RLS is all that stands between it and your data. Turn RLS on for every table in the public schema and write policies for each one. A table with RLS switched off is readable and writable by anyone with the public key, which is everyone.

6. Stop it happening again

  • Check every release for secrets in the built JavaScript, not just in the source code.
  • Keep the service key only in server-side environment variables, never in a file that's built into the front end.
  • Run a check like ours before each launch and after any change made with an AI builder.

FAQ

Questions

Is the Supabase anon key a secret?

No. It's designed to be public, and is safe as long as row-level security is on and correct for every table.

Does rotating the JWT secret log users out?

Yes, for projects on the legacy JWT keys: existing sessions become invalid and users sign in again. The newer secret keys can be replaced without that.

Can I just delete the key from my code?

Not on its own. Anyone who loaded your site may already have copied it. Rotate first, then remove it.

How do I know if someone used the key?

Look at the API and database logs for the period it was public. Absence of evidence isn't proof, so rotate regardless.

Tools for this

Products that help

Security & Compliance

LaunchLock

Security check for AI-built apps

Built it with AI? Make sure it isn't leaking before you launch. Checks apps built with Lovable, Bolt, v0, Replit or Cursor for secret keys anyone can copy, public files, and database tables strangers can read, before you launch.

  • Who it's forFounders who built their MVP with Lovable, Bolt, v0 or Replit · Agencies shipping AI-built apps for clients
  • What you getLeaked-key and exposed-file report · Table-by-table RLS results · A branded client report to print to PDF
Free to start · from $29/monthView product →
Security & Compliance

LeakResponder

Leaked secret response

From leaked key to closed incident. When a password or API key leaks, it finds every leaked secret in your code, tells you which to change first and how, and keeps proof that each one was fixed.

  • Who it's forSoftware companies without a security team · Agencies handing repositories to clients
  • What you getRanked list of leaked secrets · Response runbook per provider · Verified rotation tracker
Free to start · from $14/developer/monthView product →
DevOps & Cloud

LaunchReady

Production readiness score

Launch with confidence. Checks an app before launch for the basics that cause failures, such as exposed passwords, missing health checks and no rollback plan, and gives it a Bronze, Silver or Gold score.

  • Who it's forIT services firms · Startups before launch or due diligence
  • What you getReadiness tier and score · Fix list per tier · Client-ready report
From $49/monthView product →