@davoodmehraban89 / VELYQOR / commits / bb38bd6
Fork 0

Intelligence, Advanced Charting & Trading Platform

security(db): reject trigger if persisted quality gate is suspended or sample timestamps disagree

davoodmehraban89 committed Oct 22, 2026 at 23:42 UTC bb38bd6ccfc26e9ae972a59faf56483dc4fd20f2
1 file changed +12
db/migrations/0006_alert_runtime_atomic.sql
+12
@@ -141,6 +141,18 @@ BEGIN
141 THEN RAISE EXCEPTION 'invalid triggered event or recipient' USING ERRCODE = '22023';
142 END IF;
143
144 + -- Defense in depth: the data-integrity gate must have accepted the
145 + -- same exact timestamp; an event cannot bypass a suspended price feed.
146 + IF p_next_state #>> '{gate,suspended}' IS DISTINCT FROM 'false'
147 + OR p_next_state #>> '{gate,lastSampleAt}'
148 + IS DISTINCT FROM p_next_state #>> '{alert,lastTimestamp}'
149 + OR p_next_state #>> '{gate,lastAccepted,timestamp}'
150 + IS DISTINCT FROM p_next_state #>> '{alert,lastTimestamp}'
151 + THEN
152 + RAISE EXCEPTION 'unverified or stale quality gate cannot enqueue'
153 + USING ERRCODE = '22023';
154 + END IF;
155 +
156 -- No implicit consent, no stored chat identifiers. Lock the opt-in row so
157 -- revocation and enqueue cannot commit in the opposite order.
158 PERFORM 1 FROM public.alert_notification_consents AS consent