AleannLab

Supabase "permission denied for table" (42501) on a New Table: What Changed and the Safe Fix

AleannLab team3 min read

Since October 30, 2026, a new table in the public schema of a Supabase project is not reachable through the Data API until you grant access to it. Your client gets error 42501, "permission denied for table". The fix is a GRANT per table, per role, with only the operations that role needs, plus Row Level Security. Do not paste grant all on all tables to make the error go away.

On this page
  1. What changed
  2. How to recognise it
  3. The safe fix
  4. The fix to avoid
  5. Check what is exposed today
  6. Make it stick

If your app worked last month and a table you added this week returns nothing but errors, this is the most likely reason. AI coding tools trained on older Supabase projects still generate migrations without grants, so we expect to see this one for a while.

What changed

Supabase used to grant select, insert, update and delete on every new public table to three roles: anon, authenticated and service_role. A table was reachable from supabase-js the moment it existed, and RLS was the only gate.

Supabase announced the new behaviour on April 28, 2026. It became the default for new projects from May 30 and was applied to all existing projects on October 30. Now:

  • New tables in public get no automatic grants.
  • Tables that already existed keep the grants they had.
  • RLS works exactly as before.
  • Direct Postgres connections are not affected.

So there are two gates now. A grant decides whether a role may touch the table at all. RLS decides which rows.

How to recognise it

The response from the Data API looks like this:

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

One thing confuses people: the same code 42501 also appears when an insert violates an RLS policy. Read the message. "permission denied for table" is a missing grant. "new row violates row-level security policy" is a policy problem and a grant will not help.

The safe fix

Decide who needs what, then write it down in a migration:

SQL
create table public.invoices (
  id uuid primary key default gen_random_uuid(),
  user_id uuid not null references auth.users (id),
  amount_cents integer not null,
  created_at timestamptz not null default now()
);

alter table public.invoices enable row level security;

-- logged-in users work with their own rows
grant select, insert, update on public.invoices to authenticated;

-- server code with the secret key
grant select, insert, update, delete on public.invoices to service_role;

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

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

Notice what is missing: nothing is granted to anon. Visitors who are not logged in have no reason to read invoices, so the role gets no access at all. Before the change, a table like this was one bad policy away from being public. Now the grant has to be wrong too.

If the table uses a serial column, inserts also need grant usage on sequence ... to authenticated. Identity columns and gen_random_uuid() do not.

The fix to avoid

Search results and AI assistants will offer this:

SQL
grant all on all tables in schema public to anon, authenticated;

The error disappears. So does the protection Supabase just gave you. Every table, including ones that had no business being reachable from a browser, is back to "RLS is the only gate", and all includes truncate. If one of those tables has RLS off, it is public.

The second tempting fix is restoring the old default privileges for the whole schema. It works, and it is a decision to make on purpose, not by copying a snippet.

Check what is exposed today

Existing tables kept their old grants, so the change did not clean up anything. This query shows what the browser-facing roles can do:

SQL
select table_name, grantee,
       string_agg(privilege_type, ', ' order by privilege_type) as privileges
from information_schema.role_table_grants
where table_schema = 'public'
  and grantee in ('anon', 'authenticated')
group by table_name, grantee
order by table_name, grantee;

Go through the list and ask one question per row: does this role need this? Internal tables (job queues, audit logs, webhook events, admin settings) usually should not appear for anon at all:

SQL
revoke all on table public.webhook_events from anon, authenticated;

The Supabase Security Advisor and the exposure badge in the Table Editor show the same information per table.

Make it stick

  • Put grants next to create table in the same migration, so local, preview and production behave the same.
  • Add a line to your agent's rules file (CLAUDE.md, .cursorrules, AGENTS.md): "Every new table needs RLS, policies, and explicit grants. Never grant to anon unless the data is public."
  • Run the two-account test from our post on Supabase RLS mistakes after each schema change.

Grants and RLS belong to check 2 in our security checklist for vibe-coded apps. If you want someone to go through your tables, grants and policies and fix what they find, that is our app rescue and security audit.

All articles →

Ready to discuss your project with us?

idea
*
*
*
I'm interested in...
Web Development
App Development
UX/UI Design
DevOps
Artificial Intelligence And Machine Learning
QA Testing
Mobile Development
Consultation
OutSource
Project budget (USD)
≤ $5K
$10K-$20K
$30K-$40K
$50K-$60K
>$100K
Upload file