将数据保存为 XML 时防止攻击
我们有一个 Web 应用程序,它以 XML 格式保存调查数据,而不是保存到标准数据库。它使用第三方调查组件(实际上, 此组件,但经过修改以添加一些功能)
现在我们正在使用非常严格的白名单验证方法来防止潜在的恶意输入进入调查结果 XML 文件。然而,白名单规则正在变成我们客户的支持问题。他们的限制实在是太严格了,而我想知道我是不是太限制了。我不知道如果有人使用尖括号(未闭合或闭合的 html/xml 标签)等会对 XML 文档产生什么影响。
如果我将这些存储在 CDATA 部分中,然后清理输出将阻止在这些情况下 XML 文档是否损坏?我们确实使用 Microsoft.Anti-Xss 和 Web Protection 库来清理所有不受信任的输出。
更好的是,是否有防止 XML 注入或特定于 XML 数据的 XSS 的指南?或者我只是想太多了?
核心问题是,只要正确清理输出,我是否需要过滤输入?我偏执的本性说是的,但我不确定,我想我应该征求一些专家的意见。
We have a web application that saves survey data in XML format, rather than to a standard database. It uses a third-party survey component (actually, this component, but modified to add some functionality)
Right now we're using a very restrictive white-list validation approach to prevent potentially malicious input from making it into the survey results XML file. However, the white-list rules are turning into a support problem for our customers. They're simply too restrictive, and I'm wondering if I'm simply being too restrictive. I don't know what the effects are on an XML document if someone were to use angled brackets (html/xml tags unclosed or closed), etc.
If I'm storing these in CDATA sections, and then sanitizing the output will that prevent corruption to the XML document in these cases? We do use the Microsoft.Anti-Xss and Web Protection libraries to sanitize all untrusted output.
Better yet, is there a guide to preventing XML injection, or XSS specific to XML data? or am I just over-thinking this?
The core question is, do I need to filter the input as long as I'm sanitizing the output properly? My paranoid nature says yes, but I'm not sure and thought I'd ask for some expert opinions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请查看 OWASP 数据验证指南,了解您需要解决的漏洞是什么。
Check the OWASP Data Validation Guide to understand what the vulnerabilities are that you need to address.
将数据存储到 xml 文件时,假设您自己不是直接写入 xml,则不需要对其进行编码。检索后,您应该对向用户显示的任何内容进行 HTML 编码。建议使用Microsoft Anti-XSS Library 进行编码。
When storing the data to the xml file, you shouldn't need to encode it, assuming you're not writing straight to the xml yourself. Once retrieved, you should HTML encode anything you display to the user. It is recommended to use the Microsoft Anti-XSS Library for the encoding.