Is my Supabase database public?
Probably not, but the only way to know is to look from outside, the way a stranger would. It takes one request and no tools.
Why this question comes up at all
Supabase serves every table in the public schema over a REST
endpoint, and your anon key ships inside your frontend bundle on purpose. Anyone
can read that key out of your JavaScript in a few seconds. That is not the flaw.
The flaw appears when a table has no Row Level Security. Then the anon key, which everyone has, is enough to read and often write that table. The key was never the secret. The policies are the protection.
Check it in 30 seconds
Open your deployed site, open developer tools, and search the loaded
JavaScript for supabase.co. You will find your project URL and anon
key. Then, from a terminal, ask the database directly:
curl "https://YOUR-PROJECT.supabase.co/rest/v1/YOUR_TABLE?select=*&limit=5" \ -H "apikey: YOUR_ANON_KEY"
Read the answer carefully:
[]means the table exists and nothing was returned to an anonymous caller. That is what you want.- Rows of real data means anyone on the internet can read that table right now.
- A message about permission denied means the role has no privileges on it, which is also fine.
Do the same for writing, which people forget to check:
curl -X POST "https://YOUR-PROJECT.supabase.co/rest/v1/YOUR_TABLE" \
-H "apikey: YOUR_ANON_KEY" -H "Content-Type: application/json" \
-d '{"id":"00000000-0000-0000-0000-000000000000"}'
Anything other than a refusal means a stranger can insert rows into your database.
What the dashboard does and does not tell you
The shield beside a table tells you Row Level Security is enabled. It does not tell you whether the policy restricts anyone. These two tables both show a shield, and one of them is wide open:
-- Protected: a row belongs to the user who owns it create policy "own rows" on public.invoices for all to authenticated using ( (select auth.uid()) = user_id ) with check ( (select auth.uid()) = user_id ); -- Shield on, protection off: this passes for every caller, signed in or not create policy "enable read" on public.invoices for all using ( true );
The second policy is common because it is the fastest way to make an error
message go away. It is worth searching your migrations for using (true)
before you trust any shield.
The other half: privileges
Row Level Security is checked after table privileges, not instead of them. A grant like this hands write access to every anonymous visitor regardless of your policies:
grant all on public.invoices to anon; -- almost never what you want
List what the anonymous role can actually do:
select table_name, privilege_type from information_schema.role_table_grants where grantee = 'anon' and table_schema = 'public' order by table_name;
If you find something open
Turn Row Level Security on before you write the policy. An app that errors is better than a table that leaks, and the error tells you exactly which query needs a policy:
alter table public.invoices enable row level security; alter table public.invoices force row level security; revoke all on public.invoices from anon; grant select, insert, update, delete on public.invoices to authenticated; create policy "own invoices" on public.invoices for all to authenticated using ( (select auth.uid()) = user_id ) with check ( (select auth.uid()) = user_id );
Then check from outside again with the same curl command. Trusting the dashboard instead of the response is how people stay exposed after fixing it.
If a service key was also exposed, rotate it before anything else. Deleting the line does not help, because the old value stays in your git history.
Related
- "new row violates row-level security policy"
- NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY
- RLS Disabled in Public
- Supabase returns an empty array but the rows are there
- Is it safe to expose the Supabase anon key?
- Supabase security scanner
Check your own project
One command. No install, no signup, and it never touches the network. It reads your repository and tells you which tables are reachable and which keys are exposed, with the fix beside each finding.
npx github:humora2504/vibeproof .
Free and MIT licensed. If you want the policies generated for your own schema, and a script that proves an anonymous visitor is refused, there is a $19 Fix Pack. The scanner stays free either way.