Supabase anon key vs service_role key: which one is safe in your app?

By Arif Khan, AIVolve LLC · Updated November 18, 2026

"My AI tool put a Supabase key in my front-end code. Is that a leak?"

Short answer: it depends on which key. The anon key (or the new publishable key, sb_publishable_...) is meant to be public. It's fine in browser code, but it only stays safe if Row Level Security (RLS) is on and correct for every table. The service_role key (or the new secret key, sb_secret_...) skips every RLS policy and can read or change all your data. It must never be in your browser code, your app bundle or your repo. If you find it there, treat it as leaked and rotate it.

Supabase is deprecating the anon and service_role keys by the end of 2026 in favor of publishable and secret keys, so this is a good week to check which ones your app uses.

The four keys in one table

Key Looks like Safe in the browser? What it can reach
Publishable sb_publishable_... Yes Only what your RLS policies allow
anon (legacy) long string starting eyJ Yes Only what your RLS policies allow
Secret sb_secret_... No Everything. It bypasses RLS
service_role (legacy) long string starting eyJ No Everything. It bypasses RLS

A quick way to tell the legacy keys apart: both start with eyJ, so you can't tell anon from service_role by looking. Check which one it is in your Supabase dashboard under Settings > API Keys before you decide it's safe.

Why the anon key being public is normal

Supabase's own rule is to pick the key by where the code runs. Anything you ship to users (web page, mobile app, script) gets the publishable or anon key, because anyone can read it from the page source or the network tab. Anything you control (a server, an Edge Function, a scheduled job) can use the secret key.

The public key isn't what protects your data. Each key maps to a database role, and your RLS policies decide what that role can see:

One more layer sits in front of RLS: table grants. Postgres checks the grant first and only then applies your policies. A missing grant gives a "permission denied" error (code 42501), while a policy that matches no rows just returns an empty result. Since Supabase's Oct 30, 2026 change, new public tables don't get those grants automatically, so see our 42501 guide if a new table suddenly errors.

So "my anon key is visible" is not the problem. "My anon key is visible and a table has RLS off or a policy like using (true)" is.

How to check your app in 10 minutes

  1. Search your live site for secret keys. Open your published app, press F12, then Ctrl+Shift+F (Cmd+Option+F on Mac) to search all loaded files. Search for service_role, sb_secret_ and SERVICE_ROLE. Any match in browser code means the key is public.
  2. Check the long eyJ keys you find. If the only Supabase key in the page is an eyJ... string, compare it with the anon and service_role values in Settings > API Keys. If it matches service_role, it's leaked.
  3. Check your environment variable names. Front-end frameworks ship variables with public prefixes to the browser (for example VITE_ or NEXT_PUBLIC_). A secret key should never be in a variable with one of those prefixes. Supabase's own example keeps the secret key in an unprefixed server-only variable.
  4. Turn on RLS everywhere. In the Supabase dashboard, every table your app reads from the browser should have RLS enabled with policies written for anon and authenticated. Run the Security Advisor in your project and read each finding before dismissing it.
  5. Test with a second account. Sign in as user B and try to open user A's data. If you can, the public key is reaching more than it should, and the fix is in your policies, not the key.

Our 10-minute Supabase RLS check walks through steps 4 and 5 in more detail.

If your service_role or secret key leaked

Supabase's advice is to find out how it leaked and fix that first, or the new key can leak the same way. If someone is already using the leaked key, retire it right away, even if parts of your app stop working until you swap in the new key. Otherwise:

  1. Create a new secret key in Settings > API Keys.
  2. Replace the old key everywhere your server code or Edge Functions use it.
  3. If the leaked key was a legacy service_role key, also switch your browser and mobile code from the legacy anon key to a publishable key. Turning off the legacy keys turns off both of them together.
  4. Confirm every part of your app now uses the new keys.
  5. Retire the old key. A secret key is deleted, which can't be undone. Legacy anon and service_role keys are deactivated together in the same screen. If you find something you missed afterward, move it to a new key rather than turning the legacy keys back on, because that brings the leaked key back too. See Rotate a leaked or compromised API key.

If the leaked key was a legacy service_role key, Supabase also says to revoke the legacy JWT secret by moving to JWT signing keys, because anything that still trusts that secret can accept the leaked key.

Also remove the key from your code history. Deleting it from the latest version of a public repo doesn't remove it from earlier commits.

Moving to publishable and secret keys

A prompt you can give your AI tool:

List every place this project reads a Supabase key. For each one, tell me whether it runs in the browser or on a server, which key it uses (publishable/anon or secret/service_role), and the environment variable name. Flag any secret or service_role key that could end up in browser code. Don't change anything yet.

FAQ

Is it safe to expose the Supabase anon key?+

Yes, the anon key (and the new publishable key) is designed to be public. It only reaches what your Row Level Security policies allow, so it's safe only if RLS is enabled and correct on every table.

What happens if my service_role key is exposed?+

Anyone who has it can read and change all of your project's data, because the service_role key bypasses Row Level Security. Fix how it leaked, create a new secret key and switch your server code to it. Move your browser code from the anon key to a publishable key too, then deactivate the legacy keys, which turns off both anon and service_role.

Do I have to switch to publishable and secret keys?+

Supabase is deprecating the anon and service_role keys by the end of 2026. The new keys work alongside the old ones, so you can switch one part of your app at a time and disable the legacy keys when nothing uses them.

How do I tell the anon key and the service_role key apart?+

Both legacy keys are long strings starting with eyJ. Compare the key with the values in Settings > API Keys in your Supabase dashboard. The new keys are labeled in the key itself: sb_publishable_ or sb_secret_.

Not sure what you found?

If the checks turned up something you don't know how to fix, or you'd like a second pair of eyes, our free App X-ray takes about 2 minutes and needs no code or passwords: you paste a prompt into your AI builder, send us the report, and get a plain-English verdict on what works, what only looks done and your biggest risk. An AIVolve developer reviews every X-ray within 1 business day. Get a free X-ray →

Related: Supabase RLS for AI-built apps: the 10-minute check · Is my Lovable app secure? The 15-minute check before real users · Supabase "permission denied for table" after Oct 30 · Claude Code "don't ask again" leaked your keys? · Free leaked-keys checker · Is the Supabase MCP server safe? · Lovable Cloud vs your own Supabase

Written by Arif Khan, AIVolve LLC. VibeCoderSOS isn't affiliated with Lovable, Bolt or Supabase. Settings names were checked against Supabase's documentation on October 29, 2026, and may change.

Need help?

Start with a free X-ray: 2 minutes, no code or passwords. You'll get a plain-English verdict on what works, what only looks done, and your biggest risk.

Get a free X-ray →