-
Notifications
You must be signed in to change notification settings - Fork 334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for conditional HTML commenting e.g. <!--[if mso]>
#379
Comments
This is because of htmlpurifier/library/HTMLPurifier/Lexer.php Line 277 in 6eb6123
Conditional comments are only supported by IE 5 - 9, so lack of support only really affects a tiny minority of people? |
These conditionals are automatically inserted by a service that some of our users use to build email HTML documents. I'm guessing the service is including these conditionals in order to support older email clients. It would be really nice if these conditional comments didn't unavoidably break a HTML document that's been passed through HTMLPurifier, as it seems they are still in use sometimes in modern browsers and email clients for maximum backwards compatibility. If it's easy enough to implement, could that be made optional? |
Conditional comments are still used extensively in email to target Outlook clients. Why do we even need to remove these? If you simply remove all comments, then conditional comments will get removed also. The problem with
Unfortunately, HTMLPurifier removes both of these so neither one is displayed. I suggest getting rid of diff --git a/library/HTMLPurifier/Lexer.php b/library/HTMLPurifier/Lexer.php
index 1f552a17..bbe47769 100644
--- a/library/HTMLPurifier/Lexer.php
+++ b/library/HTMLPurifier/Lexer.php
@@ -277,7 +277,7 @@ class HTMLPurifier_Lexer
protected static function removeIEConditional($string)
{
return preg_replace(
- '#<!--\[if [^>]+\]>.*?<!\[endif\]-->#si', // probably should generalize for all strings
+ '#<!--\[if (?!!)[^>]+\]>.*?<!\[endif\]-->#si', // probably should generalize for all strings
'',
$string
); Currently I'm working around the issue by removing all HTML comments before passing to HTMLPurifier. |
I'm unlikely to ever merge PRs that add support for this, because the conditional comment syntax is not well specified and I don't have time to exactly reverse engineer how it is actually implemented to ensure it can't be used as the basis for an XSS bypass. |
I agree with you. That's why I think the best course of action is to eliminate It's not necessary to remove conditional comments because HTMLPurifier removes all comments by default. Conditional comments are just specially formatted HTML comments. I submitted PR #401 that includes a unit test to demonstrate that conditional comments are converted to objects of By doing it this way:
The title of this issue could be changed from Support for conditional HTML commenting to Remove special handling of conditional HTML commenting |
Thanks for merging the PR. I think that fixes the issue. Although conditional comments are still not supported by HTMLPurifier, users can opt to allow them with this regexp:
|
The syntax specified here for conditional Outlook CSS does not seem to be compatible with HTMLPurifier, everything inside the conditional comment will be removed.
The simplified version of the syntax I'm trying to use is:
As these are HTML comments, I initially thought I might be able to use the
HTML.AllowedComments
config option, however it does not have an option to allow ALL comments. The exact comment body has to be specified, which will not work for this use case as the content is not always known.I next tried
HTML.AllowedCommentsRegexp
with a regexp that should allow everything:However this also does not work. It seems that in the
<!--[if mso]>
comment marker, the non-standard[if mso]
seems to cause the comment to be removed regardless.Is there a way to support this syntax currently or is it not possible?
Thank you for any help!
The text was updated successfully, but these errors were encountered: