Files
accounted/supabase/migrations/20260831180000_connector_grants_require_expiry.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

25 lines
1.4 KiB
SQL

-- Require an expiry on every source='connector' capability grant.
--
-- Connector grants are the self-host instance's offline cache: the hourly
-- connector sync writes them with expires_at = min(now + 72h, period_end + 3d)
-- and deletes them when the subscription lapses. Both the TS gate
-- (lib/entitlements/has-capability.ts grantIsActive) and the SQL helper
-- (public.company_has_capability) treat a NULL expires_at as active forever,
-- so a hand-written connector row without an expiry would be a permanent
-- unlock that no sync ever revokes. No writer legitimately produces that
-- shape; make the database refuse it (CodeRabbit finding on PR #1747,
-- defense in depth on top of the sync's own arithmetic).
--
-- Safe to validate inline: 'connector' entered the source CHECK only in
-- 20260831170000 (this same PR) and no code path has written a connector row
-- yet, so no existing row can violate the constraint. The table is small
-- (a handful of grant rows per company); the ACCESS EXCLUSIVE lock is brief.
ALTER TABLE public.capability_grants
ADD CONSTRAINT capability_grants_connector_expiry_check
CHECK (source <> 'connector' OR expires_at IS NOT NULL);
COMMENT ON CONSTRAINT capability_grants_connector_expiry_check
ON public.capability_grants IS
'Connector grants are a short-lived offline cache written by the instance connector sync; a NULL expiry would be a permanent unlock nothing revokes.';