@@ -745,7 +745,7 @@ public function getAttributesWithFriendlyName()
745745 return $ this ->_getAttributesByKeyName ('FriendlyName ' );
746746 }
747747
748- private function _getAttributesByKeyName ($ keyName= "Name " )
748+ private function _getAttributesByKeyName ($ keyName = "Name " )
749749 {
750750 $ attributes = array ();
751751 $ entries = $ this ->_queryAssertion ('/saml:AttributeStatement/saml:Attribute ' );
@@ -1090,12 +1090,17 @@ protected function decryptAssertion(\DomNode $dom)
10901090 $ objKey ->loadKey ($ key );
10911091 }
10921092
1093- $ decrypted = $ objenc ->decryptNode ($ objKey , true );
1094-
1095- if ($ decrypted instanceof DOMDocument) {
1093+ $ decryptedXML = $ objenc ->decryptNode ($ objKey , false );
1094+ $ decrypted = new DOMDocument ();
1095+ $ check = Utils::loadXML ($ decrypted , $ decryptedXML );
1096+ if ($ check === false ) {
1097+ throw new Exception ('Error: string from decrypted assertion could not be loaded into a XML document ' );
1098+ }
1099+ if ($ encData ->parentNode instanceof DOMDocument) {
10961100 return $ decrypted ;
10971101 } else {
1098- $ encryptedAssertion = $ decrypted ->parentNode ;
1102+ $ decrypted = $ decrypted ->documentElement ;
1103+ $ encryptedAssertion = $ encData ->parentNode ;
10991104 $ container = $ encryptedAssertion ->parentNode ;
11001105
11011106 // Fix possible issue with saml namespace
@@ -1112,13 +1117,14 @@ protected function decryptAssertion(\DomNode $dom)
11121117 } else {
11131118 $ ns = 'xmlns ' ;
11141119 }
1115-
11161120 $ decrypted ->setAttributeNS ('http://www.w3.org/2000/xmlns/ ' , $ ns , Constants::NS_SAML );
11171121 }
11181122
1119- $ container -> replaceChild ( $ decrypted , $ encryptedAssertion );
1123+ Utils:: treeCopyReplace ( $ encryptedAssertion , $ decrypted );
11201124
1121- return $ decrypted ->ownerDocument ;
1125+ // Rebuild the DOM will fix issues with namespaces as well
1126+ $ dom = new DOMDocument ();
1127+ return Utils::loadXML ($ dom , $ container ->ownerDocument ->saveXML ());
11221128 }
11231129 }
11241130
0 commit comments