-
-
Notifications
You must be signed in to change notification settings - Fork 320
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
[comments re] halt with CPU 100% on some html #263
Comments
Problem is at https://github.com/jgm/CommonMark/blob/master/js/lib/inlines.js#L36 var HTMLCOMMENT = "<!--([^-]+|[-][^-]+)*-->"; What are those complex conditions for? May be use one below? var HTMLCOMMENT = "<!--[\s\S]*?-->"; It works. |
From the spec:
I think the |
Ah, got it. Well:
I think it's more simple & safe to remove those from regexp. If anyone wish to get better safety, he will pas result via sanitizer. Or we could force escaping those. But those should not be considered as "not comment" block. |
Upd: |
Memo. Verify that CDATA regexp does not have the same vulnerability, because it's built with the same principle. Updated the first message. |
These regexes work fine with cmark (and re2c, which creates a non-backtracking DFA from the regex). I guess the regex libraries in javascript allow pathological backtracking. Presumably there are ways to write equivalent regexes that won't be pathological? (In the case of the comment regex, it's probably worth matching HTML5 behavior, #264.) |
How about this for a non-pathological regex that matches HTML5 behavior?
|
I've fixed comments in markdown-it/markdown-it@792f386 Don't know if it's good for ref implementation. |
@puzrin can you publish a new version markdown-it to npm? |
@fengmk2 please, wait ~ 1 day max. We are about to finish 3.0.0 milestone. Feel free to use markdown-it tracker for related questions. |
Put this into dingus:
Bug in tag detection regexp. Found by @fengmk2
Upd Verify that CDATA regexp does not have the same vulnerability
Upd2 The same problem in CDATA #267
The text was updated successfully, but these errors were encountered: