1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 08:24:04 +00:00

fix origin identification: parse hostname when full URL is used

This commit is contained in:
Samuel Štancl 2025-07-14 21:44:12 +02:00
parent d8af9b4b43
commit 91295f01e2
2 changed files with 11 additions and 1 deletions

View file

@ -10,6 +10,10 @@ class InitializeTenancyByOriginHeader extends InitializeTenancyByDomainOrSubdoma
{ {
public function getDomain(Request $request): string public function getDomain(Request $request): string
{ {
return $request->header('Origin', ''); if ($origin = $request->header('Origin', '')) {
return parse_url($origin, PHP_URL_HOST) ?? $origin;
}
return '';
} }
} }

View file

@ -36,6 +36,12 @@ test('origin identification works', function () {
->withHeader('Origin', 'foo.localhost') ->withHeader('Origin', 'foo.localhost')
->post('home') ->post('home')
->assertSee($tenant->id); ->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 () { test('tenant routes are not accessible on central domains while using origin identification', function () {