LeakyVibe

Guides · Updated 2026-10-26

Is the Supabase anon key safe to expose? What it can and can't do

Short answer: Yes, by design. Supabase's docs say the publishable key (sb_publishable_...) and its legacy version, the anon key, are safe to expose in a web page or mobile app. But "safe to expose" only holds if your database is set up for it: anyone who copies the key can do exactly what your table grants and Row Level Security (RLS) policies allow the anon and authenticated roles to do. The key you must never expose is the secret key (sb_secret_...) or the legacy service_role key, because it bypasses RLS completely. So seeing the anon key in your JavaScript is normal; the real question is what that key can read and write.

Does your app have this problem? Free scan, 15 sec, no sign-up

or watch it scan our demo app ▶

The short version: two kinds of Supabase keys

  • Publishable key (sb_publishable_...) or legacy anon key (a long JWT starting with eyJ): low privilege, meant for anything you ship, such as a web page, a mobile app or a CLI. Supabase's docs call it "safe to expose online" (https://supabase.com/docs/guides/api/api-keys).
  • Secret key (sb_secret_...) or legacy service_role key: elevated privilege, full access to your data, bypasses every RLS policy. It belongs only in servers, Edge Functions and cron jobs that you control.
  • Supabase is deprecating the legacy anon and service_role keys by the end of 2026 in favor of publishable and secret keys. Creating the new keys doesn't revoke the old ones; they stay valid until you disable them in Settings > API Keys.

Supabase's own analogy: the publishable key is taped to the front door and only opens the lobby; the secret key is the master key and stays in your pocket. Apps built with Lovable, Bolt or v0 usually ship the public one in a variable like VITE_SUPABASE_PUBLISHABLE_KEY, VITE_SUPABASE_ANON_KEY or NEXT_PUBLIC_SUPABASE_ANON_KEY. Finding it in your JavaScript is expected, not a leak.

Why a public key doesn't mean public data

Every Supabase key maps to a Postgres role, and that role is what your database rules check. A request with the publishable or anon key and no logged-in user runs as the anon role. The same key plus a signed-in user's token runs as authenticated. The secret key runs as service_role, which has the BYPASSRLS attribute, so policies never apply to it (https://supabase.com/docs/guides/api/api-keys).

Postgres checks table grants first and RLS second. So for a table in an exposed schema (usually public), what the anon key can do depends on two things: whether the anon role has a GRANT on the table, and whether RLS is on with policies that limit rows. Supabase's docs warn that a table with RLS off can be read and written by any role that has a grant on it (https://supabase.com/docs/guides/database/postgres/row-level-security). That's the real risk in AI-built apps: not the key being visible, but a table that answers to it.

What someone can do with your anon key

Assume a stranger has copied it from your site. They can call your project directly with curl or a script, outside your app's screens, and do whatever your rules allow:

  • Read, insert, update or delete rows in any exposed table where the anon role has a grant and RLS is off, or where a policy allows it (for example using (true)).
  • Sign up for an account, unless you turned off "Allow new users to sign up" in Auth settings. After that they act as authenticated, so any policy that only checks "is logged in" lets them in too.
  • Call database functions through rpc() if anon or authenticated can execute them. A SECURITY DEFINER function runs with its owner's rights and usually skips RLS.
  • Read through views. A view usually runs as its owner (often postgres) and skips the RLS of the tables behind it, unless it's created with security_invoker = true (Postgres 15+).
  • Download files from public Storage buckets and anything that Storage policies allow, and listen to Realtime channels that aren't private.

Hiding or obfuscating the key doesn't help. Supabase's docs list what publishable keys don't protect against, including reverse engineering and the browser's Network inspector. Your rules have to be right on their own.

When it is a leak: the secret / service_role key

If sb_secret_ or a JWT whose payload says "role": "service_role" shows up in your frontend code, your git repo or your live JavaScript, treat it as an incident. That key skips every policy and can read, change or delete everything.

How to check what your anon key can reach (15 minutes)

  1. Open your Supabase dashboard > Advisors > Security Advisor. Fix errors first: tables with RLS disabled, views that bypass RLS, and similar findings.
  2. In Table Editor or the SQL editor, confirm RLS is on for every table in public, and read each policy in plain words: who (to anon / to authenticated) can do what (select, insert, update, delete) on which rows.
  3. Search your migrations and policies for using (true) and with check (true) on tables that hold private data.
  4. Test from outside, only on your own project: open your site in a private window, logged out, and watch DevTools > Network for responses that contain other people's data.
  5. Make two test accounts. Logged in as B, try to load, edit and delete rows that belong to A by changing ids in the URL or the request. If it works, the policy isn't scoped to the owner.
  6. Search your live JavaScript (DevTools > Sources) for sb_secret_ and service_role. Only the publishable or anon key should be there.

A quick request with only the public key, against one of your own tables (it should return no private rows):

curl "https://YOUR-PROJECT.supabase.co/rest/v1/YOUR_TABLE?select=*&limit=1" \
  -H "apikey: YOUR_PUBLISHABLE_OR_ANON_KEY"

How to lock it down

  • Turn RLS on for every table in an exposed schema, then add one policy per operation that names the role and scopes rows to the owner, for example using (auth.uid() = user_id), plus with check (auth.uid() = user_id) for inserts and updates.
  • Revoke grants anon doesn't need. If logged-out visitors should never touch a table, remove the anon grant instead of relying on a policy alone.
  • Turn off public sign-ups if your app is invite-only, and don't base roles on user_metadata (users can edit it). Use app_metadata or a table only your server writes.
  • Create views with security_invoker = true, and revoke execute on SECURITY DEFINER functions from anon if they don't need it.
  • From October 30, 2026, new tables in public aren't reachable from the Data API until you GRANT access. When you add the grant, add RLS and policies at the same time: https://leakyvibe.com/guides/supabase-october-30-data-api-change.

A prompt for Lovable, Bolt or Cursor

Check how this app uses Supabase keys and rules. (1) List every place a Supabase key is used. Only the publishable/anon key may appear in frontend code or in VITE_ / NEXT_PUBLIC_ variables; any secret or service_role key must move to a server function or Edge Function secret, and tell me to rotate it. (2) For every table, view and function the anon key can reach, show whether RLS is on and each policy in plain English: which role can select, insert, update and delete which rows. Replace any using (true) or authenticated-only policy on private data with an owner-scoped one, and revoke anon grants that aren't needed. (3) Make views security_invoker and remove anon execute from SECURITY DEFINER functions that don't need it. Don't print key values. List what you changed.

Short checklist

  • Only the publishable/anon key is in the browser; no sb_secret_ or service_role anywhere public.
  • Security Advisor shows no errors.
  • RLS on for every exposed table, owner-scoped policies, no using (true) on private data.
  • Logged-out and second-account tests show only what they should.
  • Any secret key that was ever public has been rotated.

Want a quick outside check? The free LeakyVibe scan above reads your public pages and same-origin JavaScript, read-only, in about 15 seconds. It flags a Supabase service_role key and other secret-looking keys in your JavaScript (the public anon key alone is not flagged), and Supabase tables that answer to your public key. It's a first check, not a full audit: it can't see your policies, your code or data behind a login. Sources: https://supabase.com/docs/guides/api/api-keys, https://supabase.com/docs/guides/database/postgres/row-level-security, https://supabase.com/docs/guides/api/securing-your-api.

Check your app for this now

Free scan · about 15 seconds · no sign-up

Passive, read-only checks. Only scan apps you own or have permission to test.