Skip to content
View original post on X: scatto
Published

Supabase new tables need explicit GRANTs after Oct 30 cutoff

AISupabase no longer applies default Data API grants to new public tables created after October 30, 2026. AI-generated migrations that only run CREATE TABLE and ENABLE ROW LEVEL SECURITY will fail with SQLSTATE 42501 permission denied, so the author advises adding explicit GRANT statements alongside RLS policies.
scattoVerified on X
@itsscatto
View on X

Since the Oct 30 cutoff, new public tables no longer get default API grants.

AI migrations will fail unless you explicitly run GRANT alongside RLS. https://x.com/i/article/2117622918427332608

How to Configure Cursor and Supabase Migrations After the Oct 30 Data API Cutoff

Updating my .cursorrules file this week after hitting a 42501 permission denied error on a fresh Supabase table saved me hours of blind debugging.

Since the October 30 cutoff, new tables created in the public schema no longer receive default Data API grants. Because every AI coding model was trained on the old behavior, AI-generated SQL migrations will fail out of the box unless you enforce explicit GRANT rules alongside Row Level Security (RLS). Here is the complete breakdown of what changed under the hood, the traps to avoid, and the exact configuration to drop into your agent rules:

1. What Changed on October 30: The End of Automatic public Grants

For years, spinning up a new table in Supabase worked on autopilot because of how default privileges were pre-configured in Postgres.

Whenever you ran CREATE TABLE public.users (...), Supabase automatically applied default GRANTprivileges behind the scenes, giving the anon, authenticated, and service_role Postgres roles full table-level access (SELECT, INSERT, UPDATE, DELETE) over the Data API (PostgREST). Your only job was turning on Row Level Security (ENABLE ROW LEVEL SECURITY) to filter which rows a user could see.

Starting October 30, 2026, Supabase flipped that security model to strict opt-in for all new tables:

- Existing tables keep their current permissions and continue working without interruption.

- New tables created via SQL migrations, the dashboard, or AI prompts receive zero automatic table grants for the Data API roles.

Because Cursor, Claude Code, and Codex were trained on thousands of pre-cutoff repositories, they still generate migrations that only include CREATE TABLE and ENABLE ROW LEVEL SECURITY. The moment your frontend or backend hits that new table, PostgREST throws an immediate HTTP 401/403 with SQLSTATE 42501: permission denied for table.

2. The Two-Gate Architecture: Table Grants vs. Row Level Security

To fix this cleanly without introducing security holes, you need to understand how Postgres and PostgREST evaluate an incoming API request. Every query passes through two separate, sequential gates:

Gate 1: Postgres Table-Level Privileges (GRANT)

Before Postgres even looks at the rows inside your table, it checks the access control list (ACL) of the table itself. It asks a simple binary question: Is the role attached to this JWT (anon, authenticated, or service_role) allowed to execute a SELECT or INSERT on this table object?

If the explicit GRANT is missing, Postgres halts execution at Gate 1 and throws error 42501. Turning off RLS will not help you here, because the request is rejected before RLS even runs.

Gate 2: Row-Level Policies (RLS)

Only after the role passes Gate 1 does Postgres evaluate your CREATE POLICY statements against the individual rows.

This creates a dangerous debugging contrast:

- Missing GRANT (Gate 1 failure): Fails loudly and immediately with 42501 permission denied.

- Enabled RLS with a missing policy (Gate 2 failure): Fails silently by default, returning a 200 OK with an empty array [] instead of an error, which is much easier to miss during testing.

3. The Two Worst Mistakes Builders Are Making Right Now

After I shared my initial fix on X, several sharp engineers pointed out two critical failure modes happening across production codebases right now:

Trap A: The AI "Lazy Fix" (GRANT ALL TO anon)

When a developer hits error 42501 during a coding session and pastes the terminal error back into Cursor or Claude Code, the LLM tries to make the error disappear as fast as possible.

Left unchecked, the AI will often generate:

If your AI runs GRANT ALL TO anon and forgets to bundle strict RLS policies in the exact same migration, it turns a broken table into a wide-open table that anyone on the internet can read or mutate using your public anon key.

