Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OWASP HTML Sanitizer cleans comments

I have application where customer can store following html lines in order to load different styles for actual browser:

<!--[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:

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

But after sanitation if browser lines are dropped.

Could you please suggest how to configure policy in order to allow storing such content?

like image 507
fashuser Avatar asked Nov 25 '16 08:11

fashuser


2 Answers

The OWASP Sanitizer can not be configured to accept these tags. Instead you could use a HTML parser like JSoup to extract these lines before santizing, then add them back in afterwards.

like image 175
Ben-JD Avatar answered Oct 16 '22 04:10

Ben-JD


There is Issue #1532: Allow comments to be preserved in HTML. Until that feature request, or a similar one, is completed, this is not possible with the HTML sanitizer.

like image 25
Thunderforge Avatar answered Oct 16 '22 05:10

Thunderforge