Skip to content

Commit d076595

Browse files
committed
Restrict chat_threads INSERT to initiator (close rate-limit bypass)
Owner-role inserts skipped thread-initiation limit via OR branch. App only creates threads as donor/initiator (ChatWindow). Made-with: Cursor
1 parent 5e6bfc2 commit d076595

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

supabase/migrations/20260420120000_chat_thread_rate_limit_and_profile_first_name.sql

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,9 @@ DROP POLICY IF EXISTS "Users can create threads they're involved in" ON public.c
4141
CREATE POLICY "Users can create threads they're involved in" ON public.chat_threads
4242
FOR INSERT TO authenticated
4343
WITH CHECK (
44-
(auth.uid() = initiator_id OR auth.uid() = owner_id)
44+
auth.uid() = initiator_id
4545
AND public.check_message_rate_limit(auth.uid())
46-
AND (
47-
auth.uid() <> initiator_id
48-
OR public.check_thread_initiation_rate_limit(auth.uid())
49-
)
46+
AND public.check_thread_initiation_rate_limit(auth.uid())
5047
);
5148

5249

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- Only the donor/initiator may insert a chat thread (matches ChatWindow.initializeChat).
2+
-- Previously, owner_id inserts satisfied (auth.uid() <> initiator_id OR rate_limit) without
3+
-- evaluating the thread-initiation limit. Initiator-only insert applies that limit to everyone
4+
-- who can create a thread.
5+
6+
DROP POLICY IF EXISTS "Users can create threads they're involved in" ON public.chat_threads;
7+
8+
CREATE POLICY "Users can create threads they're involved in" ON public.chat_threads
9+
FOR INSERT TO authenticated
10+
WITH CHECK (
11+
auth.uid() = initiator_id
12+
AND public.check_message_rate_limit(auth.uid())
13+
AND public.check_thread_initiation_rate_limit(auth.uid())
14+
);

0 commit comments

Comments
 (0)