Skip to content

Commit

Permalink
fix: prevent redirecting to an absolute URL after login
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
julien-nc committed Oct 10, 2024
1 parent 94a818b commit 4038f12
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/Controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,18 @@ private function buildProtocolErrorResponse(?bool $throttle = null): TemplateRes
return $this->buildFailureTemplateResponse('', 'error', $params, Http::STATUS_NOT_FOUND, $throttleMetadata, $throttle);
}

/**
* @param string|null $redirectUrl
* @return RedirectResponse
*/
private function getRedirectResponse(?string $redirectUrl = null): RedirectResponse {
return new RedirectResponse(
$redirectUrl === null
? null
: preg_replace('/^https?:\/\//', '', $redirectUrl)
);
}

/**
* @PublicPage
* @NoCSRFRequired
Expand All @@ -210,7 +222,7 @@ private function buildProtocolErrorResponse(?bool $throttle = null): TemplateRes
*/
public function login(int $providerId, ?string $redirectUrl = null) {
if ($this->userSession->isLoggedIn()) {
return new RedirectResponse($redirectUrl);
return $this->getRedirectResponse($redirectUrl);
}
if (!$this->isSecure()) {
return $this->buildProtocolErrorResponse();
Expand Down Expand Up @@ -602,7 +614,7 @@ public function code(string $state = '', string $code = '', string $scope = '',

$redirectUrl = $this->session->get(self::REDIRECT_AFTER_LOGIN);
if ($redirectUrl) {
return new RedirectResponse($redirectUrl);
return $this->getRedirectResponse($redirectUrl);
}

return new RedirectResponse(\OC_Util::getDefaultPageUrl());
Expand Down

0 comments on commit 4038f12

Please sign in to comment.