@@ -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