Files
accounted/supabase/migrations/20260517090000_signature_immutability_full.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

34 lines
1.6 KiB
PL/PgSQL

-- Extend the signed-immutability trigger on
-- arsredovisning_signature_requests to cover EVERY audit-critical column,
-- not just the role/signer_name/signed_at/status subset the original
-- migration (20260516170000) protected.
--
-- Without this, a row with status='signed' could be UPDATEd to change
-- bankid_signature_data, signer_personnummer_encrypted, or
-- signer_personnummer_hash — silently altering the audit trail and
-- breaking the "signed = immutable" guarantee that the application layer
-- relies on for fastställelseintyg evidence.
CREATE OR REPLACE FUNCTION public.enforce_signed_signature_request_immutability()
RETURNS TRIGGER AS $$
BEGIN
IF OLD.status = 'signed' THEN
IF NEW.role IS DISTINCT FROM OLD.role
OR NEW.signer_name IS DISTINCT FROM OLD.signer_name
OR NEW.signed_at IS DISTINCT FROM OLD.signed_at
OR NEW.status IS DISTINCT FROM OLD.status
OR NEW.bankid_signature_data IS DISTINCT FROM OLD.bankid_signature_data
OR NEW.signer_personnummer_encrypted IS DISTINCT FROM OLD.signer_personnummer_encrypted
OR NEW.signer_personnummer_hash IS DISTINCT FROM OLD.signer_personnummer_hash
OR NEW.fiscal_period_id IS DISTINCT FROM OLD.fiscal_period_id
OR NEW.company_id IS DISTINCT FROM OLD.company_id THEN
RAISE EXCEPTION 'Cannot modify a signed signature request (id=%)', OLD.id
USING ERRCODE = 'check_violation';
END IF;
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
NOTIFY pgrst, 'reload schema';