DTD prohibited in xml document exception

前端 未结 4 524
星月不相逢
星月不相逢 2020-11-29 06:00

I\'m getting this error when trying to parse through an XML document in a C# application:

\"For security reasons DTD is prohibited in this XML documen

4条回答
  •  粉色の甜心
    2020-11-29 06:12

    Note that settings.ProhibitDtd is now obsolete, use DtdProcessing instead: (new options of Ignore, Parse, or Prohibit)

    XmlReaderSettings settings = new XmlReaderSettings();
    settings.DtdProcessing = DtdProcessing.Parse;
    

    and as stated in this post: How does the billion laughs XML DoS attack work?

    you should add a limit to the number of characters to avoid DoS attacks:

    XmlReaderSettings settings = new XmlReaderSettings();
    settings.DtdProcessing = DtdProcessing.Parse;
    settings.MaxCharactersFromEntities = 1024;
    

提交回复
热议问题