适用于 .NET 的 HTML 清理工具
我正在启动一个使用 asp.net mvc 面向公众的项目。 我知道大约有 10 亿个 php、python 和 ruby html 清理程序,但是有人能指出 .net 中的任何好东西吗? 您对外面的事物有什么经验? 我知道 stackoverflow 是一个用 asp.net 完成的网站,允许自由格式的 HTML,它使用什么?
I'm starting a project that will be public facing using asp.net mvc. I know there are about a billion php, python, and ruby html sanitizers out there, but does anyone have some pointers to anything good in .net? What are your experiences with what is out there? I know stackoverflow is a site done in asp.net that allows freeform HTML, what does it use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
HtmlSanitizer
来源:https://github.com/mganss/HtmlSanitizer
一个相当强大的消毒剂。 它理解并可以清理内联样式,但没有可以处理
HtmlSanitizer
Source: https://github.com/mganss/HtmlSanitizer
A fairly robust sanitizer. It understands and can clean inline styles, but doesn't have a parser that can deal with <style> blocks, so it strips them. It's certainly up to and probably beyond the level that Microsoft's AntiXSS was at, before it was abandoned.
https://blog.stackoverflow.com/2008/06/safe-html-and-xss /
https://blog.stackoverflow.com/2008/06/safe-html-and-xss/
HtmlRuleSanitizer
根据您的问题,我有以下建议:
我遇到了同样的问题,并构建了 HtmlRuleSanitizer,它是基于 Html Agility Pack 之上的基于白名单规则的 HTML 清理程序。
HtmlRuleSanitizer
Based on your question I have the following suggestions:
I faced the same problem and built HtmlRuleSanitizer which is a white listing rule based HTML sanitizer on top of the Html Agility Pack.
这里有 c# 版本
there is a c# version here
这是微软构建的一个。 http://wpl.codeplex.com/
Here is one built by microsoft. http://wpl.codeplex.com/
我们还可以使用
AntiXss.GetSafeHtmlFragments
通过解析 HTML 片段来清理输入,使用此清理程序来处理丰富的内容,以确保它不包含任何有害脚本,并且可以安全地显示在浏览器上。对于文本输入(不丰富)内容)以使用 AntiXss.HtmlEncode 或任何其他等效的 html 编码器。这是丰富内容的示例。
注意:从 nugetpackage 管理器下载 AntiXSS 库并包含此名称空间
源代码中的Microsoft.Security.Application;
We can also use
AntiXss.GetSafeHtmlFragments
sanitize input by parsing the HTML fragment,to use this sanitizer for rich content to ensure that it does not content any harmful script and it is safe to be displayed on the browser.For the text input(not rich content) to use AntiXss.HtmlEncode or any other equivalent html encoder.Here is the Sample for rich content.
Note: Download AntiXSS library fron nugetpackage manager and include this namesapce
Microsoft.Security.Application in the souce code;