Supabase Service-Role Key Exposed? Here's Exactly What to Do

Found your Supabase service_role key in client code or a public repo? It bypasses all your security. Here's exactly how to rotate it and lock things down — step by step.

· 5 min read

If your Supabase service_role key has leaked, don't panic — but do move now. Unlike the anon key, the service-role key bypasses every Row-Level Security policy you have. Anyone holding it can read, edit, and delete your entire database. Treat an exposed service-role key as a live break-in.

If you only do one thing

Rotate the key immediately. Everything else below matters, but rotation is what actually cuts off the attacker — the leaked value is out there and can't be un-leaked.

Step 1 — Rotate the key now

In your Supabase dashboard, open Project Settings → API and roll (regenerate) your keys. Rolling invalidates the leaked service-role key so it stops working.

Step 2 — Get it out of the code (and history)

  1. Delete the key from your source. It should never live in client-side code at all.
  2. If it was in a public repo, assume bots already scraped it — Step 1 (rotation) is what protects you, not deletion. Then purge it from git history (e.g. git filter-repo or BFG) so it isn't sitting in old commits.

Step 3 — Turn on Row-Level Security for every table

The service-role key is powerful precisely because your anon /authenticated access is supposed to be constrained by RLS. If RLS is off, even your public anon key exposes everything. In the Table Editor, enable RLS on every table and add policies so users can only touch their own rows.

Step 4 — Keep the service-role key server-side, forever

Check your repo for exposed Supabase keys — free

Trust detects service-role JWTs and 20+ other key types in your code and live site.

Run a free scan →

Want to be sure nothing else slipped through? Trust scans your GitHub repo and your live URL in one pass and flags exposed keys, RLS-off patterns, and misconfigurations — in plain language, with the fix.