Summary
The security monitoring system (/api/admin/security/scan and the security-scan cron) already detects and persists critical alerts, but nothing acts on them automatically. Build an automated incident-response / circuit-breaker layer that escalates critical alerts into safe, reversible recovery actions.
Today the scan returns alerts (severity: "critical", etc.) and writes them to the alert table, but no code path ever invokes the contracts' existing pause/emergency_withdraw primitives or flips a pool to the paused status.
Requirements
- Critical-alert → auto-pause — when a scan flags a configured threshold of
critical alerts for a pool, automatically invoke the contract's pause function (rotational contract: fn pause) and persist the paused status + reason to Supabase.
- Incident record — create an
incidents table (pool, trigger, severity, created_by_scan, timestamps, resolution) so every automatic action is auditable via the existing admin audit log (/api/admin/audit-log).
- Escalation & cooldown — add a cooldown to prevent pause-flap (e.g., no auto-pause more than N times per pool per window), and notify admins via the existing notification/push system.
- Admin review & recovery — an admin endpoint to review a paused pool, mark the incident resolved, and (optionally) resume it; keep
emergency_withdraw admin-only and manual, never automatic.
- Dry-run mode — a config flag to run in dry-run (log-only) before enabling auto-action, with the scan result reporting whether action would have fired.
Notes / context
- Contract primitives already exist:
rotational/src/lib.rs has pause, emergency_withdraw, migrate. Reuse them — do not change contract logic unless required.
- Follow
/api/cron/security-scan/route.ts and /api/admin/security/scan/route.ts conventions for auth (server-side checks + CRON_SECRET) and rate limiting.
- Add unit tests for the cooldown/pause-flap logic and the dry-run path, mirroring existing
route.test.ts patterns.
Acceptance criteria
Summary
The security monitoring system (
/api/admin/security/scanand thesecurity-scancron) already detects and persists critical alerts, but nothing acts on them automatically. Build an automated incident-response / circuit-breaker layer that escalates critical alerts into safe, reversible recovery actions.Today the scan returns alerts (
severity: "critical", etc.) and writes them to the alert table, but no code path ever invokes the contracts' existingpause/emergency_withdrawprimitives or flips a pool to thepausedstatus.Requirements
criticalalerts for a pool, automatically invoke the contract'spausefunction (rotational contract:fn pause) and persist thepausedstatus + reason to Supabase.incidentstable (pool, trigger, severity, created_by_scan, timestamps, resolution) so every automatic action is auditable via the existing admin audit log (/api/admin/audit-log).emergency_withdrawadmin-only and manual, never automatic.Notes / context
rotational/src/lib.rshaspause,emergency_withdraw,migrate. Reuse them — do not change contract logic unless required./api/cron/security-scan/route.tsand/api/admin/security/scan/route.tsconventions for auth (server-side checks +CRON_SECRET) and rate limiting.route.test.tspatterns.Acceptance criteria