Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HtmlSanitizer] Node renderer does not account for HTML5 void elements #46258

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

Closed
omniError opened this issue May 4, 2022 · 1 comment · Fixed by #46274
Closed

[HtmlSanitizer] Node renderer does not account for HTML5 void elements #46258

omniError opened this issue May 4, 2022 · 1 comment · Fixed by #46274

Comments

@omniError
Copy link
Contributor

Symfony version(s) affected

6.1.0-beta2

Description

The render() method in the HtmlSanitizer's Visitor\Node\Node.php file incorrectly assumes that all elements with no content are self-closing (or void) elements. This can produce invalid HTML in the result.

How to reproduce

I discovered this because I was testing and found that strings containing Font Awesome icons were getting mangled. For example it may look something like: <i class="fas fa-thumbs-up"></i> where you can see that the i element has no content (it gets replaced later with the icon). What HtmlSanitizer is doing is treating it as a void element and returning <i class="fas fa-thumbs-up" /> which is both invalid HTML and something that Font Awesome cannot recognize.

Possible Solution

The problem is here: https://github.com/symfony/symfony/blob/6.1/src/Symfony/Component/HtmlSanitizer/Visitor/Node/Node.php#L60

This needs some sort of logic to check for HTML elements which are allowed to be void. In HTML5 these are:
['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr']
Everything else that has no children should get a closing tag instead.

Additional Context

No response

@nicolas-grekas
Copy link
Member

Thanks for the report @omniError
Would you like to work on a PR to fix this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants