Supabase "permission denied for table" (42501) after Oct 30: the safe fix
Created a new Supabase table and now your app gets 42501 "permission denied for table"? That's Supabase's new default, not a bug. The fix is a small, specific GRANT. The dangerous "fix" your AI tool might suggest is a bulk GRANT ALL or turning off Row Level Security. Here's the safe way.
anon, authenticated and service_role roles automatic access to new tables in the public schema. It became the default for new projects on May 30, 2026 and applies to all existing projects from October 30, 2026. Existing tables keep their current grants. New tables need an explicit GRANT before supabase-js, REST (/rest/v1) or GraphQL can see them. RLS works the same as before. Apps that only use a direct Postgres connection aren't affected.The error looks like this. Supabase added the hint so you (or your AI agent) can see which role is missing which privilege:
{
"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;"
}
Grants and RLS are two separate locks. A grant decides whether a role can touch the table at all. Row Level Security decides which rows it can see or change. You need both on every table your app reads from the browser. Policies without a grant still return 42501, and a grant without RLS makes every row public.
Step 1: Read the error (table + role)
The message names the table, and the hint names the role that made the request. Be careful here: if you tested while logged out, the hint says TO anon even if only signed-in users should read that table. Don't paste the hint blindly. Decide first.
To see which tables each API role can reach and whether RLS is on, run this in the SQL Editor:
select c.relname as table_name,
c.relrowsecurity as rls_on,
has_table_privilege('anon', c.oid, 'select') as anon_select,
has_table_privilege('authenticated', c.oid, 'select') as auth_select,
has_table_privilege('authenticated', c.oid, 'insert') as auth_insert
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public' and c.relkind in ('r','p','v','m')
order by 1;
Any row with anon_select = true and rls_on = false is readable by anyone who has your public key. Fix those first.
Step 2: Decide who should reach the table
Most tables in a vibe-coded app fit one of three patterns:
- Private, per user (notes, orders, profiles): signed-in users only, and only their own rows. Grant to
authenticated, notanon. - Public read (published posts, a product catalogue): anyone may read, nobody may write from the browser. Grant
selecttoanonandauthenticated. - Server only (payments, audit logs, job queues): no browser access at all. Grant to
service_roleonly, and only if your server code uses the Data API.
Step 3: Grant only those privileges
Private, per-user table
-- signed-in users only; no anon grant at all
grant select, insert, update, delete on table public.notes to authenticated;
Only grant the actions the app actually does. If the app never deletes notes, leave out delete. A missing write grant just returns another 42501 with a hint, which is easy to fix later.
Public read-only table
grant select on table public.posts to anon, authenticated;
Server-only table
-- only if your backend or edge functions use the service_role key with the Data API
grant select, insert, update, delete on table public.payments to service_role;
Serial ids and views
A serial id column uses a sequence, and inserts fail with "permission denied for sequence" until you grant it. Identity and uuid keys don't need this:
grant usage, select on sequence public.notes_id_seq to authenticated;
A new view needs its own grant. Create it with security_invoker so the table's RLS still applies (Postgres 15+). A plain view runs with its owner's rights and skips RLS:
create view public.my_notes with (security_invoker = true) as
select id, body from public.notes;
grant select on public.my_notes to authenticated;
Step 4: Keep RLS on with real policies
A grant lets the role in the door. RLS policies decide which rows it sees. For the per-user table:
alter table public.notes enable row level security;
create policy "read own notes" on public.notes
for select to authenticated
using ((select auth.uid()) = user_id);
create policy "insert own notes" on public.notes
for insert to authenticated
with check ((select auth.uid()) = user_id);
create policy "update own notes" on public.notes
for update to authenticated
using ((select auth.uid()) = user_id)
with check ((select auth.uid()) = user_id);
create policy "delete own notes" on public.notes
for delete to authenticated
using ((select auth.uid()) = user_id);
For the public read table, a policy like for select to anon, authenticated using (published = true) keeps drafts hidden. For server-only tables, enable RLS and add no policies for anon or authenticated (service_role bypasses RLS). More detail in how to check Row Level Security.
What not to do
-- ❌ exposes every table in public to anyone with your public key
grant all on all tables in schema public to anon;
-- ❌ makes every row of the table public to any role that has a grant
alter table public.notes disable row level security;
-- ❌ brings back "every new table is exposed automatically"
alter default privileges in schema public grant all on tables to anon;
-- ❌ a policy that lets everyone see everything
create policy "allow all" on public.notes using (true);
Already ran a bulk grant? Take it back per table for anything that shouldn't be public:
revoke all on table public.payments from anon, authenticated;
Step 5: Test while logged out
This is the test that matters, because it's exactly what a stranger can do with the public key from your website. Use your project URL and your public anon or publishable key (never the service_role or secret key):
# read: a private table must return [] or a 401/42501 error, never real rows
curl -s "https://YOUR-PROJECT.supabase.co/rest/v1/notes?select=*&limit=5" \
-H "apikey: YOUR_PUBLIC_ANON_KEY"
# write: this must fail for anon
curl -s -X POST "https://YOUR-PROJECT.supabase.co/rest/v1/notes" \
-H "apikey: YOUR_PUBLIC_ANON_KEY" \
-H "Content-Type: application/json" \
-d '{"body":"test from a logged-out stranger"}'
Then sign in as a test user in your app and check that you can only see your own rows. A public read table should return rows to the first command, but the write must still fail.
Step 6: Put grants in your migrations
Treat these as one unit in the same migration that creates the table: create table → grant → enable RLS → policies. Then every new environment, branch or restore gets the same access. Watch out for migrations that drop and re-create a table: the new table starts with no grants. Supabase's Security Advisor and the Data API settings in the dashboard also show which tables are exposed.
Copy-paste prompt for your AI coding tool
Paste this into Cursor, Claude, Lovable, Bolt or whichever AI built your app:
My Supabase app returns error 42501 "permission denied for table" because, since Oct 30, 2026, new tables in the public schema need explicit GRANTs. Do NOT use "grant all on all tables", do NOT disable Row Level Security, do NOT change default privileges, and do NOT use policies with using (true) on private data. For each table my app uses: 1) tell me which roles (anon, authenticated, service_role) need which actions based on how the code uses it, 2) write one migration per table with only those GRANTs (plus sequence grants for serial ids), alter table ... enable row level security, and policies that limit rows (e.g. auth.uid() = user_id), 3) create any views with security_invoker = true, 4) give me curl commands using only the public anon key to prove a logged-out user can't read private rows or write anything. Explain each grant and policy in plain English. Don't print any secret keys.
Check your Supabase app in about a minute
Paste a public GitHub repo into KeySnare for a free grade and your top 3 issues, including tables created without RLS, the service_role key in browser code and hardcoded keys, each with a copy-paste AI fix prompt.
Run a free scan →FAQ
Why did my new Supabase table start returning 42501?
Supabase stopped exposing new tables in the public schema to the Data API by default. New projects got this on May 30, 2026 and existing projects on October 30, 2026. A new table now needs an explicit GRANT before supabase-js, REST or GraphQL can reach it, so the request fails with 42501 "permission denied for table" until you add one.
Are my existing tables affected?
No. According to Supabase, tables that existed before the change keep their current grants and stay reachable. The change hits tables you create afterwards, including tables recreated by a migration that drops and re-creates them, or by restoring a dump without its privileges.
Can I just run GRANT ALL ON ALL TABLES to fix it?
Don't. A bulk grant gives the anon role (anyone holding your public key) access to every table in public, including private tables and any table with Row Level Security turned off. Grant only the privileges each role needs, table by table.
Should I disable RLS to make the error go away?
No. RLS is not what causes 42501. Grants decide whether a role can touch a table at all, and RLS decides which rows it can see. Disabling RLS on a table that anon can reach makes every row public.
The error hint says GRANT SELECT ... TO anon. Should I run it as-is?
Only if logged-out visitors really should read that table. The hint names the role that made the failing request, so if you tested while logged out it will say anon even when only signed-in users should have access. For user data, grant to authenticated instead and keep RLS policies on.
Does this affect direct Postgres connections or the service_role key?
Apps that talk to Postgres directly (psql, an ORM or a server with a connection string) aren't affected. The service_role key does go through the Data API, so if your server or edge functions use it on a new table, grant that table to service_role too.
Does KeySnare check Supabase grants?
Not yet. The free scan reads the SQL migrations in your repo and flags tables created without Row Level Security turned on, and it flags the service_role key in browser code. It doesn't connect to your database or read dashboard settings, so also run the logged-out curl test in this guide.