Is the Supabase anon key safe to expose?

Short answer: yes, the anon key is designed to be in your website's code. Whether that's safe depends entirely on your Row Level Security policies, and on the other key staying secret.

The short answer

Every Supabase app that talks to the database from the browser ships a key to every visitor. That's by design. Supabase's API key documentation describes the publishable key (the older name is the anon key) as safe to put in web pages, mobile apps and source code.

What makes it safe isn't the key. It's the rules behind it. A request made with the public key runs as the anon role in Postgres, or as authenticated once a user signs in, and Row Level Security (RLS) decides which rows that role can read or change. With good policies, the key is harmless. With RLS off on a table, the same key can read that whole table.

Two keys, two very different jobs

The publishable (anon) key

  • Meant for the browser and mobile apps.
  • Gets only what your RLS policies and database permissions allow.
  • Can be copied by anyone who opens your site, so treat it as public from day one.

The secret (service_role) key

  • Meant only for servers: Edge Functions, your backend, scripts you run yourself.
  • Runs as service_role, which skips Row Level Security completely. Supabase's docs say policies never apply to it.
  • Must never be in front-end code, a mobile app or a public repository. If it is, whoever has it can read and change everything.

The two keys can look alike. The older ones are both long JWTs, and you tell them apart by the role inside (decode it at any JWT viewer you trust, or look in your Supabase dashboard). The newer ones start with sb_publishable_ and sb_secret_, which makes the difference obvious.

When the anon key becomes a problem

A table without RLS

If Row Level Security is off on a table in an exposed schema, what the public key can do depends only on the database permissions it has, and for many tables that means reading everything. This is the most common way Supabase data leaks.

A policy that's too broad

using (true) on a read policy means "everyone may read every row". That's right for a public product list and wrong for profiles, orders or messages. A policy that only checks "is someone signed in" isn't much better when anyone can sign up.

Storage and functions

The same key reaches your storage buckets and any database functions you expose. A bucket with a broad policy lets anyone list and download files; a function marked security definer runs with its owner's rights and can get around your policies if the public key may call it.

Sign-up settings

Because sign-up is usually open, "authenticated" often means "anyone with an email address". If email confirmation is off, they don't even need a real one. Policies have to compare the signed-in user's id with the row's owner, not just check that someone is signed in.

How to check your own app

  1. In the Supabase dashboard, open each table and confirm RLS is enabled. Read every policy and ask "who does this let in?"
  2. As a stranger: with only the public key and no login, query each table through the REST API. Anything that comes back is public.
  3. As another user: sign in as a test user A and try to read user B's rows.
  4. Search your built JavaScript (browser developer tools) for service_role and sb_secret_. Neither should be there.

Supabase's RLS guide explains policies in detail, and our RLS explainer walks through working examples.

If the secret key was exposed

Replace it straight away, following Supabase's guide to rotating a leaked key: create a new secret key, update your server code, then retire the old key. Assume your data may have been read or changed, and check your tables and logs. Removing the key from your code isn't enough on its own, because old builds and copies keep it.

What Securick checks

From your public URL, the free scan checks that no secret key ships to the browser:

  • #5 Supabase service key exposed Free
  • #111 Supabase personal access token exposed Free
  • #112 Database connection string with password exposed Free

On a domain you verify, the Deep scan uses the public key your app already ships, the way an attacker would, and reports what it could read. It counts rows and never stores your data:

  • #59 Supabase tables not readable with the public key Deep
  • #60 Supabase storage buckets not listable Deep
  • #147 Database functions not callable by anyone Deep
  • #96 Data isolation between users Deep
  • #97 User files and profiles isolated Deep

Questions

Should I hide the Supabase anon key with environment variables?

Keeping it in an environment variable is tidy, but it still ends up in the code the browser downloads. That's fine: it's designed to be public. Spend the effort on Row Level Security instead.

Can someone use my anon key to run up my Supabase bill?

They can call your API like any visitor can. Protect expensive operations with policies, rate limits and server-side checks rather than by hiding the key.

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

It plays the same role and is just as public. The newer key format makes it easier to tell public and secret keys apart, which helps prevent the dangerous mistake: shipping the secret one.

Check your live app now

Paste your app's address. The free scan runs 46 tests and shows proof for everything it finds.