Skip to content

Commit

Permalink
Handle missing referer in session handler
Browse files Browse the repository at this point in the history
  • Loading branch information
danon committed Oct 9, 2024
1 parent b2afb0c commit 0c70fb6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/Services/Session/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ protected function getDefaultPayload($payload)
$payload['path'] = $path === '/' ? $path : ('/' . $path);
}
if (\in_array($request->path(), ['ping', 'User/Settings/Ajax'])) {
$payload['path'] = \parse_url($request->header('Referer'), \PHP_URL_PATH);
$parseUrl = \parse_url($request->header('Referer'), \PHP_URL_PATH);
if ($parseUrl) {
$payload['path'] = $parseUrl;
}
}
}

Expand Down
21 changes: 21 additions & 0 deletions tests/Unit/OnlineUsers/PingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,27 @@ public function ajaxSettingsIsSavedAsReferer(): void
$this->assertSame('/Mikroblogi', $this->sessionPath());
}

#[Test]
public function ignoreEmptyHttpRefererPathEmpty(): void
{
$this->request('/ping', 'http://localhost:8880/');
$this->assertSame('/', $this->sessionPath());
}

#[Test]
public function ignoreEmptyHttpRefererPathMissing(): void
{
$this->request('/ping', 'http://localhost:8880');
$this->assertSame('/ping', $this->sessionPath());
}

#[Test]
public function ignoreEmptyHttpRefererMissing(): void
{
$this->request('/ping', '');
$this->assertSame('/ping', $this->sessionPath());
}

private function sessionPath(): string
{
/** @var Handler $handler */
Expand Down

0 comments on commit 0c70fb6

Please sign in to comment.