简体   繁体   English

OWASP HTML Sanitizer清除评论

[英]OWASP HTML Sanitizer cleans comments

I have application where customer can store following html lines in order to load different styles for actual browser: 我有应用程序,客户可以存储以下html行,以便为实际浏览器加载不同的样式:

<!--[if IE 6]><link rel="stylesheet" type="text/css" media="all" href="default/css/general_ie6.css"><![endif]--> 
<!--[if IE 7]><link rel="stylesheet" type="text/css" media="all" href="default/css/general_ie7.css"><![endif]--> 
<!--[if IE 8]><link rel="stylesheet" type="text/css" media="all" href="default/css/general_ie8.css"><![endif]--> 

Also I've configured OWASP policy to disallow malicious html tags in following way: 我还配置了OWASP policy以便以下列方式禁止恶意html标记:

new HtmlPolicyBuilder().allowElements("link").allowAttributes("rel", "type", "media", "href").onElements("link").toFactory();

But after sanitation if browser lines are dropped. 但在卫生设施之后, if browser lines被丢弃。

Could you please suggest how to configure policy in order to allow storing such content? 您能否建议如何配置策略以便存储此类内容?

The OWASP Sanitizer can not be configured to accept these tags. OWASP Sanitizer无法配置为接受这些标记。 Instead you could use a HTML parser like JSoup to extract these lines before santizing, then add them back in afterwards. 相反,你可以使用像JSoup这样的HTML解析器在santizing之前提取这些行,然后再添加它们。

There is Issue #1532: Allow comments to be preserved in HTML . 问题#1532:允许在HTML中保留注释 Until that feature request, or a similar one, is completed, this is not possible with the HTML sanitizer. 在完成该功能请求或类似功能请求之前,HTML清理程序无法做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM