90 lines
3.4 KiB
PHP
90 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace Config;
|
|
|
|
use CodeIgniter\Config\BaseConfig;
|
|
|
|
class RateLimiter extends BaseConfig
|
|
{
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| JWT / Authenticated API Routes
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
public array $jwtApi = [
|
|
'limit' => 60, // max requests
|
|
'window' => 60, // window in seconds
|
|
'violation_soft' => 3, // violations before soft block
|
|
];
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Auth API Routes (verifyMobile, verifyOTP, etc.)
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
public array $authApi = [
|
|
'limit' => 10, // max requests per window
|
|
'window' => 180, // window in seconds (3 min)
|
|
'violation_soft' => 3, // failed attempts before soft block
|
|
];
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| User-Level Progressive Block Durations (seconds)
|
|
| 0 = permanent until manual unblock
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
public array $userBlock = [
|
|
'soft_duration' => 900, // permanent, manual unblock only
|
|
'medium_duration' => 7200, // 2 hours
|
|
'hard_duration' => 86400, // 24 hours
|
|
// attempts while at a block level before escalating to next
|
|
'medium_trigger' => 1, // attempts during soft → medium
|
|
'hard_trigger' => 1, // attempts during medium → hard
|
|
];
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| IP-Level Throttle & Progressive Block (independent of user)
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
public array $ipBlock = [
|
|
'limit' => 120, // max requests per window
|
|
'window' => 60, // window in seconds
|
|
'violation_soft' => 5, // violations before soft block
|
|
'soft_duration' => 0, // permanent, manual unblock only
|
|
'medium_duration' => 7200, // 2 hours
|
|
'hard_duration' => 86400, // 24 hours
|
|
'medium_trigger' => 1, // attempts during soft → medium
|
|
'hard_trigger' => 1, // attempts during medium → hard
|
|
];
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Cache Key Prefixes
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
public array $cacheKeys = [
|
|
'ip_count' => 'rl_ip_count_',
|
|
'ip_violations' => 'rl_ip_viol_',
|
|
'ip_block' => 'rl_ip_block_',
|
|
'ip_block_hits' => 'rl_ip_blkhit_',
|
|
'user_count' => 'rl_usr_count_',
|
|
'user_violations' => 'rl_usr_viol_',
|
|
'user_block' => 'rl_usr_block_',
|
|
'user_block_hits' => 'rl_usr_blkhit_',
|
|
];
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| HTTP Status Codes per block level
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
public array $statusCodes = [
|
|
'throttle' => 429,
|
|
'soft' => 429,
|
|
'medium' => 403,
|
|
'hard' => 451,
|
|
];
|
|
}
|