Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/installcheck
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ else
fi

# Execute the test fixtures
psql -v ON_ERROR_STOP= -f test/fixtures.sql -f lints/0001*.sql -f lints/0002*.sql -f lints/0003*.sql -f lints/0004*.sql -f lints/0005*.sql -f lints/0006*.sql -f lints/0007*.sql -f lints/0008*.sql -f lints/0009*.sql -f lints/0010*.sql -f lints/0011*.sql -f lints/0013*.sql -f lints/0014*.sql -f lints/0015*.sql -f lints/0016*.sql -f lints/0017*.sql -f lints/0018*.sql -f lints/0019*.sql -f lints/0020*.sql -f lints/0021*.sql -f lints/0022*.sql -f lints/0023*.sql -f lints/0024*.sql -f lints/0025*.sql -f lints/0026*.sql -f lints/0027*.sql -f lints/0028*.sql -f lints/0029*.sql -f lints/0030*.sql -f lints/0031*.sql -f lints/0032*.sql -d contrib_regression
psql -v ON_ERROR_STOP= -f test/fixtures.sql -f lints/0001*.sql -f lints/0002*.sql -f lints/0003*.sql -f lints/0004*.sql -f lints/0005*.sql -f lints/0006*.sql -f lints/0007*.sql -f lints/0008*.sql -f lints/0009*.sql -f lints/0010*.sql -f lints/0011*.sql -f lints/0013*.sql -f lints/0014*.sql -f lints/0015*.sql -f lints/0016*.sql -f lints/0017*.sql -f lints/0018*.sql -f lints/0019*.sql -f lints/0020*.sql -f lints/0021*.sql -f lints/0022*.sql -f lints/0023*.sql -f lints/0024*.sql -f lints/0025*.sql -f lints/0026*.sql -f lints/0027*.sql -f lints/0028*.sql -f lints/0029*.sql -f lints/0030*.sql -f lints/0031*.sql -f lints/0032*.sql -f lints/0033*.sql -d contrib_regression

# Run tests
${REGRESS} --use-existing --dbname=contrib_regression --inputdir=${TESTDIR} ${TESTS}
Expand Down
80 changes: 80 additions & 0 deletions docs/0033_default_privileges_expose_new_tables.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@

**Level:** WARN

**Summary:** Default privileges grant every future table to `anon`, `authenticated` or `PUBLIC`.

**Ramification:** Since October 30, 2026, new tables are not exposed to the Data API until you `grant` them. A default-privileges entry like this brings back automatic exposure for every table its owner creates. Nothing leaks because of it today, but the next table created without `enable row level security` can be read (and, with write privileges, changed) with the public anon key as soon as it exists.

---

### Rationale

On October 30, 2026 Supabase stopped exposing new tables in `public` to the Data API by default. Before, default privileges granted `select`, `insert`, `update` and `delete` on every new table to `anon`, `authenticated` and `service_role`, so a table was reachable through PostgREST and pg_graphql the moment it was created, protected or not. After the change, each table needs an explicit `grant`, which keeps access a reviewable, per-table decision.

The first sign of the change is usually a `42501 permission denied for table` error. A common way to make it go away is to put the old behavior back:

```sql
alter default privileges in schema public
grant select, insert, update, delete on tables to anon, authenticated;
```

That silences the error for every future table at once, and with it the safety net the change added: a table created by a migration, the SQL editor, the Management API or an AI tool is exposed before anyone has enabled RLS or written a policy.

The lint reports one row per owner role and schema (or one row for an entry without `in schema`, which applies to every schema). It only looks at table defaults (`on tables`): sequences and functions are out of scope. Entries owned by platform roles (`supabase_*`, `pg_*`) are skipped because the project owner can't change them. Entries that only grant to `service_role` are not reported.

### How to Resolve

**Option 1: Revoke the default privileges and grant per table (recommended)**

Use the owner and schema from the finding:

```sql
alter default privileges for role postgres in schema public
revoke all on tables from anon, authenticated, public;
```

Then grant each table in the migration that creates it, next to its RLS policies, and only the privileges each role needs:

```sql
create table public.notes (
id bigint generated always as identity primary key,
user_id uuid not null default auth.uid(),
body text
);
alter table public.notes enable row level security;

grant select, insert, update, delete on public.notes to authenticated;

create policy "own notes" on public.notes
for all to authenticated
using ((select auth.uid()) = user_id)
with check ((select auth.uid()) = user_id);
```

