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 () {