diff --git a/plugins/sMultisitePlugin.php b/plugins/sMultisitePlugin.php index 93b6c47..2bc6c41 100644 --- a/plugins/sMultisitePlugin.php +++ b/plugins/sMultisitePlugin.php @@ -240,10 +240,15 @@ function ms_sso_current_session_id(): string { * Enforces resource access per domain on the front-end: * - Compares evo()->documentIdentifier against cached allowed resource IDs for the current site_key. * - Whitelists SSO service endpoints to avoid accidental 404 / access blocks. + * - Leaves API entrypoints without an HTTP request binding outside page access checks. * * @return void */ Event::listen('evolution.OnWebPageInit', function () { + if (!app()->bound('request')) { + return; + } + $uri = strtok($_SERVER['REQUEST_URI'] ?? '/', '?'); $suffix = (string) evo()->getConfig('friendly_url_suffix', ''); $path = $uri; diff --git a/tests/runtime/api-request-test.php b/tests/runtime/api-request-test.php new file mode 100644 index 0000000..5538a86 --- /dev/null +++ b/tests/runtime/api-request-test.php @@ -0,0 +1,34 @@ +denials++; } +}; +$GLOBALS['apiTestApp'] = $app; +$events = new Dispatcher($app); +$app->instance('events', $events); +Facade::setFacadeApplication($app); +if (!class_exists('Event', false)) { class_alias(Illuminate\Support\Facades\Event::class, 'Event'); } +require dirname(__DIR__, 2) . '/plugins/sMultisitePlugin.php'; +$events->dispatch('evolution.OnWebPageInit', [[]]); +if ($app->bound('request') || $app->denials !== 0) { throw new RuntimeException('API event must not bind a request or deny access'); } + +$app->instance('request', Illuminate\Http\Request::create('/private/')); +$app->instance('cache', new Illuminate\Cache\Repository(new Illuminate\Cache\ArrayStore())); +$_SERVER['REQUEST_URI'] = '/private/'; +$events->dispatch('evolution.OnWebPageInit'); +if ($app->denials !== 1) { throw new RuntimeException('Bound HTTP request must still deny a foreign resource'); } +$app['cache']->put('sMultisite-default-resources', [1]); +$events->dispatch('evolution.OnWebPageInit'); +if ($app->denials !== 1) { throw new RuntimeException('Allowed HTTP resource must remain accessible'); } +echo "API and HTTP resource guards passed\n";