@@ -800,7 +800,7 @@ def doc_to_validate
800800 # If the response contains the signature, and the assertion was encrypted, validate the original SAML Response
801801 # otherwise, review if the decrypted assertion contains a signature
802802 subject_id = RubySaml ::XML ::SignedDocumentValidator . subject_id ( document )
803- return nil unless subject_id
803+ return decrypted_document unless subject_id
804804
805805 sig_elements = document . xpath (
806806 "/p:Response[@ID=$id]/ds:Signature" ,
@@ -858,7 +858,7 @@ def validate_signature
858858 fingerprint_alg : settings . idp_cert_fingerprint_algorithm
859859 }
860860
861- if fingerprint && RubySaml ::XML ::SignedDocumentValidator . validate_document ( doc , fingerprint , @errors , soft : @soft , **opts )
861+ if fingerprint && RubySaml ::XML ::SignedDocumentValidator . validate_document ( doc , fingerprint , @errors , soft : @soft , **opts ) . is_a? ( TrueClass ) # TODO: DANGEROUS
862862 if settings . security [ :check_idp_cert_expiration ] && RubySaml ::Utils . is_cert_expired ( idp_cert )
863863 return append_error ( "IdP x509 certificate expired" )
864864 end
@@ -869,7 +869,7 @@ def validate_signature
869869 valid = false
870870 expired = false
871871 idp_certs [ :signing ] . each do |idp_cert |
872- valid = RubySaml ::XML ::SignedDocumentValidator . validate_document_with_cert ( doc , idp_cert , @errors , soft : @soft )
872+ valid = RubySaml ::XML ::SignedDocumentValidator . validate_document_with_cert ( doc , idp_cert , @errors , soft : @soft ) . is_a? ( TrueClass ) # TODO: DANGEROUS
873873 next unless valid
874874
875875 if settings . security [ :check_idp_cert_expiration ] && RubySaml ::Utils . is_cert_expired ( idp_cert )
@@ -911,29 +911,27 @@ def cached_signed_assertion
911911 empty_doc = Nokogiri ::XML ::Document . new
912912
913913 xml = doc_to_validate
914- dup = doc_to_validate . to_s . dup
915914 return empty_doc if xml . nil?
916915
917- xml = RubySaml ::XML ::SignedDocumentValidator . subject_node ( xml )
916+ subject = RubySaml ::XML ::SignedDocumentValidator . subject_node ( xml )
918917 return empty_doc if xml . nil? # when no signature/reference is found, return empty document
919918
920- root = xml . document . root
921- subject_id = RubySaml ::XML ::SignedDocumentValidator . subject_id ( dup )
919+ subject_id = RubySaml ::XML ::SignedDocumentValidator . subject_id ( xml )
922920 return nil unless subject_id
923921
924- if root [ "ID" ] != subject_id
922+ if subject [ 'ID' ] != subject_id
925923 return empty_doc
926924 end
927925
928926 assertion = empty_doc
929- if root . name == "Response"
930- if ( result = root . at_xpath ( "a:Assertion" , { "a" => RubySaml ::XML ::NS_ASSERTION } ) )
927+ if subject . name == "Response"
928+ if ( result = subject . at_xpath ( "a:Assertion" , { "a" => RubySaml ::XML ::NS_ASSERTION } ) )
931929 assertion = result
932- elsif ( result = root . at_xpath ( "a:EncryptedAssertion" , { "a" => RubySaml ::XML ::NS_ASSERTION } ) )
930+ elsif ( result = subject . at_xpath ( "a:EncryptedAssertion" , { "a" => RubySaml ::XML ::NS_ASSERTION } ) )
933931 assertion = RubySaml ::XML ::Decryptor . decrypt_assertion ( result , settings &.get_sp_decryption_keys )
934932 end
935- elsif root . name == "Assertion"
936- assertion = root
933+ elsif subject . name == "Assertion"
934+ assertion = subject
937935 end
938936
939937 assertion
0 commit comments