Skip to content

Commit ebb3f40

Browse files
Programcodeclaude
andcommitted
Drop hosted rate_limits and global_prompts policies by catalog
Production and staging carry rate_limits policies that no migration created (rate_limits_select_own_or_global, "Users can read own limits"), both allowing global rows. Dropping by the migration's own name would have left them. Drop every policy on the two tables, and revoke client writes on rate_limits. Rehearsed on read-only dumps of both projects. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 633317c commit ebb3f40

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

‎supabase/migrations/20261016120000_security_preship_hardening.sql‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,34 @@ BEGIN
148148
END;
149149
$$;
150150

151+
-- The hosted projects carry policies on these two tables that no migration
152+
-- created (for example "rate_limits_select_own_or_global" and "Users can read
153+
-- own limits", both allowing user_id IS NULL). Drop every policy on them,
154+
-- whatever its name, and recreate only the one intended below.
155+
DO $$
156+
DECLARE
157+
v_policy record;
158+
BEGIN
159+
FOR v_policy IN
160+
SELECT policyname, tablename FROM pg_policies
161+
WHERE schemaname = 'public' AND tablename IN ('global_prompts', 'rate_limits')
162+
LOOP
163+
EXECUTE format('DROP POLICY %I ON public.%I', v_policy.policyname, v_policy.tablename);
164+
END LOOP;
165+
END;
166+
$$;
167+
151168
-- Operator instructions are part of the live system prompt; only Edge
152169
-- Functions (service role) read or write them.
153-
DROP POLICY IF EXISTS "global_prompts_select_all" ON public.global_prompts;
154170
REVOKE ALL ON TABLE public.global_prompts FROM anon, authenticated;
155171

156172
-- Global limits (user_id IS NULL) are server configuration. A signed-in user
157173
-- may still read limits set for their own account.
158-
DROP POLICY IF EXISTS "rate_limits_select_own" ON public.rate_limits;
159174
CREATE POLICY "rate_limits_select_own" ON public.rate_limits
160175
FOR SELECT TO authenticated
161176
USING (user_id = (SELECT auth.uid()));
162177
REVOKE ALL ON TABLE public.rate_limits FROM anon;
178+
REVOKE INSERT, UPDATE, DELETE ON TABLE public.rate_limits FROM authenticated;
163179

164180
-- Admin reporting RPCs relied only on require_admin() inside them; one reads
165181
-- every user's email. The admin Edge Function calls them with the service role.

0 commit comments

Comments
 (0)