PatchPaste · Guides

Last updated 27 October 2026

Supabase “permission denied for table” (42501): the safe fix

Your new Supabase table suddenly returns 42501 permission denied for table? From 30 October 2026, that is expected. Here is what changed, and how to fix it without making your data public.

Short answer: from 30 October 2026, Supabase stops opening new tables in the public schema to the Data API on existing projects. A new table returns 42501 until you grant access to it. The safe fix is three steps, done together: grant only what each role needs, turn on Row Level Security (RLS), and add policies. Don't fix it by granting everything to anon or turning RLS off.

What changed

Until now, every new table in public got select, insert, update and delete for the anon, authenticated and service_role roles. So a new table could be reached through the Data API (what supabase-js calls) the moment it existed.

Supabase is changing that default (Supabase changelog):

You are affected if your app uses supabase-js or /rest/v1/, and your AI tool or migrations create tables without GRANT statements. That describes most Lovable, Bolt and Cursor apps on Supabase.

What the error looks like

When a grant is missing, the Data API returns:

{
  "code": "42501",
  "message": "permission denied for table your_table",
  "hint": "Grant the required privileges to the current role with: GRANT SELECT ON public.your_table TO anon;"
}

In your app this often shows up as a 401 or 403, a form that won't save, or a new page that stays empty.

Tell grants and RLS apart by the message. Both can use code 42501, so read the text:

The tempting “fix” that makes your data public

When your app breaks, your AI editor will want to make the error go away. Watch for any of these:

-- Don't do this
grant all on public.orders to anon;
alter table public.orders disable row level security;
create policy "allow all" on public.orders for select using (true);

Each one “works”, and each one can let anyone with your public anon key read (or change) the whole table. Your anon key is already in your site's JavaScript, so “anyone” really means anyone.

The safe fix: grant, turn on RLS, add policies

Do all three in the same migration (or the same SQL editor run), so the table is never open without protection. Here is an example for an orders table where signed-in users should only see their own rows:

-- 1. Grant only what each role needs
grant select, insert, update, delete on public.orders to authenticated;
grant select, insert, update, delete on public.orders to service_role;
-- Only grant to anon if logged-out visitors truly need this table.

-- 2. Turn on Row Level Security
alter table public.orders enable row level security;

-- 3. Policies: users can only touch their own rows
create policy "read own orders" on public.orders
  for select to authenticated
  using ((select auth.uid()) = user_id);

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

Need a table that logged-out visitors can read, like a list of blog posts? Grant select to anon, keep RLS on, and write a policy that only returns the rows meant to be public (for example using (published = true)).

Check what a table is granted right now

select grantee, privilege_type
from information_schema.role_table_grants
where table_schema = 'public' and table_name = 'orders';

A prompt you can paste into Lovable, Bolt or Cursor

My Supabase table <table> returns 42501 "permission denied for table".
Fix it safely in ONE migration:
1. GRANT only the privileges each role needs (authenticated and service_role;
   anon only if logged-out users must read it).
2. ALTER TABLE ... ENABLE ROW LEVEL SECURITY.
3. Add policies scoped to auth.uid() = user_id for select, insert, update, delete.
Do NOT grant all to anon, do NOT disable RLS, and do NOT use USING (true).
Show me the SQL before running it.

Also add a line to your project rules (for example .cursorrules, CLAUDE.md or your Lovable knowledge): “Every new table needs grants, RLS and policies in the same migration.”

Then test it like a stranger would

  1. Open your live app in a private window and make sure no private data shows.
  2. Request the table with only your anon key (/rest/v1/orders?select=*&limit=1). Private tables should return no rows or an error.
  3. Sign up as a second user and check you can't see the first user's data.

PatchPaste can do the logged-out part for you. It uses the same public key your site already shares, reads at most one row per table to prove a problem, and stores no row data. More detail is in our Supabase RLS check.

FAQ

Will my existing tables break on 30 October?

No. Supabase says existing tables keep their current grants and stay reachable. Only tables you create after the change reaches your project need an explicit grant.

Why does my new table work in the SQL editor but not in my app?

The SQL editor runs as a privileged role. Your app calls the Data API as anon or authenticated, and those roles have no grant on the new table yet.

Is it OK to just grant everything to anon?

Only if RLS is on with policies that limit what anon can see, and even then, grant only what is needed. A grant with RLS off means anyone with your anon key can use the table.

Is the 42501 error a security problem?

No. It is the safe failure: the table is closed until you open it on purpose. The risk is the quick fix, not the error.

Does this affect apps that don't use supabase-js?

If your app only connects to Postgres directly (with psql, an ORM or a server-side connection string) and not through the Data API, Supabase says the change does not affect you.

Does it change the storage, auth or custom schemas?

No. Supabase says the change only touches default grants in the public schema.

How do I know if my live app has an open table right now?

Run the logged-out test on this page, or scan your app free with PatchPaste. You get a grade and a plain-English list of what is exposed.

Sources: Supabase changelog: tables not exposed to the Data API automatically · Supabase docs: Database API 42501 errors · Supabase docs: Securing your API

Check your live app free

Before you paste any “fix” your AI suggests, see what your live app already shows strangers. Free report; £9 one-off if you want the paste-in fixes.

Free. No login. No code access.

Want to see one first? View a sample report.