Trap B: Assuming service_role Bypasses Grants on Edge Functions

Many builders assume that backend scripts and Supabase Edge Functions using the service_role secret key are immune to permission errors.

In Postgres, the service_role has the BYPASSRLS attribute. As the name implies, BYPASSRLS skips Row Level Security policies (Gate 2), not underlying table grants (Gate 1). If you create a new table for a webhook handler or background worker and forget to run GRANT ALL ON TABLE public.events TO service_role, your Edge Functions will crash with 42501 even when authenticating with the admin key.

4. The Atomic Migration Pattern: Least-Privilege by Default

Never grant permissions globally, and never split table creation, RLS activation, and role grants across separate steps. Every migration generated by your AI assistant must follow an atomic, four-part structure inside the exact same SQL file:

SQL

Notice what happens in Step 4:

1. anon gets nothing by default. Unauthenticated visitors cannot even reach the RLS evaluation layer.

1. authenticated gets only the exact verbs required by the app (SELECT, INSERT), preventing accidental DELETE or UPDATE calls even if a policy is misconfigured later.

1. service_role receives explicit table access so backend Edge Functions and server-side MCP tools never hit a 42501 wall.

(Note: If your table uses SERIAL or BIGSERIAL instead of UUID, you must also grant USAGE, SELECT ON SEQUENCE to the target roles, or INSERT calls will fail with a sequence permission error).

5. Copy-Paste Rule for Your .cursorrules / AGENTS.md / SKILL.md

To stop Cursor, Claude Code, or Windsurf from generating broken legacy migrations, add this exact block to your project's .cursorrules or AGENTS.md file today:

Markdown

## Supabase SQL Migration Rules (Post-Oct 30, 2026 Cutoff)
Whenever generating or modifying a PostgreSQL migration for Supabase in the public schema, you MUST enforce the following 4 rules in the exact same migration file:

  1. No Implicit Grants: Assume all new public tables have zero default privileges for anon, authenticated, and service_role.
  2. Mandatory RLS + Policies: Every CREATE TABLE statement MUST be immediately followed by ALTER TABLE ... ENABLE ROW LEVEL SECURITY; and at least one explicit CREATE POLICY statement in the same migration.
  3. Least-Privilege Role Grants:
  4. NEVER run GRANT ALL ... TO anon. Leave anon with zero privileges unless the user explicitly asks for a public unauthenticated table.
  5. Grant ONLY the specific operations required (SELECT, INSERT, UPDATE, DELETE) to the authenticated role.
  6. Always include GRANT ALL ON TABLE public.<table_name> TO service_role; so Edge Functions and backend workers do not fail with SQLSTATE 42501.
  7. Sequence Permissions: If any column uses SERIAL or BIGSERIAL, explicitly run GRANT USAGE, SELECT ON SEQUENCE <sequence_name> TO authenticated, service_role;.

6. The Pre-Deploy Smoke Test: Querying with the anon Key

Even with strict rules in your .cursorrules file, you should never trust an AI-generated database migration without verifying both gates.

Right after applying a new migration locally or on a staging branch, run a two-line smoke test using only your public anon key before deploying to production:

Bash

If that curl command returns permission denied for table, your Gate 1 protection is locked in. If it returns 200 OK on a table meant for logged-in users, your migration leaked a grant to anon and needs to be revoked before shipping.

The Bottom Line for Builders

Vibe coding with AI assistants works great right up until an infrastructure provider changes a core security default under your feet.

Supabase removing default API grants on the public schema is a massive win for the ecosystem: it kills the most common vulnerability in indie micro-SaaS apps (tables created on the fly and left exposed by mistake). Update your .cursorrules once today, lock in least-privilege GRANT templates alongside RLS, and you won't waste a single minute debugging 42501 errors.

Have you already updated your local agent rules for the new Supabase cutoff, or did you find out the hard way on a fresh migration this week?

Source details

scatto · x.comPublished · added here

Original title: Since the Oct 30 cutoff, new public tables no longer get default API grants.