feat: optional API key auth via X-API-Key header or ?key= param
This commit is contained in:
@@ -24,6 +24,14 @@ if (php_sapi_name() == 'cli-server' && file_exists(ROOT . DS . 'web' . DS . impl
|
||||
|
||||
switch ($url[0]) {
|
||||
case 'api':
|
||||
if (defined('API_KEY') && API_KEY !== '') {
|
||||
$provided = $_SERVER['HTTP_X_API_KEY'] ?? $_REQUEST['key'] ?? '';
|
||||
if ($provided !== API_KEY) {
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
echo 'Invalid or missing API key';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$target = substr($_SERVER['REQUEST_URI'], 5);
|
||||
if (!$target || !filter_var($target, FILTER_VALIDATE_URL))
|
||||
$target = $_REQUEST['url'];
|
||||
|
||||
Reference in New Issue
Block a user