Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland committed Jan 5, 2024
1 parent 947645d commit 743f4ea
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions framework/core/src/Forum/Controller/LogOutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Illuminate\Support\Arr;
use Laminas\Diactoros\Response\HtmlResponse;
use Laminas\Diactoros\Response\RedirectResponse;
use Laminas\Diactoros\Uri;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface;
Expand Down Expand Up @@ -129,13 +130,9 @@ protected function sanitizeReturnUrl(string $url, string $base): string
return $base; // Return base URL for empty return URL
}

$parsed = parse_url($url);
$parsed = new Uri($url);

if (!$parsed || !isset($parsed['host'])) {
return $base; // Return early for invalid URLs
}

$host = $parsed['host'];
$host = $parsed->getHost();

if (in_array($host, $this->getWhitelistedRedirectDomains())) {
return $url;
Expand All @@ -146,14 +143,10 @@ protected function sanitizeReturnUrl(string $url, string $base): string

protected function getWhitelistedRedirectDomains(): array
{
$forumUrl = $this->config->url();
$parsedForumUrl = parse_url($forumUrl);

// Extract the host from the parsed forum URL
$forumHost = isset($parsedForumUrl['host']) ? $parsedForumUrl['host'] : '';

$forumUri = new Uri($this->config->url());

return array_merge(
[$forumHost],
[$forumUri->getHost()],
$this->config->offsetGet('redirectDomains') ?? []
);
}
Expand Down

0 comments on commit 743f4ea

Please sign in to comment.