Revoking default privileges does not change tables that already exist: they keep the grants they have.

**Option 2: Keep the defaults, with a guarantee that RLS is always on**

If you keep the defaults on purpose, make sure every table in the exposed schemas gets RLS when it is created, for example with an event trigger, and watch lints `0013_rls_disabled_in_public` and `0008_rls_enabled_no_policy`. Without that guarantee, keeping the defaults is exactly the exposure the October 30 change removed.

### Example

The quick fix after the first 42501:

```sql
alter default privileges for role postgres in schema public
grant select, insert, update, delete on tables to anon, authenticated;
```

Fix:

```sql
alter default privileges for role postgres in schema public
revoke all on tables from anon, authenticated;

grant select on public.your_table to authenticated;
```

### False Positives

A project that deliberately exposes every new table, and enforces RLS on creation some other way, can treat this finding as accepted. A default that grants only to `service_role` is never reported.
86 changes: 86 additions & 0 deletions lints/0033_default_privileges_expose_new_tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
create view lint."0033_default_privileges_expose_new_tables" as

-- Detects ALTER DEFAULT PRIVILEGES entries that grant table privileges
-- to `anon`, `authenticated` or `PUBLIC` in a schema exposed through
-- the Data API (or in every schema). Since October 30, 2026 new tables
-- are no longer exposed automatically: each one needs an explicit
-- GRANT. A default-privileges entry like this re-creates the old
-- behavior for every table its owner creates from now on, usually
-- added to silence the first 42501 "permission denied for table".
-- Nothing is exposed by it today; the next table created without
-- `enable row level security` is readable (and writable) with the
-- public anon key the moment it exists.
--
-- Default privileges owned by platform roles (supabase_*, pg_*) are
-- skipped: the project owner cannot alter them.
select
'default_privileges_expose_new_tables' as name,
'Default Privileges Expose New Tables' as title,
'WARN' as level,
'EXTERNAL' as facing,
array['SECURITY'] as categories,
'Detects default privileges that grant every future table to the API roles, re-enabling automatic Data API exposure. Revoke them and grant each new table explicitly in the migration that creates it.' as description,
format(
'Default privileges make every table `%s` creates in %s accessible to %s.',
owner_name,
case when schema_name is null then 'any schema' else format('schema `%s`', schema_name) end,
grants
) as detail,
'https://supabase.com/docs/guides/database/database-linter?lint=0033_default_privileges_expose_new_tables' as remediation,
jsonb_build_object(
'owner', owner_name,
'schema', schema_name,
'grants', grants,
'type', 'default_privileges'
) as metadata,
format(
'default_privileges_expose_new_tables_%s_%s',
owner_name,
coalesce(schema_name, '*')
) as cache_key
from
(
select
owner_name,
schema_name,
string_agg(grantee_name || ' (' || privileges || ')', ', ' order by grantee_name) as grants
from
(
select
pg_catalog.pg_get_userbyid(d.defaclrole) as owner_name,
n.nspname as schema_name,
case when a.grantee = 0 then 'PUBLIC' else pg_catalog.pg_get_userbyid(a.grantee) end as grantee_name,
string_agg(a.privilege_type, ', ' order by a.privilege_type) as privileges
from
pg_catalog.pg_default_acl d
left join pg_catalog.pg_namespace n
on n.oid = d.defaclnamespace
cross join lateral pg_catalog.aclexplode(d.defaclacl) a
where
d.defaclobjtype = 'r'
and (
a.grantee = 0
or pg_catalog.pg_get_userbyid(a.grantee) in ('anon', 'authenticated')
)
and (
d.defaclnamespace = 0
or n.nspname = any(array(select trim(unnest(string_to_array(coalesce(current_setting('pgrst.db_schemas', 't'), 'public'), ',')))))
)
and (
n.nspname is null
or n.nspname not in (
'_timescaledb_cache', '_timescaledb_catalog', '_timescaledb_config', '_timescaledb_internal', 'auth', 'cron', 'extensions', 'graphql', 'graphql_public', 'information_schema', 'net', 'pgmq', 'pgroonga', 'pgsodium', 'pgsodium_masks', 'pgtle', 'pgbouncer', 'pg_catalog', 'realtime', 'repack', 'storage', 'supabase_functions', 'supabase_migrations', 'tiger', 'topology', 'vault'
)
)
and pg_catalog.pg_get_userbyid(d.defaclrole) not like 'supabase\_%'
and pg_catalog.pg_get_userbyid(d.defaclrole) not like 'pg\_%'
group by
1, 2, 3
) per_grantee
group by
owner_name,
schema_name
) exposing_defaults
order by
owner_name,
schema_name nulls first;
1 change: 1 addition & 0 deletions mkdocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ nav:
- Autovacuum Disabled: '0030_autovacuum_disabled.md'
- Public Can Execute Dynamic SQL Function: '0031_anon_dynamic_sql_function_executable.md'
- Signed-In Users Can Execute Dynamic SQL Function: '0032_authenticated_dynamic_sql_function_executable.md'
- Default Privileges Expose New Tables: '0033_default_privileges_expose_new_tables.md'

