ShipGuardScan a site

Is the Supabase Anon Key Safe in Browser JavaScript? A Self-Test

Updated 2026-10-26

The anon key (or the newer sb_publishable_ key) in your bundle is not a leak. Supabase designs it to be public, like a project ID with a role attached. What decides your security is what the anon and authenticated roles are allowed to do. This guide shows what that means in practice and how to test your own project.

What anyone with the key can try

Every one of these is limited by your grants and RLS policies, not by keeping the key hidden.

  • Read any table or view in an exposed schema that has RLS off or a permissive select policy.
  • Insert, update or delete rows where a policy allows it, including rows that belong to other users if the policy forgets auth.uid() or with check.
  • Call database functions exposed through the API (RPC), including security definer ones that bypass RLS.
  • Sign up for an account if sign-ups are enabled, then act as authenticated, which many policies treat as trusted.
  • List and download files in storage buckets that are public or have broad policies.

Keys that are never safe in the browser

If any of these appear in client code, treat it as an incident: rotate it and move the work to an Edge Function or server.

  • service_role JWT (its payload has "role":"service_role")
  • sb_secret_ keys
  • Database connection strings or passwords
  • The project's JWT secret

A 10-minute self-test (your own project only)

Use your own app's URL and anon key, from a terminal, not your UI. Try a table that should be private. With no session, it should return an empty array or a permission error. Then sign in as a test user and confirm you only get your own rows.

URL=https://<your-project-ref>.supabase.co
KEY=<your-anon-or-publishable-key>
# should be [] or an error for private tables
curl -s "$URL/rest/v1/profiles?select=*&limit=5" -H "apikey: $KEY" -H "Authorization: Bearer $KEY"
# writes should fail without a matching policy
curl -s -X POST "$URL/rest/v1/profiles" -H "apikey: $KEY" -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" -d '{"display_name":"rls-test"}'

Why scanners stop at the key

Testing someone else's database with a key found in their bundle means accessing their data without permission. ShipGuard never does it: it only reports that a client and table calls are present, so you can run the test above yourself.

Checklist

  • Only the anon / publishable key is in client code
  • RLS enabled on every exposed table, with policies scoped to auth.uid()
  • No policy trusts authenticated alone for per-user data
  • Security definer functions not executable by anon
  • Storage buckets private unless they must be public
  • Self-test with no session and with a second user passes

Copy-paste fix prompt

Check that only the Supabase anon/publishable key is used in this app's client code and that no service_role or sb_secret_ key is present. Then list every table, view and function reachable through the Supabase API with its RLS status, policies and grants for anon and authenticated, and flag anything a signed-out visitor or a different signed-in user could read or change.

FAQ

Should I hide the anon key with environment variables?

An env variable that ends up in the browser bundle is still public. That is fine for the anon key. It is never fine for secret keys.

Is the new publishable key safer than the legacy anon key?

It is easier to rotate and is not a JWT, but it grants the same role. Your RLS policies are still what protect the data.

Does a passive scan prove my data is exposed?

No. It can show the key and the tables your code calls. Only a test against your own project shows whether policies hold.

Check your deployed app in seconds

Free passive scan: leaked keys, Supabase exposure, public config files and headers.

Run a free scan