@@ -27,11 +27,15 @@ public class XmlClient : BaseClient
2727 static XmlClient ( )
2828 {
2929 // load the SOAP envelope document.
30- mSoapEnvelope = new XmlDocument ( ) ;
31-
32-
33-
34- mSoapEnvelope . LoadXml ( SOAP_ENVELOPE ) ;
30+ mSoapEnvelope = new XmlDocument ( ) ;
31+
32+ // Fix for Xml external entity injection violation in fortify report
33+ XmlReaderSettings settings = new XmlReaderSettings ( ) ;
34+ settings . DtdProcessing = DtdProcessing . Prohibit ;
35+ settings . XmlResolver = null ;
36+ XmlReader reader = XmlReader . Create ( new StringReader ( SOAP_ENVELOPE ) , settings ) ;
37+
38+ mSoapEnvelope . Load ( reader ) ;
3539 }
3640
3741 private XmlClient ( ) { }
@@ -90,7 +94,7 @@ public static XmlDocument RunTransaction(
9094 X509Certificate2 cybsCert = null ;
9195
9296 X509Certificate2Collection collection = new X509Certificate2Collection ( ) ;
93- collection . Import ( keyFilePath , config . EffectivePassword , X509KeyStorageFlags . Exportable | X509KeyStorageFlags . PersistKeySet ) ;
97+ collection . Import ( keyFilePath , config . EffectivePassword , X509KeyStorageFlags . MachineKeySet | X509KeyStorageFlags . Exportable | X509KeyStorageFlags . PersistKeySet ) ;
9498
9599 foreach ( X509Certificate2 cert1 in collection )
96100 {
@@ -262,9 +266,18 @@ private static void SignDocument(X509Certificate2 cert, XmlDocument doc)
262266
263267 doc . DocumentElement . FirstChild . FirstChild . AppendChild ( doc . ImportNode ( xmlDigitalSignature , true ) ) ;
264268
265- // Add KeyInfo Node with reference to the X509 cert
269+ // Add KeyInfo Node with reference to the X509 cert
270+ string keyInfoTags = "<root xmlns:ds=\" http://www.w3.org/2000/09/xmldsig#\" xmlns:wsse=\" http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" ><ds:KeyInfo><SecurityTokenReference xmlns=\" http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" ><wsse:Reference URI=\" #X509Token\" ValueType=\" http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3\" /></SecurityTokenReference></ds:KeyInfo></root>" ;
266271 XmlDocument keyInfo = new XmlDocument ( ) ;
267- keyInfo . LoadXml ( "<root xmlns:ds=\" http://www.w3.org/2000/09/xmldsig#\" xmlns:wsse=\" http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" ><ds:KeyInfo><SecurityTokenReference xmlns=\" http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" ><wsse:Reference URI=\" #X509Token\" ValueType=\" http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3\" /></SecurityTokenReference></ds:KeyInfo></root>" ) ;
272+
273+ // Fix for Xml external entity injection violation in fortify report
274+ XmlReaderSettings settings = new XmlReaderSettings ( ) ;
275+ settings . DtdProcessing = DtdProcessing . Prohibit ;
276+ settings . XmlResolver = null ;
277+ XmlReader reader = XmlReader . Create ( new StringReader ( keyInfoTags ) , settings ) ;
278+
279+ //keyInfo.LoadXml("<root xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\" xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" ><ds:KeyInfo><SecurityTokenReference xmlns=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\"><wsse:Reference URI=\"#X509Token\" ValueType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3\"/></SecurityTokenReference></ds:KeyInfo></root>");
280+ keyInfo . Load ( reader ) ;
268281 doc . DocumentElement . FirstChild . FirstChild . LastChild . AppendChild ( doc . ImportNode ( keyInfo . FirstChild . FirstChild , true ) ) ;
269282
270283 //Add The Base64 representation of the X509 cert to BinarySecurityToken Node
@@ -283,7 +296,14 @@ private static void encryptDocument(X509Certificate2 cert, XmlDocument doc)
283296 "<xenc:ReferenceList><xenc:DataReference URI=\" #Body\" ></xenc:DataReference></xenc:ReferenceList></xenc:EncryptedKey></root>" ;
284297
285298 XmlDocument encryptedDataTags = new XmlDocument ( ) ;
286- encryptedDataTags . LoadXml ( encData ) ;
299+
300+ // Fix for Xml external entity injection violation in fortify report
301+ XmlReaderSettings settings = new XmlReaderSettings ( ) ;
302+ settings . DtdProcessing = DtdProcessing . Prohibit ;
303+ settings . XmlResolver = null ;
304+ XmlReader reader = XmlReader . Create ( new StringReader ( encData ) , settings ) ;
305+
306+ encryptedDataTags . Load ( reader ) ;
287307 doc . DocumentElement . FirstChild . FirstChild . PrependChild ( doc . ImportNode ( encryptedDataTags . FirstChild . FirstChild , true ) ) ;
288308
289309 XmlElement elementToEncrypt = doc . GetElementsByTagName ( REQUEST_MESSAGE ) [ 0 ] as XmlElement ;
@@ -403,11 +423,17 @@ private static XmlDocument ReadXml(WebResponse webResponse)
403423 {
404424 Stream stream = null ;
405425 try
406- {
407- XmlDocument xmlDoc = new XmlDocument ( ) ;
408- xmlDoc . PreserveWhitespace = true ;
409- stream = webResponse . GetResponseStream ( ) ;
410- xmlDoc . Load ( stream ) ;
426+ {
427+ XmlDocument xmlDoc = new XmlDocument ( ) ;
428+ xmlDoc . PreserveWhitespace = true ;
429+ stream = webResponse . GetResponseStream ( ) ;
430+
431+ // Fix for Xml external entity injection violation in fortify report
432+ XmlReaderSettings settings = new XmlReaderSettings ( ) ;
433+ settings . DtdProcessing = DtdProcessing . Prohibit ;
434+ settings . XmlResolver = null ;
435+ XmlReader reader = XmlReader . Create ( stream , settings ) ;
436+ xmlDoc . Load ( reader ) ;
411437 return ( xmlDoc ) ;
412438 }
413439 finally
0 commit comments