Skip to content

Commit 0462f50

Browse files
tvdijenpradtke
andauthored
Merge commit from fork
* Open redirect and xss php template fix * SSP 2 adjustments for httputils, fix misaligned merge/rebase for logout --------- Co-authored-by: Patrick Radtke <patrick@cirrusidentity.com>
1 parent 81b6b53 commit 0462f50

2 files changed

Lines changed: 39 additions & 38 deletions

File tree

public/loggedOut.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,11 @@
2121
*
2222
*/
2323

24-
declare(strict_types=1);
25-
26-
session_cache_limiter('nocache');
27-
28-
$globalConfig = \SimpleSAML\Configuration::getInstance();
29-
30-
$t = new \SimpleSAML\XHTML\Template($globalConfig, 'casserver:loggedOut.twig');
31-
32-
if (array_key_exists('url', $_GET)) {
33-
$t->data['url'] = $_GET['url'];
34-
}
35-
36-
$t->send();
24+
// This file is only to preserve this older path
25+
$http = new \SimpleSAML\Utils\HTTP();
26+
$http->redirectTrustedURL(
27+
$http->addURLParameters(
28+
\SimpleSAML\Module::getModuleURL('casserver/logout.php'),
29+
$_GET['url'] ? ['url' => $_GET['url']] : []
30+
)
31+
);

public/logout.php

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
declare(strict_types=1);
2727

2828
/* Load simpleSAMLphp, configuration and metadata */
29+
30+
use SimpleSAML\Module\casserver\Cas\ServiceValidator;
31+
use SimpleSAML\Module\casserver\Cas\TicketValidator;
32+
2933
$casconfig = \SimpleSAML\Configuration::getConfig('module_casserver.php');
3034

3135
if (!$casconfig->getOptionalValue('enable_logout', false)) {
@@ -36,17 +40,27 @@
3640
throw new \Exception($message);
3741
}
3842

39-
$skipLogoutPage = $casconfig->getOptionalValue('skip_logout_page', false);
40-
41-
if ($skipLogoutPage && !array_key_exists('url', $_GET)) {
42-
$message = 'Required URL query parameter [url] not provided. (CAS Server)';
43+
$isCasV3 = array_key_exists('service', $_GET);
44+
$url = $_GET['service'] ?? $_GET['url'] ?? null;
45+
// Skip logout is enabled for valid casv3 service logouts, or if enabled for casv2
46+
$skipLogoutPage = $isCasV3 || $casconfig->getOptionalBoolean('skip_logout_page', false);
4347

48+
if ($skipLogoutPage && !$url) {
49+
$message = 'Required URL query parameter ["service" or "url"] not provided. (CAS Server)';
4450
\SimpleSAML\Logger::debug('casserver:' . $message);
45-
4651
throw new \Exception($message);
4752
}
48-
/* Load simpleSAMLphp metadata */
4953

54+
$serviceValidator = new ServiceValidator($casconfig);
55+
if (isset($url)) {
56+
$serviceCasConfig = $serviceValidator->checkServiceURL(TicketValidator::sanitize($url));
57+
if (!isset($serviceCasConfig)) {
58+
// If invalid logout url sent, act like no url sent and show logout page
59+
\SimpleSAML\Logger::info("Invalid logout url '$url'. Ignoring");
60+
$url = null;
61+
$skipLogoutPage = false;
62+
}
63+
}
5064
$as = new \SimpleSAML\Auth\Simple($casconfig->getValue('authsource'));
5165

5266
$session = \SimpleSAML\Session::getSession();
@@ -64,28 +78,20 @@
6478

6579
if ($as->isAuthenticated()) {
6680
\SimpleSAML\Logger::debug('casserver: performing a real logout');
67-
68-
if ($casconfig->getOptionalValue('skip_logout_page', false)) {
69-
$as->logout($_GET['url']);
70-
} else {
71-
$as->logout(
72-
$httpUtils->addURLParameters(
73-
\SimpleSAML\Module::getModuleURL('casserver/loggedOut.php'),
74-
array_key_exists('url', $_GET) ? ['url' => $_GET['url']] : [],
75-
),
76-
);
77-
}
81+
// Browser will be returned to this url and we will handle any $url checking
82+
$as->logout($httpUtils->getSelfURL());
7883
} else {
7984
\SimpleSAML\Logger::debug('casserver: no session to log out of, performing redirect');
8085

81-
if ($casconfig->getOptionalValue('skip_logout_page', false)) {
82-
$httpUtils->redirectTrustedURL($httpUtils->addURLParameters($_GET['url'], []));
86+
if ($skipLogoutPage) {
87+
$httpUtils->redirectTrustedURL($url);
8388
} else {
84-
$httpUtils->redirectTrustedURL(
85-
$httpUtils->addURLParameters(
86-
\SimpleSAML\Module::getModuleURL('casserver/loggedOut.php'),
87-
array_key_exists('url', $_GET) ? ['url' => $_GET['url']] : [],
88-
),
89-
);
89+
session_cache_limiter('nocache');
90+
$globalConfig = \SimpleSAML\Configuration::getInstance();
91+
$t = new \SimpleSAML\XHTML\Template($globalConfig, 'casserver:loggedOut.twig');
92+
if (!empty($url)) {
93+
$t->data['url'] = $_GET['url'];
94+
}
95+
$t->send();
9096
}
9197
}

0 commit comments

Comments
 (0)