- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
因此,当我对我的应用程序运行安全扫描时遇到了问题。 It turns out that I am failing to protect against XXE .这是一个显示有问题的代码的简短片段:
static void Main()
{
string inp = Console.ReadLine();
string xmlStr = ""; //This has a value that is much too long to put into a single post
if (!string.IsNullOrEmpty(inp))
{
xmlStr = inp;
}
XmlDocument xmlDocObj = new XmlDocument {XmlResolver = null};
xmlDocObj.LoadXml(xmlStr);
XmlNodeList measureXmlNodeListObj = xmlDocObj.SelectNodes("REQ/MS/M");
foreach (XmlNode measureXmlNodeObj in measureXmlNodeListObj)
{
XmlNode detailXmlNodeListObj = xmlDocObj.SelectSingleNode("REQ/DTD");
string measureKey = measureXmlNodeObj.Attributes["KY"].Value;
if (detailXmlNodeListObj.Attributes["MKY"].Value ==
measureKey) //Checking if selected MeasureKey is same
{
XmlNode filerNode = measureXmlNodeObj.SelectSingleNode("FS");
if (filerNode != null)
{
XDocument fixedFilterXmlObj = XDocument.Load(new StringReader(filerNode.OuterXml));
var measureFixedFilters = (from m in fixedFilterXmlObj.Element("FS").Elements("F")
select m).ToList();
foreach (var fixedFilter in measureFixedFilters)
{
var fixedFilterValues = (from m in fixedFilter.Elements("VS").Elements("V")
select m.Attribute("DESC").Value).ToList();
foreach (var value in fixedFilterValues)
{
Console.WriteLine(value.Trim());
}
}
}
}
}
Console.ReadLine();
}
根据 Veracode,不安全的行是 XDocument fixedFilterXmlObj = XDocument.Load(new StringReader(filerNode.OuterXml));
但根据 Owsap 看来,it should be safe :
Both the XElement and XDocument objects in the System.Xml.Linq library are safe from XXE injection by default. XElement parses only the elements within the XML file, so DTDs are ignored altogether. XDocument has DTDs disabled by default, and is only unsafe if constructed with a different unsafe XML parser.
所以看起来我犯了错误,使用了 usafe XML 解析器,打开 XDocument
到 XXE。
I found a unit test that replicates the issue并且还可以安全使用 XDocument
但我似乎无法找到我的代码到底有什么不安全的,因为我不使用:
XmlReaderSettings settings = new XmlReaderSettings();
settings.DtdProcessing = DtdProcessing.Parse; // unsafe!
您可以运行我的代码来重现该问题,但您应该将空 xmlStr 行替换为以下值:here (对于一个帖子来说太大了)
最佳答案
我不确定它是如何或为什么起作用的,但确实如此:
XDocument fixedFilterXmlObj;
using (XmlNodeReader nodeReader = new XmlNodeReader(filerNode))
{
nodeReader.MoveToContent();
fixedFilterXmlObj = XDocument.Load(nodeReader);
}
关于c# - XXE:使用 XDocument 对 XML 外部实体引用的不当限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46304092/
XXE安全威胁目前没有。在 OWASP 十大 Web 应用程序安全威胁列表中排名第 4,因此我希望 Java 标准 XML 库能够防止此类攻击。但是,当我以 Sonar 推荐的方式使用 Validat
我有格式如下的excel数据单元格: 需要在同一个单元格中同时包含数字和括号内的数字。 我希望再创建四个单元格,其中包含每个单元格对非支持数字总和的百分比贡献。 即第一个新单元格中的总和需要为 3e-
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 去年关闭。 Improve this
为了防止 XXE 攻击,我已按照 Java DocumentBuilderFactory 的建议禁用了以下功能 - https://www.owasp.org/index.php/XML_Extern
我在 fortify 报告中收到第 4 行的 XML 外部实体注入(inject)安全警告。不知道如何解决它。我对 SOAP、JAXB 和 Marshaller 还很陌生。 1 private
我在 veracode 报告中得到了下一个发现:XML 外部实体引用(“XXE”)的不当限制(CWE ID 611) 引用下面的下一个代码 ... DocumentBuilderFactory d
是否可以对 Javascript 进行 XXE 攻击(或者至少有意义)?这就是,当尝试用JS解析XML时,它是否处理外部实体?但是这个解析是在客户端执行的,对吗?它会对服务器造成什么危害? 我们如何防
这是关于在使用 JAXB API 时避免 XXE 攻击。据我了解,使用 JAXB 时,可以覆盖默认解析机制,并且可以使用备用 SAX 解析器并设置实体功能以避免 XXE 攻击。但想了解默认解析器到底是
我们使用 javax.xml.parsers.SAXParserFactory 读取我们的 XML 模板文件。如果我们正在读取的 XML 文件中存在 XXE,是否有办法关闭对它的处理? 谢谢 - 戴夫
我的 Veracode 报告中有下一个发现:XML 外部实体引用 ('XXE') (CWE ID 611) 的不当限制 引用下面的下一个代码 ... DocumentBuilderFactory
我有几个 SonarQube 漏洞,其中一个引起了我的注意。 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); tr
想知道如何使用 Xstream API 修复 Xml EXternal Entity (XXE) 漏洞。 就像我们能做的 // This is the PRIMARY defense. If DTDs
要求:当我将以下请求传递给我的应用程序时, 1)如何对这种存在风险的输入xml进行XML验证 2) 如何在 libxml2 中禁用 XXE,即不应该解析 ENTITY 字段 ]> LINE_ITE
用 Java 解析 XML 变得非常简单。大多数代码最终会调用 DocumentBuilderFactory.newInstance(),它返回易受 XXE kind of attacks by de
作为最后的手段,我在这里发布了一个问题,我浏览了网页并进行了多次尝试但没有成功。 复制 XXE 攻击是我试图做的,以防止它们,但我似乎无法理解 PHP 处理 XML 实体的方式。作为记录,我在 Ubu
最近,我们对我们的代码进行了安全审计,其中一个问题是我们的应用程序受到了 Xml eXternal Entity (XXE) 攻击。 基本上,该应用程序是一个计算器,通过 Web 服务接收 XML 格
我们要处理的XML消息的格式是这样的: .... 收到异常: javax.xml.bind.UnmarshalException: unexpected el
这些代码行导致 xxe 漏洞出现在 Checkmarx 报告中: InputStream is = connection.getInputStream(); XMLInputFactory facto
我使用非验证读取来显示或处理不受信任的 XML 文档,我不需要支持内部实体,但我确实希望能够处理,即使显示了 DOCTYPE。 随着disallow DOCTYPE-decl feature SAX
我们对代码进行了安全审核,他们提到我们的代码容易受到外部实体 (XXE) 攻击。我正在使用以下代码 - string OurOutputXMLString= "00000Logince_useridc
我是一名优秀的程序员,十分优秀!