Skip to content

Commit 92fae88

Browse files
author
Tessa Bloomer
committed
Suggested edits made
1 parent 9c40592 commit 92fae88

File tree

4 files changed

+24
-23
lines changed

4 files changed

+24
-23
lines changed

src/onelogin/saml2/logout_request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def is_valid(self, request_data, raise_exceptions=False):
314314
if root.get('Destination', None):
315315
destination = root.get('Destination')
316316
if destination != '':
317-
if current_url not in destination:
317+
if OneLogin_Saml2_Utils.normalize_url(current_url) not in OneLogin_Saml2_Utils.normalize_url(destination):
318318
raise OneLogin_Saml2_ValidationError(
319319
'The LogoutRequest was received at '
320320
'%(currentURL)s instead of %(destination)s' %

src/onelogin/saml2/logout_response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def is_valid(self, request_data, request_id=None, raise_exceptions=False):
118118

119119
# Check destination
120120
destination = self.document.get('Destination', None)
121-
if destination and current_url not in destination:
121+
if destination and OneLogin_Saml2_Utils.normalize_url(current_url) not in OneLogin_Saml2_Utils.normalize_url(destination):
122122
raise OneLogin_Saml2_ValidationError(
123123
'The LogoutResponse was received at %s instead of %s' % (current_url, destination),
124124
OneLogin_Saml2_ValidationError.WRONG_DESTINATION

src/onelogin/saml2/response.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def is_valid(self, request_data, request_id=None, raise_exceptions=False):
192192
# Checks destination
193193
destination = self.document.get('Destination', None)
194194
if destination:
195-
if not self.__normalize_url(destination).startswith(self.__normalize_url(current_url)):
195+
if not OneLogin_Saml2_Utils.normalize_url(destination).startswith(OneLogin_Saml2_Utils.normalize_url(current_url)):
196196
# TODO: Review if following lines are required, since we can control the
197197
# request_data
198198
# current_url_routed = OneLogin_Saml2_Utils.get_self_routed_url_no_query(request_data)
@@ -867,26 +867,6 @@ def __decrypt_assertion(self, xml):
867867
xml.replace(encrypted_assertion_nodes[0], decrypted)
868868
return xml
869869

870-
def __normalize_url(self, url):
871-
"""
872-
Returns normalized URL for comparison.
873-
This method converts the netloc to lowercase, as it should be case-insensitive (per RFC 4343, RFC 7617)
874-
If standardization fails, the original URL is returned
875-
Python documentation indicates that URL split also normalizes query strings if empty query fields are present
876-
877-
:param url: URL
878-
:type url: String
879-
880-
:returns: A normalized URL, or the given URL string if parsing fails
881-
:rtype: list
882-
"""
883-
try:
884-
scheme, netloc, *rest = urlsplit(url)
885-
normalized_url = urlunsplit((scheme.lower(), netloc.lower(), *rest))
886-
return normalized_url
887-
except Exception:
888-
return url
889-
890870
def get_error(self):
891871
"""
892872
After executing a validation process, if it fails this method returns the cause

src/onelogin/saml2/utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,3 +1062,24 @@ def validate_binary_sign(signed_query, signature, cert=None, algorithm=OneLogin_
10621062
if debug:
10631063
print(e)
10641064
return False
1065+
1066+
@staticmethod
1067+
def normalize_url(self, url):
1068+
"""
1069+
Returns normalized URL for comparison.
1070+
This method converts the netloc to lowercase, as it should be case-insensitive (per RFC 4343, RFC 7617)
1071+
If standardization fails, the original URL is returned
1072+
Python documentation indicates that URL split also normalizes query strings if empty query fields are present
1073+
1074+
:param url: URL
1075+
:type url: String
1076+
1077+
:returns: A normalized URL, or the given URL string if parsing fails
1078+
:rtype: String
1079+
"""
1080+
try:
1081+
scheme, netloc, *rest = urlsplit(url)
1082+
normalized_url = urlunsplit((scheme.lower(), netloc.lower(), *rest))
1083+
return normalized_url
1084+
except Exception:
1085+
return url

0 commit comments

Comments
 (0)