Files
accounted/supabase/migrations/20260523121000_pending_operations_chat_insert_policy.sql
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

21 lines
872 B
SQL

-- Allow the in-app chat agent (lib/agent/chat/run-turn.ts) to insert into
-- pending_operations. Until now only SELECT + UPDATE policies existed because
-- the MCP server always wrote via service role (createServiceClientNoCookies)
-- and RLS was bypassed. The chat loop runs under the user's cookie session
-- and gets RLS-denied on insert, surfacing as "behörighetsproblem på
-- serversidan" in the assistant's narration.
--
-- Scoped to actor_type='agent_chat' so this policy doesn't quietly open
-- write paths for the api_key / mcp_oauth / cron actors — those continue
-- to go through the service role.
CREATE POLICY "pending_operations_chat_insert" ON public.pending_operations
FOR INSERT
WITH CHECK (
actor_type = 'agent_chat'
AND auth.uid() = user_id
AND company_id IN (SELECT public.user_company_ids())
);
NOTIFY pgrst, 'reload schema';