Skip to content

Emergency Controls

Document ID: ACP-001.4 Version: 1.0 Classification: Internal / Regulator-Shareable Effective Date: March 2026 Next Review: September 2026 Parent Document: ACP-001 — Access Control & Permissions


1. Overview

Keshless implements 8 emergency controls (kill switches) that allow authorized administrators to rapidly restrict or shut down system operations in response to security incidents, fraud detection, or regulatory orders. These controls execute before authentication in the middleware chain, ensuring they cannot be bypassed.

2. Emergency Control Types

2.1 Control Matrix

ControlSeverityEffectKey Parameters
SYSTEM_SHUTDOWNCriticalAll API requests blocked except health/emergency endpointsallowedEndpoints, maintenanceMessage
DISABLE_ALL_TRANSACTIONSCriticalAll financial operations blockedexceptionUserIds (exempt users)
READ_ONLY_MODEHighAll write operations (POST/PUT/PATCH/DELETE) blockedallowedOperations (exempt methods)
DISABLE_WITHDRAWALSHighWithdrawal operations blockedreason
DISABLE_P2P_TRANSFERSMediumPeer-to-peer transfer operations blockedreason
DISABLE_BILL_PAYMENTSMediumBill payment operations blockedreason
DISABLE_TOPUPSMediumDeposit/topup operations blockedreason
RATE_LIMIT_EXTREMEMediumDynamic rate limiting activatedmaxRequestsPerMinute, maxRequestsPerHour, throttleDelay

2.2 Always-Allowed Endpoints

Even during SYSTEM_SHUTDOWN, the following endpoints remain accessible:

EndpointPurpose
/healthHealth check for load balancer
/api/healthAPI health check
/statusSystem status
/api/statusAPI status
/api/admin/emergencyEmergency control management

This ensures administrators can always access the system to deactivate emergency controls.

3. Activation & Authorization

3.1 Who Can Activate

ActionRequired Permission
View emergency controlsMANAGE_EMERGENCY_CONTROLS
Activate a controlMANAGE_EMERGENCY_CONTROLS
Deactivate a controlMANAGE_EMERGENCY_CONTROLS
Modify control parametersMANAGE_EMERGENCY_CONTROLS
Manage system emergency pageMANAGE_SYSTEM_EMERGENCY

Default assignment: Only SUPER_ADMIN and ADMIN roles have the MANAGE_EMERGENCY_CONTROLS permission by default. No other role template includes this permission.

3.2 Activation Flow

Admin activates emergency control via Dashboard

    ├── Permission check: MANAGE_EMERGENCY_CONTROLS

    ├── Control record created/updated in database
    │   ├── controlType: e.g. DISABLE_WITHDRAWALS
    │   ├── isActive: true
    │   ├── parameters: { reason: "..." }
    │   ├── activatedBy: admin employee ID
    │   └── activatedAt: timestamp

    ├── Audit log entry created (SHA-256 hash-chained)

    └── Control takes effect within 5 minutes (cache TTL)

3.3 Cache Behavior

Emergency controls are cached for performance:

ParameterValue
Cache TTL5 minutes
Refresh triggerAutomatic on cache expiry
StorageIn-memory (application-level)
Worst-case delayUp to 5 minutes from activation to enforcement

4. Rate Limiting

4.1 Standard Rate Limits

Rate limiting is configured per endpoint category:

CategoryLimitWindowScope
General API100 requests15 minutesPer IP
Authentication10 requests15 minutesPer IP
OTP requests5 requests15 minutesPer IP + phone
Transactions50 requests15 minutesPer user
Password reset5 requests15 minutesPer IP + email
OTP verification3 attempts5 minutesPer IP + email
Recovery key3 attempts30 minutesPer IP + email

4.2 USSD Rate Limiting

ParameterValue
Limit10 requests per 60 seconds
ScopePer phone number
TrackingIn-memory Map
CleanupEvery 5 minutes
ResponseHTTP 429

4.3 Dynamic Rate Limiting (RATE_LIMIT_EXTREME)

When the RATE_LIMIT_EXTREME emergency control is activated, the system applies configurable rate limits:

ParameterDescription
maxRequestsPerMinuteMaximum requests per user/IP per minute
maxRequestsPerHourMaximum requests per user/IP per hour
throttleDelayArtificial delay added to requests (milliseconds)

Rate Limit Response Headers:

HeaderDescription
X-RateLimit-LimitMaximum allowed requests
X-RateLimit-RemainingRemaining requests in window
X-RateLimit-ResetUnix timestamp when limit resets
Retry-AfterSeconds to wait before retrying

4.4 Rate Limit Implementation

Standard rate limits use in-memory Maps with automatic cleanup:

  • Password reset limiter: Cleanup every 60 seconds
  • USSD limiter: Cleanup every 5 minutes
  • Keying strategy: IP address + identifier (email, phone, or user ID)

5. Incident Response Integration

5.1 Emergency Control Scenarios

ScenarioRecommended ControlRationale
Active fraud detectedDISABLE_ALL_TRANSACTIONSStop all financial operations while investigating
Withdrawal fraud patternDISABLE_WITHDRAWALSBlock withdrawals specifically while allowing deposits
DDoS attackRATE_LIMIT_EXTREMEThrottle requests without full shutdown
Data breach suspectedSYSTEM_SHUTDOWNFull lockdown for investigation
Regulatory orderREAD_ONLY_MODEPreserve data for regulators; prevent modifications
P2P transfer abuseDISABLE_P2P_TRANSFERSBlock transfers while allowing commerce
Payment processor issueDISABLE_BILL_PAYMENTSBlock bills if processor is compromised
Deposit anomalyDISABLE_TOPUPSBlock deposits if source is suspicious

5.2 Activation Decision Tree

Security incident detected

    ├── Is it affecting all operations?
    │   ├── Yes → SYSTEM_SHUTDOWN (Critical)
    │   └── No ↓

    ├── Is it financial in nature?
    │   ├── All financial ops? → DISABLE_ALL_TRANSACTIONS
    │   ├── Withdrawals only? → DISABLE_WITHDRAWALS
    │   ├── Transfers only? → DISABLE_P2P_TRANSFERS
    │   ├── Bill payments? → DISABLE_BILL_PAYMENTS
    │   └── Deposits? → DISABLE_TOPUPS

    ├── Is it a volume/availability issue?
    │   └── Yes → RATE_LIMIT_EXTREME

    └── Need to preserve data integrity?
        └── Yes → READ_ONLY_MODE

5.3 Deactivation

Emergency controls are deactivated through the same dashboard interface. Deactivation:

  1. Requires MANAGE_EMERGENCY_CONTROLS permission
  2. Updates the control record (isActive: false)
  3. Creates an audit log entry
  4. Takes effect within 5 minutes (cache TTL)

6. Database Availability Control

6.1 Database Check Middleware

The databaseCheckMiddleware runs before all routes and rejects requests if the database connection is unavailable:

  • Check: Tests Prisma client connectivity
  • Failure response: HTTP 503 Service temporarily unavailable
  • Purpose: Prevents partial/corrupted operations when the database is down
  • Behavior: Fail closed — no database = no service

6.2 Interaction with Emergency Controls

Emergency controls are stored in the database. If the database is unavailable:

  1. databaseCheckMiddleware rejects all requests (step 5 in middleware chain)
  2. Emergency check middleware (step 6) never executes
  3. Net effect: System is effectively in SYSTEM_SHUTDOWN mode

This is a safe default — database unavailability results in full service denial rather than uncontrolled access.

Internal use only - Keshless Payment Platform