theme:
name: 'material'
Expand Down
88 changes: 87 additions & 1 deletion splinter.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2336,4 +2336,90 @@ from
order by
schema_name,
function_name,
function_args)
function_args)
union all
(
-- Detects ALTER DEFAULT PRIVILEGES entries that grant table privileges
-- to `anon`, `authenticated` or `PUBLIC` in a schema exposed through
-- the Data API (or in every schema). Since October 30, 2026 new tables
-- are no longer exposed automatically: each one needs an explicit
-- GRANT. A default-privileges entry like this re-creates the old
-- behavior for every table its owner creates from now on, usually
-- added to silence the first 42501 "permission denied for table".
-- Nothing is exposed by it today the next table created without
-- `enable row level security` is readable (and writable) with the
-- public anon key the moment it exists.
--
-- Default privileges owned by platform roles (supabase_*, pg_*) are
-- skipped: the project owner cannot alter them.
select
'default_privileges_expose_new_tables' as name,
'Default Privileges Expose New Tables' as title,
'WARN' as level,
'EXTERNAL' as facing,
array['SECURITY'] as categories,
'Detects default privileges that grant every future table to the API roles, re-enabling automatic Data API exposure. Revoke them and grant each new table explicitly in the migration that creates it.' as description,
format(
'Default privileges make every table `%s` creates in %s accessible to %s.',
owner_name,
case when schema_name is null then 'any schema' else format('schema `%s`', schema_name) end,
grants
) as detail,
'https://supabase.com/docs/guides/database/database-linter?lint=0033_default_privileges_expose_new_tables' as remediation,
jsonb_build_object(
'owner', owner_name,
'schema', schema_name,
'grants', grants,
'type', 'default_privileges'
) as metadata,
format(
'default_privileges_expose_new_tables_%s_%s',
owner_name,
coalesce(schema_name, '*')
) as cache_key
from
(
select
owner_name,
schema_name,
string_agg(grantee_name || ' (' || privileges || ')', ', ' order by grantee_name) as grants
from
(
select
pg_catalog.pg_get_userbyid(d.defaclrole) as owner_name,
n.nspname as schema_name,
case when a.grantee = 0 then 'PUBLIC' else pg_catalog.pg_get_userbyid(a.grantee) end as grantee_name,
string_agg(a.privilege_type, ', ' order by a.privilege_type) as privileges
from
pg_catalog.pg_default_acl d
left join pg_catalog.pg_namespace n
on n.oid = d.defaclnamespace
cross join lateral pg_catalog.aclexplode(d.defaclacl) a
where
d.defaclobjtype = 'r'
and (
a.grantee = 0
or pg_catalog.pg_get_userbyid(a.grantee) in ('anon', 'authenticated')
)
and (
d.defaclnamespace = 0
or n.nspname = any(array(select trim(unnest(string_to_array(coalesce(current_setting('pgrst.db_schemas', 't'), 'public'), ',')))))
)
and (
n.nspname is null
or n.nspname not in (
'_timescaledb_cache', '_timescaledb_catalog', '_timescaledb_config', '_timescaledb_internal', 'auth', 'cron', 'extensions', 'graphql', 'graphql_public', 'information_schema', 'net', 'pgmq', 'pgroonga', 'pgsodium', 'pgsodium_masks', 'pgtle', 'pgbouncer', 'pg_catalog', 'realtime', 'repack', 'storage', 'supabase_functions', 'supabase_migrations', 'tiger', 'topology', 'vault'
)
)
and pg_catalog.pg_get_userbyid(d.defaclrole) not like 'supabase\_%'
and pg_catalog.pg_get_userbyid(d.defaclrole) not like 'pg\_%'
group by
1, 2, 3
) per_grantee
group by
owner_name,
schema_name
) exposing_defaults
order by
owner_name,
schema_name nulls first)
Loading