Skip to content

Commit

Permalink
Only allow relative urls for auth redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
leepeuker committed Oct 5, 2023
1 parent a3180ee commit 56d9cc8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/HttpController/Web/AuthenticationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,19 @@ public function login(Request $request) : Response
}
$redirect = $postParameters['redirect'];
$target = $redirect ?? $_SERVER['HTTP_REFERER'];

$urlParts = parse_url($target);
if (is_array($urlParts) === false) {
$urlParts = ['path' => '/'];
}

/* @phpstan-ignore-next-line */
$targetRelativeUrl = $urlParts['path'] . $urlParts['query'] ?? '';

return Response::create(
StatusCode::createSeeOther(),
null,
[Header::createLocation($target)],
[Header::createLocation($targetRelativeUrl)],
);
}

Expand Down

0 comments on commit 56d9cc8

Please sign in to comment.