benweet / stackedit

In-browser Markdown editor
https://stackedit.io/
Apache License 2.0
21.69k stars 2.72k forks source link

Regular Expression DoS vulnerability #1722

Open yinxiL opened 3 years ago

yinxiL commented 3 years ago

We are working on the ReDoS problem and detected 1 vulnerable regex(es) from your repository.

1: <\/?[\w:-]+\s*(?:\s+[\w:-]+(?:=(?:("|')(\\?[\w\W])*?\1|[^\s'">=]+))?\s*)*\/?> in stackedit/src/services/markdownGrammarSvc.js

Please try the following:

var pattern = "<\\/?[\\w:-]+\\s*(?:\\s+[\\w:-]+(?:=(?:(\"|')(\\\\?[\\w\\W])*?\\1|[^\\s'\">=]+))?\\s*)*\\/?>";
var input = "<- -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  - \b";
var re = new RegExp(pattern);
var matched = input.match(re);

We didn’t create a pull request because we're not sure if these cases are possible to take place in your program, we also do not understand the functionality of these regexes as you do. Thank you for your understanding.