Skip to content

Commit 96dd9ef

Browse files
committed
Update changelog. Apply strict destination matching also on logout request and logout response
1 parent b962da1 commit 96dd9ef

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ CHANGELOG
22
=========
33
v.2.18.0
44
* Support rejecting unsolicited SAMLResponses.
5+
* Support stric destination matching.
56
* Reject SAMLResponse if requestID was provided to the validotr but the InResponseTo attributeof the SAMLResponse is missing
67
* Check destination against the getSelfURLNoQuery as well on LogoutRequest and LogoutResponse as we do on Response
78
* Improve getSelfRoutedURLNoQuery method

lib/Saml2/LogoutRequest.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -365,15 +365,26 @@ public function isValid($retrieveParametersFromServer = false)
365365
// Check destination
366366
if ($dom->documentElement->hasAttribute('Destination')) {
367367
$destination = $dom->documentElement->getAttribute('Destination');
368-
if (!empty($destination) && strpos($destination, $currentURL) !== 0) {
369-
$currentURLNoRouted = OneLogin_Saml2_Utils::getSelfURLNoQuery();
370-
371-
if (strpos($destination, $currentURLNoRouted) !== 0) {
368+
if (empty($destination)) {
369+
if (!$security['relaxDestinationValidation']) {
372370
throw new OneLogin_Saml2_ValidationError(
373-
"The LogoutRequest was received at $currentURL instead of $destination",
374-
OneLogin_Saml2_ValidationError::WRONG_DESTINATION
371+
"The LogoutRequest has an empty Destination value",
372+
OneLogin_Saml2_ValidationError::EMPTY_DESTINATION
375373
);
376374
}
375+
} else {
376+
$urlComparisonLength = $security['destinationStrictlyMatches'] ? strlen($destination) : strlen($currentURL);
377+
if (strncmp($destination, $currentURL, $urlComparisonLength) !== 0) {
378+
$currentURLNoRouted = OneLogin_Saml2_Utils::getSelfURLNoQuery();
379+
$urlComparisonLength = $security['destinationStrictlyMatches'] ? strlen($destination) : strlen($currentURLNoRouted);
380+
381+
if (strncmp($destination, $currentURLNoRouted, $urlComparisonLength) !== 0) {
382+
throw new OneLogin_Saml2_ValidationError(
383+
"The LogoutRequest was received at $currentURL instead of $destination",
384+
OneLogin_Saml2_ValidationError::WRONG_DESTINATION
385+
);
386+
}
387+
}
377388
}
378389
}
379390

lib/Saml2/LogoutResponse.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,26 @@ public function isValid($requestId = null, $retrieveParametersFromServer = false
161161
// Check destination
162162
if ($this->document->documentElement->hasAttribute('Destination')) {
163163
$destination = $this->document->documentElement->getAttribute('Destination');
164-
if (!empty($destination) && strpos($destination, $currentURL) !== 0) {
165-
$currentURLNoRouted = OneLogin_Saml2_Utils::getSelfURLNoQuery();
166-
167-
if (strpos($destination, $currentURLNoRouted) !== 0) {
164+
if (empty($destination)) {
165+
if (!$security['relaxDestinationValidation']) {
168166
throw new OneLogin_Saml2_ValidationError(
169-
"The LogoutResponse was received at $currentURL instead of $destination",
170-
OneLogin_Saml2_ValidationError::WRONG_DESTINATION
167+
"The LogoutResponse has an empty Destination value",
168+
OneLogin_Saml2_ValidationError::EMPTY_DESTINATION
171169
);
172170
}
171+
} else {
172+
$urlComparisonLength = $security['destinationStrictlyMatches'] ? strlen($destination) : strlen($currentURL);
173+
if (strncmp($destination, $currentURL, $urlComparisonLength) !== 0) {
174+
$currentURLNoRouted = OneLogin_Saml2_Utils::getSelfURLNoQuery();
175+
$urlComparisonLength = $security['destinationStrictlyMatches'] ? strlen($destination) : strlen($currentURLNoRouted);
176+
177+
if (strncmp($destination, $currentURLNoRouted, $urlComparisonLength) !== 0) {
178+
throw new OneLogin_Saml2_ValidationError(
179+
"The LogoutResponse was received at $currentURL instead of $destination",
180+
OneLogin_Saml2_ValidationError::WRONG_DESTINATION
181+
);
182+
}
183+
}
173184
}
174185
}
175186

0 commit comments

Comments
 (0)