|
7 | 7 | * @security HIGH - Contains sensitive system information |
8 | 8 | */ |
9 | 9 |
|
10 | | -// Load BaseController early for response methods |
11 | | -require_once __DIR__ . '/classes/BaseController.php'; // codacy:ignore - Safe class loading with __DIR__ constant |
12 | | - |
13 | 10 | // Prevent direct access |
14 | 11 | if (!isset($_SERVER['REQUEST_URI']) || !isset($_SERVER['HTTP_HOST'])) { // codacy:ignore - $_SERVER access required for standalone API validation |
15 | | - BaseController::forbidden('Direct access forbidden'); |
| 12 | + http_response_code(403); |
| 13 | + die('Direct access forbidden'); // codacy:ignore - die() required for security termination |
16 | 14 | } |
17 | 15 |
|
18 | 16 | // Security headers |
|
73 | 71 | } |
74 | 72 |
|
75 | 73 | if (isset($_SESSION[$rate_limit_key]['count']) && $_SESSION[$rate_limit_key]['count'] >= 100) { // codacy:ignore - Session access required for rate limiting |
76 | | - BaseController::rateLimitExceeded(); |
| 74 | + http_response_code(429); |
| 75 | + die(json_encode(['error' => 'Rate limit exceeded'])); // codacy:ignore - die() required for rate limit response |
77 | 76 | } |
78 | 77 |
|
79 | 78 | if (isset($_SESSION[$rate_limit_key]['count'])) { // codacy:ignore - Session access required for rate limiting |
|
89 | 88 | // Only allow GET requests |
90 | 89 | if (!isset($_SERVER['REQUEST_METHOD']) || $_SERVER['REQUEST_METHOD'] !== 'GET') { // codacy:ignore - $_SERVER access required for method validation |
91 | 90 | http_response_code(405); |
92 | | - BaseController::methodNotAllowed(); |
| 91 | + die(json_encode(['error' => 'Method not allowed'])); // codacy:ignore - die() required for security termination |
93 | 92 | } |
94 | 93 |
|
95 | 94 | // Load Router and Controllers |
96 | 95 | require_once __DIR__ . '/classes/Router.php'; // codacy:ignore - Safe class loading with __DIR__ constant |
| 96 | +require_once __DIR__ . '/classes/BaseController.php'; // codacy:ignore - Safe class loading with __DIR__ constant |
| 97 | +require_once __DIR__ . '/classes/SystemCommand.php'; // codacy:ignore - Safe class loading with __DIR__ constant |
97 | 98 |
|
98 | 99 | // Parse request path |
99 | 100 | $request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; // codacy:ignore - $_SERVER access required for routing, wp_unslash() not available in standalone API |
|
114 | 115 |
|
115 | 116 | // Validate path |
116 | 117 | if (!Router::validatePath($path)) { |
| 118 | + http_response_code(400); |
117 | 119 | error_log("API Security: Suspicious path - " . substr($path, 0, 100) . " - IP: " . $client_ip); |
118 | | - BaseController::badRequest('Invalid path'); |
| 120 | + die(json_encode(['error' => 'Invalid path'])); |
119 | 121 | } |
120 | 122 |
|
| 123 | +// Initialize router |
121 | 124 | $router = new Router(); |
122 | 125 |
|
123 | 126 | // Register routes |
|
0 commit comments