Skip to content
Closed
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion src/Controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ public function getReturnUrl(Request $request, ?array $sessionTicket): string
// Parse the query parameters and return them in an array
$query = $this->parseQueryParameters($request, $sessionTicket);
// Construct the ReturnTo URL
return $this->httpUtils->getSelfURLNoQuery() . '?' . http_build_query($query);
$returnToBase = Module::getModuleURL('casserver/login');
return $returnToBase . '?' . http_build_query($query);
Copy link
Member

@tvdijen tvdijen Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be giving the exact same result?
If this is not the case, I think it might be better to rely on Symfony's request object and use $request->getBaseUrl() instead of our own http-utils

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tvdijen I’m looking into the issue. These are the values I get when I use each method:

----- request->getBaseUrl() ---- :   /simplesaml/module.php
----- Module::getModuleURL('casserver/login') ---- :   https://localhost/simplesaml/module.php/casserver/login
----- this->httpUtils->getSelfURLNoQuery() ---- :  https://localhost/simplesaml/module.php/this-should-be-ignored

All methods except Module::getModuleURL() return an incorrect value. It looks like the module.php segment in the path is being treated as the end of the URL, right before the query string should start.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tvdijen I’m looking into the issue. These are the values I get when I use each method:

----- this->httpUtils->getSelfURLNoQuery() ---- :  https://localhost/simplesaml/module.php/this-should-be-ignored

Why do you feel that anything after module.php should be ignored? It's not part of the query, so it's still included in the self URL.. The query starts after the ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tvdijen i found the underlying issue. I will provide more details tomorrow and then we can decide on the best next steps.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tvdijen according to my findings the HTTP::getSelfURL() mis-reconstructs the current URL when SimpleSAMLphp is accessed through a rewritten path such as RewriteRule ^/cas/login(.*) /${SSP_APACHE_ALIAS}module.php/casserver/login.php$1 [PT]. In this scenario the public URL is /cas/login?service=..., while Apache internally rewrites it to /simplesaml/module.php/casserver/login.php?service=.... The old implementation assumes that the script-relative filesystem path (for example module.php/casserver/login.php) appears verbatim in $_SERVER['REQUEST_URI'], searches for that substring in the entire REQUEST_URI, and rebuilds the URL by stitching together getBaseURL(), that matched path, and the remainder of REQUEST_URI. With mod_rewrite, REQUEST_URI contains only the external path (/cas/login?...), so the expected script path is not present, or may only appear by accident inside query parameters. This causes getSelfURL() to either fall back to an incorrect URL or to construct one that points to module.php/... instead of /cas/login, or that has a malformed path/query combination, breaking redirects and return URLs that rely on getSelfURL() to reflect the actual public URL.

}


Expand Down
8 changes: 4 additions & 4 deletions tests/src/Controller/LoginControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public static function loginOnAuthenticateParameters(): array
'ForceAuthn' => false,
'isPassive' => false,
// phpcs:ignore Generic.Files.LineLength.TooLong
'ReturnTo' => 'http://localhost/?service=https%3A%2F%2Fexample.com%2Fssp%2Fmodule.php%2Fcas%2Flinkback.php',
'ReturnTo' => 'http://localhost/module.php/casserver/login?service=https%3A%2F%2Fexample.com%2Fssp%2Fmodule.php%2Fcas%2Flinkback.php',
],
[],
],
Expand All @@ -151,7 +151,7 @@ public static function loginOnAuthenticateParameters(): array
'ForceAuthn' => false,
'isPassive' => false,
// phpcs:ignore Generic.Files.LineLength.TooLong
'ReturnTo' => 'http://localhost/?service=https%3A%2F%2Fexample.com%2Fssp%2Fmodule.php%2Fcas%2Flinkback.php&entityId=http%3A%2F%2Flocalhost%2FentityId%2Fsso',
'ReturnTo' => 'http://localhost/module.php/casserver/login?service=https%3A%2F%2Fexample.com%2Fssp%2Fmodule.php%2Fcas%2Flinkback.php&entityId=http%3A%2F%2Flocalhost%2FentityId%2Fsso',
],
[],
],
Expand All @@ -164,7 +164,7 @@ public static function loginOnAuthenticateParameters(): array
'ForceAuthn' => false,
'isPassive' => false,
// phpcs:ignore Generic.Files.LineLength.TooLong
'ReturnTo' => 'http://localhost/?service=https%3A%2F%2Fexample.com%2Fssp%2Fmodule.php%2Fcas%2Flinkback.php&scope=desktop',
'ReturnTo' => 'http://localhost/module.php/casserver/login?service=https%3A%2F%2Fexample.com%2Fssp%2Fmodule.php%2Fcas%2Flinkback.php&scope=desktop',
'saml:IDPList' => [
'http://localhost/entityId/sso/scope/A',
'http://localhost/entityId/sso/scope/B',
Expand All @@ -187,7 +187,7 @@ public static function loginOnAuthenticateParameters(): array
'ForceAuthn' => false,
'isPassive' => false,
// phpcs:ignore Generic.Files.LineLength.TooLong
'ReturnTo' => 'http://localhost/?service=https%3A%2F%2Fexample.com%2Fssp%2Fmodule.php%2Fcas%2Flinkback.php&scope=desktop',
'ReturnTo' => 'http://localhost/module.php/casserver/login?service=https%3A%2F%2Fexample.com%2Fssp%2Fmodule.php%2Fcas%2Flinkback.php&scope=desktop',
'saml:idp' => 'http://localhost/entityId/sso/scope/A',
],
[
Expand Down