Files
gochat/backend/migrations/000084_expand_encrypted_secret_fields.up.sql
T
Rogeeandrogee f719529d66 fix(security): harden auth and secret handling (HH-444) (#101)
* fix(security): harden auth and credential handling (HH-444)

* fix(security): address HH-444 review blockers

* fix(security): close remaining HH-444 review blockers

---------

Co-authored-by: Rogee <rogee@ipao.vip>
2026-08-22 15:45:06 +08:00

39 lines
1.8 KiB
SQL

DO $$
DECLARE
target_table text;
target_column text;
BEGIN
FOR target_table, target_column IN
SELECT * FROM (VALUES
('agent_bots', 'secret'), ('agent_bots', 'access_token'),
('inboxes', 'secret'), ('integration_hooks', 'access_token'),
('webhook_subscriptions', 'secret'), ('users', 'totp_secret'),
('channel_api', 'secret'), ('channel_api', 'hmac_token'),
('channel_facebook_pages', 'page_access_token'), ('channel_facebook_pages', 'user_access_token'),
('channel_facebook_pages', 'webhook_verify_token'), ('channel_instagrams', 'page_access_token'),
('channel_tiktoks', 'access_token'), ('channel_tiktoks', 'refresh_token'),
('channel_tiktoks', 'webhook_verify_token'), ('channel_whatsapps', 'access_token'),
('channel_whatsapps', 'provider_config'), ('channel_whatsapps', 'webhook_verify_token'),
('channel_emails', 'imap_password'), ('channel_emails', 'smtp_password'),
('channel_web_widgets', 'hmac_token')
) AS fields(table_name, column_name)
LOOP
IF EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_schema = current_schema() AND table_name = target_table AND column_name = target_column
) THEN
EXECUTE format('ALTER TABLE %I ALTER COLUMN %I TYPE text', target_table, target_column);
END IF;
END LOOP;
END $$;
ALTER TABLE IF EXISTS channel_whatsapps ADD COLUMN IF NOT EXISTS provider_config text;
ALTER TABLE IF EXISTS channel_whatsapps ADD COLUMN IF NOT EXISTS webhook_verify_token_digest varchar(64);
DO $$
BEGIN
IF to_regclass('channel_whatsapps') IS NOT NULL THEN
CREATE INDEX IF NOT EXISTS idx_channel_whatsapps_webhook_verify_token_digest
ON channel_whatsapps (webhook_verify_token_digest);
END IF;
END $$;