Supabase anon key vs service_role key: which one is safe in the browser?
The anon key, now called the publishable key, is the one made for the browser: anyone can read it, and it only reaches what row level security allows. The service_role key, now called a secret key, bypasses every row level security policy and must never be in a browser, a shipped app or source control. You can check which one your live app ships in a few minutes.
Saqr (usesaqr.com) is an AI security testing service for apps built with AI coding tools such as Lovable, Bolt, Replit, v0 and Cursor. From $19 a month, cancel any time. Tests only apps you have shown are yours.
By Saqr. Last checked .
What is the difference between the two keys?
| Publishable key (formerly anon) | Secret key (formerly service_role) | |
|---|---|---|
| Looks like | sb_publishable_..., or a long legacy key starting eyJ | sb_secret_..., or a long legacy key starting eyJ |
| Where it belongs | Web pages, mobile apps, source code | Your own server code, such as an API route or an Edge Function |
| What limits it | Row level security, through the anon and authenticated roles | Nothing: it bypasses every policy |
Supabase describes the publishable key as safe to expose online, because "it only reaches what Row Level Security allows". Of a secret key it says: "Never put one in a browser, a shipped application, or source control." (API keys)
The newer keys are short strings. Supabase notes that if a tool, tutorial or AI assistant tells you to copy a long key that begins with eyJ, it was written for the legacy keys. Both legacy keys look alike at a glance, which is why the checks below compare them with the dashboard instead of guessing.
If the publishable key is public, what protects my data?
Row level security. Supabase's guidance is to enable it on every table in an exposed schema, and once it is on, no data is reachable with a publishable key until you create policies (row level security). So the publishable key is exactly as safe as your policies. The step-by-step test of Supabase row level security shows how to confirm they hold.
Supabase also refuses a secret key that is used from a browser: it matches on the User-Agent header and answers 401 Unauthorized (API keys). Treat that as a safety net for mistakes, not as protection. A key in your scripts can still be copied by anyone who opens them.
How do I check which key my app ships?
Six checks on your own project, with a browser and the Supabase dashboard. Do these checks only on an app you own or have written permission to test, with test accounts you created.
Search the live app's scripts for both kinds of key
Open your published app, open the developer tools and use Search to look through every loaded script (Chrome DevTools) for
sb_secret_,service_role,sb_publishable_andeyJ. A publishable key is expected. Anything else needs the next check.If it fails: Rotate an exposed service key and move it to the server
Compare any long key with the dashboard
If you find a long key that starts with
eyJ, open your project's Settings, then API Keys, and compare it with the legacy keys listed there. If it matches the service_role key, treat that key as leaked. Do not paste a key into an online decoder to find out: that only shares it further.If it fails: Rotate an exposed service key and move it to the server
Read every variable with a public prefix
Variables that start with
VITE_(Vite) orNEXT_PUBLIC_(Next.js) are built into the code sent to every visitor. The secret key must live in a variable without those prefixes, read only by server code.If it fails: Move secret keys out of the browser bundle
Check the repository and its history
Search the repository for
sb_secret_andservice_role, including old commits. On a public repository, GitHub's secret scanning looks through the whole history on every branch for free (GitHub Docs).Confirm the publishable key reaches only what you intend
In a private window, signed out, copy one of your app's requests to
/rest/v1/and run it for each table. Data meant for everyone may come back; for everything else, the answer should be an empty list or a permission error.If it fails: Turn on row-level security for every table
Check the server code that holds the secret key
Supabase says secret keys belong in servers that run their own authorization checks, such as Edge Functions and web servers (API keys). Because the key skips row level security, every route that uses it must check who is calling and whether the record is theirs.
If it fails: Stop one user reading another user's records by changing an id
What if the secret key was in the browser?
Rotate it first, because anyone may have copied it while it was public. Supabase's API keys page links to its steps for replacing a leaked secret or service_role key and retiring the compromised one, and says to rotate a leaked key as soon as you fix the cause of the leak. Legacy keys stay valid until you disable them under Settings, API Keys, which is a separate step (API keys).
A safe order: move the work that needed the key to a server route, deploy, create the new secret key, switch the server to it, retire the old key, then search the live scripts again. The guide to what to do about an API key exposed in the frontend covers the same steps for other providers.
Facts worth knowing, with sources
- Supabase describes the publishable key as safe to expose online, because it only reaches what row level security allows. Source
- A Supabase secret key bypasses every row level security policy and must never be put in a browser, a shipped application or source control. Source
- Supabase answers 401 Unauthorized when a secret key is used from a browser, matching on the User-Agent header. Source
- Once row level security is enabled, no data is accessible through the API with a publishable key until you create policies. Source
Questions
Is the Supabase anon key a secret?
No. The anon key, now called the publishable key, is designed to be public. What protects your data is row level security on every table in an exposed schema, so check the policies rather than hiding the key.
Can I use the service_role key in an API route or a server action?
Yes, in server code, as long as that code checks who is calling and what they may do, because the key itself bypasses row level security. Never give it a NEXT_PUBLIC_ or VITE_ prefix, which would send it to the browser.
What do the sb_publishable_ and sb_secret_ prefixes mean?
They mark Supabase's newer keys, which take over from the legacy anon and service_role keys. The newer keys are short strings; the legacy keys are long JWTs that begin with eyJ.
Does deleting the key from my code fix a leak?
No. Anyone may have copied it while it was public. Rotate it first, then remove it from the code, redeploy and confirm it is gone from the live scripts.
Where does Saqr fit?
These checks cover what is on the list, on the pages you think to try. Saqr runs this kind of test on the live app for you, in a real browser and including signed-in pages, and shows the proof for each finding with a fix prompt for your AI coding tool. After you fix something, ask it to recheck. Plans are Starter at $19 a month and Pro at $49 a month, and you can cancel any time.
Every task ends in three PDFs. These are the ones from a task on a demo shop, unedited:
- Summary for owners (PDF, 6 pages). What was found and what to fix first.
- Technical report for developers (PDF, 29 pages). Every finding, with its proof and the steps to fix it.
- AI fix pack (PDF, 10 pages). A ready-to-paste fix prompt for every finding.
No test can promise an app is secure. A task tells you what Saqr found that day, with proof.
Which other guides should I read?
- Is my Lovable app secure?
- Is my Bolt app secure?
- Is my Replit app secure?
- Is my v0 app secure?
- Is my Cursor-built app secure?
- Is my Supabase app secure?
- Is my Firebase app secure?
- How do I check if my vibe-coded app is secure?
- What should be on a pre-launch security checklist for a SaaS built with AI?
- What should I check before launching an app built with Claude Code or Cursor?
- What is the OWASP Top 10, in plain words?
- How do I test my own app for broken access control (IDOR)?
- How do I test Supabase row level security?
- How do I check if a Supabase storage bucket is public?
- How do I check my Firebase security rules?
- My Firebase API key is public. Is that safe?
- I exposed an API key in my frontend. What do I do now?
- How do I add and test login rate limiting in an app built with AI tools?
- Are my session cookies secure, and how do I check them?
- Which security headers should my Next.js or Vite app set?
- Is my CORS configuration safe, and how do I check it?
- Security fix prompts for your AI coding tool
- Saqr, automated scanners and a manual penetration test
- Questions about securing an app built with AI tools
To see what a finished test looks like, open the sample reports.
Sources
The statements above were checked against these pages on 24 November 2026. Products change; follow the links for the current wording.
- Supabase documentation: API keys
- Supabase documentation: Row Level Security
- Vite documentation: Env variables and modes
- Next.js documentation: Environment variables
- Chrome DevTools: Search across all loaded resources
- GitHub Docs: About secret scanning
Saqr is independent and is not affiliated with Supabase, Vite, Next.js or GitHub. Each name is a trademark of its owner.