wacrm/supabase/migrations
Arnas Donauskas 2b32308703 fix(security): patch DB-layer authz bypasses (GHSA-fg5p-2qc3-jmxr)
C1 (Critical): the profiles_update RLS policy gates only on user_id,
leaving account_role/account_id — the source of truth for
is_account_member() — freely writable by the row's own user. A
browser-client UPDATE could self-promote a viewer to owner or move
into another tenant. Add a BEFORE UPDATE trigger that rejects changes
to those columns when current_user = 'authenticated'; the SECURITY
DEFINER member/invitation RPCs (postgres) and the service_role backend
are unaffected.

H2 (High): match_ai_knowledge_fts/_semantic were SECURITY DEFINER,
filtered only on the caller-supplied p_account_id with no membership
check, and were granted to authenticated — letting any logged-in user
read another account's knowledge base via a foreign p_account_id.
Recreate both as SECURITY INVOKER so the existing
ai_knowledge_chunks_select RLS policy applies; the service_role
auto-reply bot still bypasses RLS.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-08 09:10:07 +03:00
..
001_initial_schema.sql fix: make migration idempotent 2026-04-16 19:46:41 +03:00
002_pipelines_enhancements.sql feat(pipelines): Kanban drag-drop, analytics, deal sheet, contact deals tab 2026-04-16 22:38:45 +03:00
003_broadcast_recipient_wamid.sql fix(broadcasts): per-recipient variables, webhook status sync, rate limit 2026-04-17 11:22:38 +03:00
004_contact_delete_set_null.sql fix(contacts): allow deletion — SET NULL on broadcast_recipients, deals 2026-04-17 16:56:45 +03:00
005_broadcast_counts_incremental.sql fix(broadcasts): senior-review hardening pass 2026-04-17 17:38:52 +03:00
006_automations.sql feat(automations): visual flow builder, engine, and logs viewer 2026-04-17 19:39:02 +03:00
007_automations_increment_counter.sql fix(automations): atomic execution_count via SQL function (migration 007) 2026-04-17 21:45:27 +03:00
008_profile_avatars_storage.sql feat(settings): user profile management 2026-04-20 17:40:39 +03:00
009_message_actions.sql feat(inbox): reactions, reply-to, and copy on chat messages 2026-05-19 16:17:26 +03:00
010_flows.sql feat(flows): foundation for interactive WhatsApp messages (PR 1/4) 2026-05-22 13:12:27 +03:00
011_profile_beta_features.sql feat(beta): per-account beta_features flag on profiles, gating Flows 2026-05-22 12:57:33 +03:00
012_flows_increment_counter.sql fix(flows): atomic execution_count increment via SECURITY DEFINER RPC 2026-05-22 15:39:00 +03:00
013_whatsapp_config_phone_number_id_unique.sql fix(whatsapp): prevent silent inbound-message drop when two users share a phone_number_id 2026-05-26 10:35:59 +02:00
014_message_templates_meta_integration.sql fix(migration-014): drop subquery from buttons CHECK (Postgres disallows it) 2026-05-29 12:21:14 +02:00
015_whatsapp_config_registration.sql fix(whatsapp): register phone numbers on Meta + verify subscription state 2026-05-29 18:12:38 +02:00
016_flow_media.sql feat(flows): add send_media node for image / video / document sends 2026-05-29 19:11:29 +02:00
017_account_sharing.sql fix(migrations): make 017 RLS rewrite re-runnable 2026-06-22 09:48:47 +03:00
018_account_member_rpcs.sql feat(api): account + members management endpoints 2026-05-31 15:00:27 +03:00
019_invitation_rpcs.sql feat(api): invitation create + peek + redeem endpoints 2026-05-31 17:32:46 +03:00
020_account_sharing_followups.sql perf(db,webhook): backend follow-ups from the multi-user review 2026-05-31 19:18:58 +03:00
021_account_default_currency.sql feat(deals): make default deal currency configurable per account (#218) 2026-06-08 13:59:48 +03:00
022_contact_phone_dedup.sql feat(contacts): prevent duplicate phone numbers on create/import (#212) 2026-06-08 15:52:38 +03:00
023_chat_media.sql feat(inbox): send photo, video, document & voice in chat (#213) 2026-06-18 10:07:16 +03:00
024_member_presence.sql feat(team): member presence (online / away / offline) on the roster 2026-06-22 14:37:29 +03:00
025_filter_contacts_by_tags.sql feat(contacts): add filter_contacts_by_tags RPC migration 2026-06-22 15:50:40 +03:00
026_api_keys.sql feat(api): public API groundwork — scoped API keys + /api/v1/me 2026-06-23 15:35:43 +03:00
027_notifications.sql feat(notifications): implement account-based notification retrieval and update logic 2026-06-30 11:16:20 +05:30
028_webhook_endpoints.sql feat(api): outbound event webhooks — /api/v1/webhooks (#245) 2026-07-01 14:53:18 +03:00
029_ai_reply.sql feat: AI reply assistant (bring-your-own-key) 2026-07-02 12:56:04 +03:00
030_ai_knowledge.sql fix(ai-kb): address code-review findings 2026-07-02 17:20:38 +03:00
031_fix_profiles_update_rls.sql fix(security): patch DB-layer authz bypasses (GHSA-fg5p-2qc3-jmxr) 2026-07-08 09:10:07 +03:00
032_fix_ai_knowledge_membership.sql fix(security): patch DB-layer authz bypasses (GHSA-fg5p-2qc3-jmxr) 2026-07-08 09:10:07 +03:00