xemlock / htmlpurifier-html5

HTML5 support for HTMLPurifier
https://packagist.org/packages/xemlock/htmlpurifier-html5
MIT License
100 stars 12 forks source link

Catastrophic backtracking #82

Open bytestream opened 1 month ago

bytestream commented 1 month ago

The comment regex in https://github.com/xemlock/htmlpurifier-html5/blob/master/library/HTMLPurifier/Lexer/HTML5.php#L57 can cause catastrophic back tracking. The result is preg_replace_callback returns null

Workaround is to increase pcre.backtrack_limit. However, I think it would be better if the error handling in this function is improved to account for when preg_replace_callback returns null. I expect that it would just skip that comment regex functionality in that case.

bytestream commented 1 month ago

Changing the regex to <!--([^>]*)(-->|\z) also fixes the back tracking issue.