// guide · Supabase · API keys · Lovable · Bolt · Dec 1, 2026
Is it safe to commit your Supabase anon key? (and the key you must never push)
Short answer
- Yes, the anon key and the newer
sb_publishable_key are public by design. Supabase says they are safe in web pages, apps and source code. They are already visible in your site's JavaScript. - They only reach what Row Level Security and table grants allow. RLS is the lock, not the key.
- Never commit or ship the
service_rolekey or ansb_secret_key. They bypass every RLS policy. - Test it: call your tables signed out with only the public key. If real rows come back, fix RLS. If a secret key leaked, create a new one and delete the old one.
Why people keep asking
Lovable, Bolt and v0 apps put the Supabase URL and key right in the frontend, and AI assistants often hardcode them in src/supabase.ts. On Nov 30, 2026 builders on X were asking whether pushing that file to GitHub, or pasting the key into Claude, is a leak. The answer depends entirely on which key it is.
The four Supabase keys
| Key | Looks like | Postgres role | Commit / ship it? |
|---|---|---|---|
| Publishable | sb_publishable_... | anon / authenticated | Yes |
| anon (legacy) | JWT eyJ..., role anon | anon / authenticated | Yes |
| Secret | sb_secret_... | service_role (BYPASSRLS) | Never |
| service_role (legacy) | JWT eyJ..., role service_role | service_role (BYPASSRLS) | Never |
From Supabase's API keys docs: the publishable key is “safe to expose online”, while secret keys “provide full access to your project's data, bypassing Row Level Security”. A request with the public key runs as anon when nobody is signed in and as authenticated when the user has a Supabase Auth session. Supabase is deprecating the legacy anon and service_role keys in early 2027; both systems work side by side until you disable the legacy ones (migration guide).
Which key is in your code?
# Which key is this? Runs locally, sends nothing anywhere.
# New-style keys: the prefix tells you
# sb_publishable_... -> public (browser, mobile, repo: fine)
# sb_secret_... -> SECRET (server only, never in git)
# Legacy keys are JWTs (start with eyJ). Read the role claim:
node -e 'const p=process.argv[1].split(".")[1];console.log(JSON.parse(Buffer.from(p,"base64url")).role)' "<paste key>"
# anon -> public
# service_role -> SECRETTwo long eyJ strings look identical at a glance, which is how service_role keys end up in frontends. Decode before you paste one anywhere.
The real lock: RLS and grants
Because the public key is public, your tables are protected only by Postgres. Supabase's RLS docs describe two checks: grants decide whether a role can run an operation on a table at all, and policies decide which rows it applies to. Once RLS is enabled, nothing is readable with the publishable key until you add policies. A table in public with RLS off can be read and changed by anyone holding your public key, which is everyone who opened your site. Adding policies also doesn't revoke grants, so check both (Securing your API).
The 2-minute signed-out test
# Signed-out test: what can the public key read? Run it per table.
curl -s "https://<project-ref>.supabase.co/rest/v1/profiles?select=*&limit=3" \
-H "apikey: <your anon or sb_publishable_ key>"
# [] -> RLS is on and no row is visible to anon: good
# 401 or 403, code 42501 -> anon has no grant on the table: good
# rows of real data -> anyone on the internet can read this tableUse a table route, not the API root: Supabase notes that GET /rest/v1/ only accepts secret keys, so a publishable key gets 401 there even when tables are open. Run the test for every table that holds user data (profiles, orders, messages, bookings). Then sign in as a second test user and check you can't read the first user's rows: the authenticated role is open to anyone who signs up.
Find secret keys in your repo
# Secret keys anywhere in the repo (current files)
grep -rnE "sb_secret_[A-Za-z0-9_-]{20,}|service_role" --exclude-dir=node_modules .
# ...and in git history (a deleted key is still retrievable)
git log -p --all | grep -nE "sb_secret_[A-Za-z0-9_-]{20,}" | head
# Public env vars that hold a secret get bundled into your JS
grep -rnE "(VITE|NEXT_PUBLIC|REACT_APP|EXPO_PUBLIC)_[A-Z_]*(SERVICE_ROLE|SECRET)" --exclude-dir=node_modules .Supabase's docs say a secret key must never appear in a web page, source code or a shipped app, or travel in a URL. Secret keys return 401 when Supabase sees a browser User-Agent, but “an attacker can still use the key from other tools.” Keep secret keys in server-only env vars:
# .env.local (gitignored; real values live in your host's env settings)
# Safe to expose to the browser:
VITE_SUPABASE_URL=https://<project-ref>.supabase.co
VITE_SUPABASE_PUBLISHABLE_KEY=sb_publishable_...
# Server only. No VITE_ / NEXT_PUBLIC_ prefix, or the bundler ships it:
SUPABASE_SECRET_KEY=sb_secret_...If a secret key leaked
- Fix the cause first: move the code that needs it into a server route or Edge Function, and remove the key from the frontend and the repo.
- Create a new secret key in Settings > API Keys and switch your server code to it.
- Delete the leaked
sb_secret_key. For a leaked legacyservice_rolekey, deactivate the legacy keys (move browser clients to a publishable key first) and revoke the legacy JWT secret. - Removing the key from the latest commit is not enough: it stays in git history and forks. Rotation is what makes it useless.
Full steps, including the Management API version: Rotate a leaked API key.
Prompt to paste into Lovable, Cursor or Claude Code
Audit how this app uses Supabase keys:
1. List every place a Supabase key is used and say which kind it is: anon / sb_publishable_ (public) or service_role / sb_secret_ (secret). Do not print key values.
2. Flag any secret key that is hardcoded, committed (including .env files), in a VITE_/NEXT_PUBLIC_/REACT_APP_/EXPO_PUBLIC_ variable, or used in code that runs in the browser.
3. For each table in the public schema, say whether RLS is enabled in the migrations and what the anon and authenticated roles can select, insert, update and delete.
4. Propose moving every secret-key operation into a server route or Edge Function, and list which keys I need to rotate.
Show the diff before changing anything.Check it automatically
RescueMyRepo's free scan reads your code and migrations without running anything. It flags hardcoded service_role JWTs and sb_secret_ keys (critical, including sb_secret_ keys deleted from the code but still in git history), service-role keys referenced from browser code, secrets in VITE_/NEXT_PUBLIC_ variables, committed .env files and tables without RLS. Public anon and sb_publishable_ keys are left alone.
FAQ
Is it safe to push my Supabase URL and anon key to GitHub?
Yes. Supabase's API keys docs list the publishable key (and its legacy version, the anon key) as safe to expose online, including in web pages, mobile apps, GitHub Actions, CLIs and source code. Anyone can already read it from your site's JavaScript. What protects your data is Row Level Security plus table grants, so the real question is whether every table in an exposed schema has RLS on and correct policies.
Which Supabase keys must never be committed?
The service_role key (a long JWT starting with eyJ whose payload says "role": "service_role") and secret keys that start with sb_secret_. Both map to the service_role Postgres role, which has the BYPASSRLS attribute, so they skip every policy and get full access to your project's data. Also keep your database password and connection string out of git.
How do I tell an anon key from a service_role key?
New keys say it in the prefix: sb_publishable_ is public, sb_secret_ is secret. Legacy keys are both JWTs starting with eyJ; decode the middle part (the payload) and read the role claim: "anon" is the public one, "service_role" is the admin one. The one-liner in this guide does it locally without sending the key anywhere.
Supabase says sb_secret_ keys don't work in a browser. Isn't that enough?
No. Supabase returns 401 when it sees a browser User-Agent on a secret key, but its docs point out that an attacker can still use the key from other tools such as curl or a script. A secret key in your bundle or repo is a full leak: fix the code, then create a new secret key and delete the old one.
My anon key is public. Can someone read my tables with it?
Only what your RLS policies and grants allow for the anon role (signed out) or the authenticated role (signed in with any account). If RLS is off on a table in the public schema, anyone with the anon key can read and change it through the REST API. With RLS on and no policy, the API returns no rows. Test it with the signed-out curl in this guide.
Do I need to switch from anon/service_role to publishable/secret keys?
Supabase's docs say the anon and service_role keys are being deprecated in early 2027 and recommend publishable (sb_publishable_) and secret (sb_secret_) keys. Creating the new keys doesn't revoke the legacy ones; both work until you disable the legacy keys in Settings > API Keys. See Supabase's migration guide.
Does RescueMyRepo check this?
Yes. The free scan flags a hardcoded service_role JWT, a hardcoded sb_secret_ key or one still in git history after you deleted it (added Dec 1, 2026), a service-role key referenced from browser code, secrets in VITE_/NEXT_PUBLIC_ variables, committed .env files, and tables without RLS in your migrations. Anon and sb_publishable_ keys are not flagged, because they are public by design.
Related
- Is your OpenAI or Stripe secret key in your frontend?
- Check that your Supabase data isn't readable without a login
- Supabase October 30, 2026 change: fix “42501 permission denied” without turning off RLS
- Supabase views bypass RLS by default
Sources
- Supabase docs: API keys
- Supabase docs: Row Level Security
- Supabase docs: Securing your API
- Supabase docs: Rotate a leaked API key
- Supabase docs: Migrating to new API keys
Facts per the linked Supabase docs, read Dec 1, 2026.