From 1e7d0327ccebddb38a7753fbb6e6294029ac87ee Mon Sep 17 00:00:00 2001 From: bchanot Date: Thu, 8 Oct 2026 22:47:20 +0200 Subject: [PATCH] fix(supabase): no USAGE on schema private for anon; pin it and RPC EXECUTE in pgTAP --- supabase/migrations/20261008100000_foundation.sql | 3 ++- supabase/tests/001_schema.sql | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/supabase/migrations/20261008100000_foundation.sql b/supabase/migrations/20261008100000_foundation.sql index 62dabfa3..5941f296 100644 --- a/supabase/migrations/20261008100000_foundation.sql +++ b/supabase/migrations/20261008100000_foundation.sql @@ -15,7 +15,8 @@ revoke all on schema private from public; revoke all on schema audit from public; -- Policies evaluated for API roles call private.* helpers by qualified name, -- which needs USAGE on the schema. EXECUTE is granted per function below. -grant usage on schema private to anon, authenticated, service_role; +-- anon gets nothing: no policy for anon evaluates a helper yet. +grant usage on schema private to authenticated, service_role; grant usage on schema audit to authenticated, service_role; -- PostgreSQL grants EXECUTE on every new function to PUBLIC. Flip the default diff --git a/supabase/tests/001_schema.sql b/supabase/tests/001_schema.sql index 5ce12896..ad7283bf 100644 --- a/supabase/tests/001_schema.sql +++ b/supabase/tests/001_schema.sql @@ -1,6 +1,6 @@ -- Schema contract: objects exist, RLS is on, API roles start from zero. begin; -select plan(22); +select plan(24); -- Schemas select has_schema('private', 'schema private exists'); @@ -48,6 +48,8 @@ select ok(not has_table_privilege('authenticated', 'public.profiles', 'insert'), select ok(not has_table_privilege('authenticated', 'public.profiles', 'delete'), 'authenticated cannot delete profiles'); select ok(not has_table_privilege('authenticated', 'public.profile_roles', 'insert'), 'authenticated cannot insert profile_roles'); select ok(not has_column_privilege('authenticated', 'public.profiles', 'active', 'update'), 'authenticated cannot update profiles.active'); +select ok(not has_schema_privilege('anon', 'private', 'usage'), 'anon has no usage on schema private'); +select ok(not has_function_privilege('anon', 'public.grant_platform_role(uuid, public.platform_role)', 'execute'), 'anon cannot execute grant_platform_role'); select * from finish(); rollback;