Skip to main content
All posts

Is the Supabase anon key safe to expose?

What the Supabase anon key is for, why it can sit in your frontend, and how Row Level Security decides who sees your data. Includes a no-code check.

6 min readSupabaseSecurityRow Level Security

The anon key is meant to be public. Supabase's docs list it as a low-privilege key that can sit in a website or app. The key is not what limits the damage. Row Level Security is: a table without it can be read by anyone holding the key, and a loose policy is almost as open.

What is the Supabase anon key?

It is the public key a Supabase app uses to reach its database from a browser or phone. Supabase's API keys page calls it a "legacy" key: a JWT that starts with eyJ, low privilege, mapped to the Postgres roles anon (not signed in) and authenticated (signed in). The newer publishable key (sb_publishable_...) replaces it, and the docs describe it as fine to expose online. Supabase also says it is deprecating the anon and service_role keys by the end of 2026, and that legacy keys stay valid until you disable them.

Why is a public key not a problem on its own?

The key only says who is asking. What that asker may see is decided by Row Level Security (RLS), rules that run inside the database. Supabase puts it this way: "Once RLS is enabled, no data is accessible through the API when using a publishable key, until you create policies." (Row Level Security docs) The setup it describes has RLS on for every table reachable through the API, plus one policy per action that limits rows to their owner.

When does a public anon key become a problem?

Four situations come up again and again.

  1. RLS is off on a table. Supabase's own Security Advisor flags this as lint 0013, "Table publicly accessible", at level ERROR: "Anyone with your project URL can read, edit, and delete all data in this table because Row-Level Security is not enabled." (Database Advisors)
  2. RLS is on, but the policy lets everyone in. A policy that says true for the anon role is open by another route.
  3. A view sits on top of a table that has RLS. Views bypass RLS by default because they are usually created with the postgres user. On Postgres 15 and above, security_invoker = true makes a view obey the table's policies. (Row Level Security docs)
  4. The wrong key was shipped. A secret key (or the legacy service_role key) bypasses every RLS policy. Supabase: "Never use a secret key in the browser or expose it to customers." (API keys, Row Level Security) See which API keys belong in a website.

Supabase is also changing the platform default so that new tables are no longer exposed through the Data API automatically: "exposure becomes opt-in." The docs say this applies only to new objects, that existing tables keep their grants and stay reachable, and that defaults differ between projects depending on when the project was created and its Data API settings. The page checked on 2026-11-20 gives no date. Don't rely on it. Check your tables. (Securing your API)

Real cases

