Supabase 42501 "permission denied for table" on new tables
On October 30, 2026, Supabase stopped auto-exposing new public tables on existing projects, so the first table you create now returns 42501 until you grant it. Here's the safe fix, and the two tempting fixes that leak data.
If supabase-js suddenly returns {"code": "42501", "message": "permission denied for table your_table"} for a table you just created, and the same query works in the SQL Editor, you've almost certainly hit Supabase's default-grants change. It isn't an RLS bug, and you shouldn't "fix" it by turning RLS off.
What changed
Per Supabase's changelog, projects used to grant select, insert, update and delete on every new public table to the anon, authenticated and service_role roles automatically. That default is now gone:
- New projects have had the new behavior by default since a gradual rollout starting May 30, 2026.
- Existing projects switched on October 30, 2026.
- Existing tables keep their grants. Only tables created after the change are affected.
- Direct Postgres connections (psql, an ORM or server code with a connection string) aren't affected. The change hits the Data API:
supabase-js, the other client libraries,/rest/v1/and/graphql/v1.
The SQL Editor runs as postgres, which owns the table, so it always works there. That's why the error looks confusing: it only shows up in the app. If your UI swallows errors, users just see an empty list or a button that does nothing.
Why AI-built apps hit this first
Supabase made this change because agents, CLI scripts and AI platforms now create tables with no human reviewing the diff. If Cursor, Claude Code, Lovable or Bolt writes your migrations, expect the first new table you create now to fail until the migration includes grants. The 42501 response carries a hint naming the missing grant, and agents will happily apply it. Check what they apply.
The safe fix: grant, enable RLS, add policies, in one migration
Treat these three steps as a unit and put them in the same migration that creates the table, so local, staging and production match:
-- 1. Grant only what each role needs
grant select, insert, update, delete on public.notes to authenticated;
grant select, insert, update, delete on public.notes to service_role;
-- grant select on public.notes to anon; -- only if logged-out visitors should read it
-- 2. Turn on RLS
alter table public.notes enable row level security;
-- 3. Policies decide which rows
create policy "own rows: read" on public.notes
for select to authenticated using (auth.uid() = user_id);
create policy "own rows: write" on public.notes
for insert to authenticated with check (auth.uid() = user_id);
Grants decide whether a role can touch the table at all. RLS decides which rows it sees. You need both. If the grant is missing, Postgres rejects the query before RLS even runs.
Note that service_role needs a grant too. Server code using the secret key will also get 42501 on new tables without one.
Two fixes that leak data
1. Disabling RLS
Turning RLS off doesn't fix 42501, because the grant is still missing. But it's a common reflex, and if someone later adds the grant, the table is wide open to anyone with your public anon key.
2. Granting every table in bulk
Supabase's own rollback for people who opted in early is grant select, insert, update, delete on all tables in schema public to anon, authenticated, service_role;. It works, and it also re-exposes every table in public, including ones you meant to keep private. On any table without RLS, that publishes every row. If you run it, run the RLS checks below right after, and revoke tables that should stay private: revoke all on table public.your_private_table from anon, authenticated, service_role;
The same goes for restoring the old default privileges with alter default privileges ... grant ... to anon. That brings back exactly the "new table is public on creation" behavior Supabase is removing.
Check your project now
- Security Advisor. Open Database → Security Advisor and clear any RLS or exposure warnings. If it offers remediation SQL, read it before you apply it.
- See current grants for a table:
select grantee, privilege_type from information_schema.role_table_grants where table_schema = 'public' and table_name = 'notes'; - Find tables without RLS in
public:
Every one of those plus anselect relname from pg_class c join pg_namespace n on n.oid = c.relnamespace where n.nspname = 'public' and c.relkind = 'r' and not c.relrowsecurity;anongrant is readable by anyone. - Update your agent's rules so every table-creating migration includes grants, RLS and policies together. Supabase also publishes an agent skill that includes the grants step.
- Test from outside. Call the new table with only the anon key and no session, then as a second user. You should get errors or only your own rows. The Supabase RLS checklist walks through the two-user test.
Paste this rule into your agent (free)
Add it to AGENTS.md, CLAUDE.md or a Cursor rule so Cursor, Claude Code or Codex stop writing this bug in the first place. It ends with a test you can run yourself.
## Supabase grants (error 42501 since Oct 30, 2026)
- Since Oct 30, 2026, new tables in public are not granted to anon, authenticated or service_role automatically. Existing tables keep their grants; a dropped and recreated table loses them.
- Every migration that creates a table does three things in the same file: grants only what each role needs, enables RLS, and adds policies scoped to auth.uid().
grant select, insert, update, delete on public.notes to authenticated;
grant select, insert, update, delete on public.notes to service_role;
alter table public.notes enable row level security;
create policy "own notes" on public.notes for all to authenticated
using ((select auth.uid()) = user_id) with check ((select auth.uid()) = user_id);
- On 42501 / "permission denied for table", add the missing grant for that one table and role. Never fix it by disabling RLS, granting to anon "to make it work", or running grant ... on all tables in schema public.
- Grant to anon only when logged-out visitors really need the table, and say why in a comment.
- Show the migration SQL and wait for an explicit yes before running it.
Verify: select grantee, privilege_type from information_schema.role_table_grants where table_schema = 'public' and table_name = '<table>'; must list only the roles you meant. Then the feature works as a logged-in user, and a request with only the anon key and no session gets an error or [] for private tables.This is one of the free Last Mile Rules. Get all 10 free launch-security rules (keys, RLS, grants, webhooks), each with a verify step.
Prompt your agent safely
A prompt that works: "A new table returns 42501 permission denied. Do not disable RLS and do not grant on all tables. Write one migration that grants only the privileges each role needs on this table, enables RLS, and adds policies scoped to auth.uid(). Show me the SQL before running it." Then rerun the anon-key and two-user tests.
The grants rule above is LM-03 in the free Last Mile Rules, next to the RLS rule (LM-02), each with a verify step. Run your live URL through the free check, or get all 110 rules.
FAQ
Why does my new Supabase table return 42501 permission denied for table?
Since Supabase's default-grants change, new tables in the public schema are no longer granted to the anon, authenticated and service_role roles automatically. Without a grant, the Data API (supabase-js, /rest/v1/, /graphql/v1) rejects the query with 42501 before RLS runs. Add explicit grants for the roles that need the table, enable RLS, and add policies in the same migration.
When does the change hit existing Supabase projects?
October 30, 2026. New projects have had the new behavior by default since a gradual rollout that started May 30, 2026.
Are my existing tables affected?
No. Existing tables keep their grants. Only tables created after the change need explicit grants.
Why does the query work in the SQL Editor but fail in my app?
The SQL Editor runs as postgres, which owns the table, so it always has access. Your app goes through the Data API as anon or authenticated, which now needs an explicit grant.
Should I disable RLS to fix 42501?
No. Disabling RLS doesn't fix 42501 because the grant is still missing, and if a grant is added later the table becomes readable by anyone with your public anon key.
Is granting on all tables in schema public safe?
It works, but it re-exposes every table in public, including ones meant to stay private, and publishes every row of any table without RLS. Grant per table instead, or run RLS checks and revoke private tables right after.
Does service_role need a grant too?
Yes. Server code using the secret key also gets 42501 on new tables without a grant. Direct Postgres connections such as psql or an ORM with a connection string are not affected.
Related guides
- Supabase RLS checklist before launch
If your vibe-coded app talks to Supabase from the browser, Row Level Security is the difference between “users see their own data” and “anyone with the anon key reads the whole table.”
- Supabase anon key exposed: is it a problem?
Short answer: the anon key being visible is normal. Whether that's a problem depends entirely on your Row Level Security. The service_role key is a different story.
- Lovable and Bolt app security before launch
AI app builders get you from idea to working app in an afternoon. They don't decide who should be allowed to read which rows. That part is still yours, and it's checkable without writing code.
Make your coding agent enforce this
The 10 core Last Mile Rules are free: drop-in AGENTS.md, CLAUDE.md and Cursor rules that stop your agent shipping these mistakes, each with a Verify step.
Get launch notes
$ subscribe --launch-notes # new checks, prompts and shipping tips for vibe coders. No spam.