How to configure the XML parser to disable external entity resolution in c#

后端 未结 3 1923
粉色の甜心
粉色の甜心 2020-12-30 04:00
var xDoc = XDocument.Load(fileName);

I am using above code in a function to load an XML file. Functionality wise its working fine but it is showing

3条回答
  •  长情又很酷
    2020-12-30 04:15

    If you are not using external entity references in your XML, you can disable the resolver by setting it to null, from How to prevent XXE attack ( XmlDocument in .net)

    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.XmlResolver = null;
    xmlDoc.LoadXml(OurOutputXMLString);
    

    If you are expecting the document to contain entity references, then you will need to create a custom resolver and whitelist what you are expecting. Especially, any references to websites that you do not control.

提交回复
热议问题