Skip to content

Commit abd69f0

Browse files
committed
Merge pull request #131 from onelogin/revert-113-108-get-assertion-when-empty-signature-ref-uri
Revert "Get/validate assertion when empty Response signature ref URI"
2 parents e0bb871 + c12d308 commit abd69f0

4 files changed

Lines changed: 8 additions & 36 deletions

File tree

src/onelogin/saml2/response.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,8 @@ def __query_assertion(self, xpath_expr):
417417
# Check if the message is signed
418418
signed_message_query = '/samlp:Response' + signature_expr
419419
message_reference_nodes = self.__query(signed_message_query)
420-
# we can have reference node but URI can be empty
421-
message_id = None
422420
if message_reference_nodes:
423421
message_id = message_reference_nodes[0].get('URI')
424-
if message_id:
425422
final_query = "/samlp:Response[@ID='%s']/" % message_id[1:]
426423
else:
427424
final_query = "/samlp:Response"

src/onelogin/saml2/utils.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,15 +1051,17 @@ def validate_node_sign(signature_node, elem, cert=None, fingerprint=None, finger
10511051
if fingerprint == x509_fingerprint_value:
10521052
cert = OneLogin_Saml2_Utils.format_cert(x509_cert_value)
10531053

1054-
# Check if Reference URI is empty
1055-
reference_elem = OneLogin_Saml2_Utils.query(signature_node, '//ds:Reference')
1056-
if len(reference_elem) > 0:
1057-
if reference_elem[0].get('URI') == '':
1058-
reference_elem[0].set('URI', '#%s' % signature_node.getparent().get('ID'))
1059-
10601054
if cert is None or cert == '':
10611055
return False
10621056

1057+
# Check if Reference URI is empty
1058+
reference_elem = OneLogin_Saml2_Utils.query(signature_node, '//ds:Reference')
1059+
if len(reference_elem) > 0:
1060+
if reference_elem[0].get('URI') == '':
1061+
reference_elem[0].set('URI', '#%s' % signature_node.getparent().get('ID'))
1062+
1063+
dsig_ctx = xmlsec.DSigCtx()
1064+
10631065
file_cert = OneLogin_Saml2_Utils.write_temp_file(cert)
10641066

10651067
if validatecert:

tests/data/responses/valid_response_with_unsigned_assertion.xml.base64

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/src/OneLogin/saml2_tests/response_test.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -207,26 +207,6 @@ def testQueryAssertions(self):
207207
response_7 = OneLogin_Saml2_Response(settings, xml_7)
208208
self.assertEqual(['http://idp.example.com/'], response_7.get_issuers())
209209

210-
def testQueryAssertionsWithEmptyRefenceURI(self):
211-
"""
212-
Tests the __query_assertion if //Signature/Reference/@URI is empty.
213-
"""
214-
settings = OneLogin_Saml2_Settings(self.loadSettingsJSON())
215-
216-
# test with signed assertion still work
217-
xml = self.file_contents(join(self.data_path, 'responses', 'valid_response.xml.base64'))
218-
response = OneLogin_Saml2_Response(settings, xml)
219-
self.assertEqual('492882615acf31c8096b627245d76ae53036c090', response.get_nameid())
220-
221-
# test with unsigned assertion still work
222-
xml = self.file_contents(join(self.data_path, 'responses', 'valid_response_with_unsigned_assertion.xml.base64'))
223-
response = OneLogin_Saml2_Response(settings, xml)
224-
self.assertEqual('492882615acf31c8096b627245d76ae53036c090', response.get_nameid())
225-
226-
xml = self.file_contents(join(self.data_path, 'responses', 'response_without_reference_uri.xml.base64'))
227-
response = OneLogin_Saml2_Response(settings, xml)
228-
self.assertEqual('saml@user.com', response.get_nameid())
229-
230210
def testGetIssuers(self):
231211
"""
232212
Tests the get_issuers method of the OneLogin_Saml2_Response
@@ -1218,12 +1198,6 @@ def testIsValidSignWithEmptyReferenceURI(self):
12181198
response = OneLogin_Saml2_Response(settings, xml)
12191199
self.assertTrue(response.is_valid(self.get_request_data()))
12201200

1221-
def testIsValidSignWithEmptyReferenceURIAndIdPCert(self):
1222-
settings = OneLogin_Saml2_Settings(self.loadSettingsJSON())
1223-
xml = self.file_contents(join(self.data_path, 'responses', 'valid_response_with_unsigned_assertion.xml.base64'))
1224-
response = OneLogin_Saml2_Response(settings, xml)
1225-
self.assertTrue(response.is_valid(self.get_request_data()))
1226-
12271201
def testIsValidWithoutInResponseTo(self):
12281202
"""
12291203
If assertion contains InResponseTo but not the Response tag, we should

0 commit comments

Comments
 (0)