ValidateInput(false),但现在如何保持我的 HTML 输入干净?
因此,在 ASP.NET MVC2 应用程序的一部分中,我必须允许来自典型的富文本框的 HTML 输入。因此,我在控制器方法上添加了一个属性来关闭 MVC 的强力输入验证。
但是,现在我该怎么做才能防止 XSS 攻击呢?到目前为止,我已经查看并发现:
- AntiXSS:看起来不错,但白名单似乎不可编辑。另外,由于某种原因,我在使其正常工作时遇到问题。添加对 dll 的引用后,编译器仍然发现缺少程序集。
- Antisamy:允许配置白名单,但 .NET 上次更新是在 2009 年。这并不能激发人们对安全软件的信心。
还有什么?是否有其他库可以清理包含 HTML 的输入,以便轻松配置允许的标签?
So, in a section of an ASP.NET MVC2 app, I have to allow HTML input from a typical rich textbox. So, I added an attribute on the controller method to turn off MVC's brute-force input validation.
But, now what do I do to prevent XSS attacks. So far, I have looked and found:
- AntiXSS: looks good, but the whitelist seems to not be editable. Also, I am having issues getting it to work, for some reason. After adding the reference to the dll, the compiler still sees a missing assembly.
- Antisamy: allows configuration of a whitelist, but the last time the .NET was updated was in 2009. That doesn't inspire confidence in security software.
What else? Are there other libraries for cleaning up HTML-containing input such that it is easy to configure allowable tags?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能会考虑使用 HTML 解析器,沿着解析树遍历,消除有害的标签/属性。您将完全控制允许的内容。根据 这个问题 HTMLAgilityPack 是 C# 的最佳选择。
You might consider using an HTML parser, walking along the parse tree eliminating tags/attributes that are harmful. You would have full control of what was allowed. According to this question HTMLAgilityPack is the best for C#.