How can I check without writing code?

  1. Run the Security Advisor. In the Supabase dashboard open Advisors, then Security Advisor (https://supabase.com/dashboard/project/_/advisors/security). Any "Table publicly accessible" entry is the first thing to fix. (Database Advisors)
  2. Check which key your app ships. Go to Settings, then API Keys, and compare the key in your site's code with the list there. If it is the service_role or secret key, rotate it before anything else.
  3. Visit your own app signed out. Open it in a private window, open the browser's DevTools Network tab, type rest/v1 in the filter, reload, and click the responses. If you can see other people's names or emails without logging in, a table is too open.
  4. Do the two-account test. Sign up two test users. As user A, create a record. As user B, try to open, change or delete it. If B succeeds, the policy checks "signed in" but not "owner".

This check will not show tables the page never requests, storage buckets, or database functions. Supabase notes that RLS does not apply to functions, so you limit execute on them separately. (Securing your API)

For developers: the queries

Run these in the SQL Editor of your own project. They read catalog tables only.

Which public tables have RLS off:

sql
select schemaname, tablename, rowsecurity
from pg_tables
where schemaname = 'public'
order by rowsecurity, tablename;

Every policy, to read by eye:

sql
select tablename, policyname, cmd, roles, qual, with_check
from pg_policies
where schemaname = 'public'
order by tablename, cmd;

Policies that allow everything:

sql
select tablename, policyname, cmd, roles
from pg_policies
where schemaname = 'public'
  and (qual = 'true' or with_check = 'true');

Tables with RLS on and no policy at all (the API returns nothing for them, which is why an app suddenly shows empty lists):

sql
select c.relname as table_name
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public'
  and c.relkind = 'r'
  and c.relrowsecurity
  and not exists (
    select 1 from pg_policies p
    where p.schemaname = 'public' and p.tablename = c.relname
  );

What the anon role can touch at all:

sql
select table_name, privilege_type
from information_schema.role_table_grants
where table_schema = 'public' and grantee = 'anon'
order by table_name, privilege_type;

A starting policy for a table with a user_id column. Wrapping auth.uid() in a select lets Postgres cache the result per statement, as the Supabase docs recommend:

sql
alter table public.notes enable row level security;

create policy "owners read own notes" on public.notes
  for select to authenticated
  using ((select auth.uid()) = user_id);

create policy "owners add own notes" on public.notes
  for insert to authenticated
  with check ((select auth.uid()) = user_id);

create policy "owners change own notes" on public.notes
  for update to authenticated
  using ((select auth.uid()) = user_id)
  with check ((select auth.uid()) = user_id);

create policy "owners delete own notes" on public.notes
  for delete to authenticated
  using ((select auth.uid()) = user_id);

An outside test of your own project with only the public key (replace the placeholders; the apikey header is mandatory per the docs):

bash
curl -s "https://<project-ref>.supabase.co/rest/v1/notes?select=*&limit=5" \
  -H "apikey: <ANON_OR_PUBLISHABLE_KEY>"

An empty list [] is the result you want for a table that should be private. Rows mean the table is open to anyone with that key. Run this only against projects you own.

Create views with with (security_invoker = true) on Postgres 15 and above. (Row Level Security docs)

To see which legacy key you hold, decode the middle section of the JWT and read its role claim: anon is the public one, service_role is not. Do it locally, and never paste a secret key into an online decoder.

ShipSafe reads a GitHub repo for issues like these and reports them in plain English, with the file, the line and a list of what it could not check. Plans are on the pricing page, and the scanner lives at ship-safe.co.

Sources

  1. Supabase docs, API keys: https://supabase.com/docs/guides/api/api-keys (checked 2026-11-20)
  2. Supabase docs, Row Level Security: https://supabase.com/docs/guides/database/postgres/row-level-security (checked 2026-11-20)
  3. Supabase docs, Securing your API: https://supabase.com/docs/guides/api/securing-your-api (checked 2026-11-20)
  4. Supabase docs, Database Advisors, lint 0013 "Table publicly accessible": https://supabase.com/docs/guides/database/database-advisors?lint=0013_rls_disabled_in_public (checked 2026-11-20)
  5. Wiz, "Exposed Moltbook database reveals millions of API keys": https://www.wiz.io/blog/exposed-moltbook-database-reveals-millions-of-api-keys (published about 2026-02-02; checked 2026-11-20)
  6. UpGuard Labs, "Everything, everywhere: systemic data exposure in Supabase apps": https://www.upguard.com/labs/research/everything-everywhere-systemic-data-exposure-in-supabase-apps (published 2026-09-23; checked 2026-11-20)

Questions and answers

Can someone hack my database with my Supabase anon key?
Not with the key alone, if Row Level Security is on for every table and the policies check ownership. The key only identifies your project and the anon role. If a table has no RLS, or a policy says true, anyone holding the key can read it, and sometimes change it. That is the gap researchers found in the Moltbook case. Start with the Security Advisor and the policy list.
Is the Supabase anon key the same as the service_role key?
No, though they look alike: in Supabase's legacy format both start with eyJ. The anon key maps to the low-privilege anon and authenticated roles. The service_role key bypasses Row Level Security and belongs only on a server. Compare the key in your site's code with the entries under Settings, API Keys. If it is service_role, rotate it now.
Is the Supabase publishable key the same as the anon key?
It is the newer replacement. Supabase's docs list both as low privilege and meant to be exposed online, mapped to the anon and authenticated roles. The publishable key starts with sb_publishable_ and is a short string, not a JWT. Supabase says it is deprecating the anon and service_role keys by the end of 2026, and legacy keys stay valid until you disable them.
I turned on RLS and my app now shows no data. What did I do wrong?
Nothing is broken. Supabase states that once RLS is enabled, no data is accessible through the API with a publishable key until you create policies. Add a select policy that limits rows to their owner, then insert, update and delete policies as the app needs. Don't fix the empty screen with a policy that says true, because that reopens the table to everyone.
Does RLS cover my views, storage and functions?
Not automatically. Supabase notes that views bypass RLS by default because they are usually created by the postgres user, and that RLS does not apply to functions, so you limit execute on those separately. On Postgres 15 and above you can set security_invoker on a view so it follows the table's policies. Storage buckets have their own policies.

You just read what AI builders ship. Now check yours.

Paste your GitHub URL. 2 minutes. You get the findings in plain English, and the report says what it could not check. Free, no card.

Scan My App Free