HtmlSanitizer icon indicating copy to clipboard operation
HtmlSanitizer copied to clipboard

Sanitizer does not remove comment but converts it to plain html

Open Sicos1977 opened this issue 1 year ago • 6 comments

I use the latest version from nuget (not a beta version). When sanitizing the attached HTML it does not remove the comment that is between the javascript tags but for some reason it is converted to plain html.

image

comment.zip

Sicos1977 avatar Sep 27 '23 13:09 Sicos1977

What is your configuration? The HTML comment syntax used inside a script element does not create HTML comments but they become part of the script's text.

mganss avatar Sep 27 '23 15:09 mganss

What do you mean with configuration? I don't understand that question.

The HTML is coming from an e-mail that is sent to us from a customer. We convert that e-mail to PDF but sanitize it before doing so.

Sicos1977 avatar Sep 27 '23 16:09 Sicos1977

Sorry, I should have been more clear. By configuration I mean how have you initialized the HtmlSanitizer object, which elements have you allowed in AllowedTags etc.

mganss avatar Sep 27 '23 16:09 mganss

This is the code --> https://github.com/Sicos1977/ChromiumHtmlToPdf/blob/master/ChromiumHtmlToPdfLib/Helpers/DocumentHelper.cs it starts at line 189 and this are the settings.

Sorry for the Dutch comments.

a minus sign means first remove everything and then add the rows below the sign an asterix ( * ) means use default settings and the lines after it means add those to the default settings

image

Sicos1977 avatar Sep 28 '23 06:09 Sicos1977

I can't reproduce. AFAICT you are using HtmlSanitizer in the default configuration (default allowed tags, attributes etc). In that configuration, the script tag is disallowed and should be removed (including its content). Can you provide a minimal example that shows the issue?

mganss avatar Sep 28 '23 11:09 mganss

Sorry for the late response, I got side tracked by other things so I have to look into this again.

Sicos1977 avatar Oct 25 '23 13:10 Sicos1977