Exposure Medium

Replace the exposed Supabase secret key

Supabase's newer API keys come in two kinds: a publishable key (sb_publishable_...) that is safe in a browser because Row Level Security decides what it can do, and a secret key (sb_secret_...) for servers only. Supabase's docs say a secret key bypasses Row Level Security and must never be put in a browser, so one in a page's code hands every visitor full access to the project's data.

Find out whether your site has this problem, and every other check, in one free scan.

Check your site free

Why it matters

A Supabase secret key (sb_secret_...) acts as the service_role, which skips every Row Level Security policy, so anyone who copies it from the page can read and change every table in the project.

How to fix

  1. 1 Revoke it: in the Supabase dashboard (Project Settings, API Keys) create a new secret key, switch your servers and Edge Functions to it, then delete the exposed key. Deleting it is the step that stops the copied key from working.
  2. 2 Use the publishable key (sb_publishable_...) in browser code, with Row Level Security on every table deciding what it can reach.
  3. 3 Purge the old key from git history so it is not recoverable from a prior commit.
  4. 4 Redeploy and confirm the shipped bundle has no sb_secret_ key in it.

Common mistakes

  • Swapping the legacy service_role key for a secret key during the move to the new keys, and keeping the old habit of using it in client code.
  • Creating a new secret key but never deleting the exposed one, so the copied key keeps working.
  • Moving the key to a NEXT_PUBLIC_ or VITE_ environment variable, which still ships it to every browser.

How to verify

  1. 1 Re-run the scan and confirm the Supabase secret key finding is gone.
  2. 2 Search the deployed JavaScript for sb_secret_ to confirm no key remains, not just the source files.
  3. 3 Confirm in the Supabase dashboard that the exposed secret key is deleted and only server-side code uses the new one.

Related checks

Ready to see where you stand?

Scan your site and get your Engineering Score with a prioritized roadmap in under a minute, no signup required.

Scan your site

Session expired

Your session has expired for security. Please log in again to continue.