Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/Controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,20 @@ private function buildProtocolErrorResponse(?bool $throttle = null): TemplateRes
* @return RedirectResponse
*/
private function getRedirectResponse(?string $redirectUrl = null): RedirectResponse {
$baseUrl = $this->urlGenerator->getBaseUrl();

if ($redirectUrl === null) {
return new RedirectResponse($this->urlGenerator->getBaseUrl());
return new RedirectResponse($baseUrl);
}

// Remove protocol and domain name
$filtered = preg_replace('/^https?:\/\/[^\/]+/', '', $redirectUrl) ?? '';

// Additional check: ensure the result starts with a single /
if (!preg_match('/^\/[^\/]/', $filtered)) {
return new RedirectResponse($this->urlGenerator->getBaseUrl());
// Reject protocol-relative URLs and anything not starting with a single slash followed
// by an alphanumeric or one of [_-.~?#]
if (!preg_match('/^\/[A-Za-z0-9_\-.~?#]/', $filtered)) {
$this->logger->error("Rejected invalid redirect url '{$filtered}'");
return new RedirectResponse($baseUrl);
}

return new RedirectResponse($filtered);
Expand Down
Loading