From 91295f01e221b8a44a6e36a2d7c613d60a2d42ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Mon, 14 Jul 2025 21:44:12 +0200 Subject: [PATCH] fix origin identification: parse hostname when full URL is used --- src/Middleware/InitializeTenancyByOriginHeader.php | 6 +++++- tests/OriginHeaderIdentificationTest.php | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Middleware/InitializeTenancyByOriginHeader.php b/src/Middleware/InitializeTenancyByOriginHeader.php index 4d85dc5c..4aa4f342 100644 --- a/src/Middleware/InitializeTenancyByOriginHeader.php +++ b/src/Middleware/InitializeTenancyByOriginHeader.php @@ -10,6 +10,10 @@ class InitializeTenancyByOriginHeader extends InitializeTenancyByDomainOrSubdoma { public function getDomain(Request $request): string { - return $request->header('Origin', ''); + if ($origin = $request->header('Origin', '')) { + return parse_url($origin, PHP_URL_HOST) ?? $origin; + } + + return ''; } } diff --git a/tests/OriginHeaderIdentificationTest.php b/tests/OriginHeaderIdentificationTest.php index 071aa493..1d2eb4dc 100644 --- a/tests/OriginHeaderIdentificationTest.php +++ b/tests/OriginHeaderIdentificationTest.php @@ -36,6 +36,12 @@ test('origin identification works', function () { ->withHeader('Origin', 'foo.localhost') ->post('home') ->assertSee($tenant->id); + + // Test with a full URL - not just a hostname + pest() + ->withHeader('Origin', 'https://foo.localhost') + ->post('home') + ->assertSee($tenant->id); }); test('tenant routes are not accessible on central domains while using origin identification', function () {