feat: SuperAdmin server-access kill switch gate
Add /super/settings endpoints and API middleware that returns generic 503 while keeping unlock routes whitelisted. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* Bearer token must match SUPERADMIN_REMOTE_TOKEN (same as SuperAdmin Tenant.remoteApiToken).
|
||||
*/
|
||||
class EnsureSuperAdminRemoteToken
|
||||
{
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
$expected = trim((string) config('services.superadmin.remote_token', ''));
|
||||
if ($expected === '') {
|
||||
return response()->json([
|
||||
'message' => 'SUPERADMIN_REMOTE_TOKEN is not configured',
|
||||
], 503);
|
||||
}
|
||||
|
||||
$auth = (string) $request->header('Authorization', '');
|
||||
$token = '';
|
||||
if (preg_match('/^\s*Bearer\s+(.+)\s*$/i', $auth, $m)) {
|
||||
$token = trim($m[1]);
|
||||
}
|
||||
|
||||
if ($token === '' || ! hash_equals($expected, $token)) {
|
||||
return response()->json(['message' => 'Unauthorized'], 401);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user