Skip to content
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

fix Regular Expression DoS #26 #27

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/parse.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*jshint -W030 */
var tagRE = /(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g;
var tagRE = /<[a-zA-Z\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g;
adrai marked this conversation as resolved.
Show resolved Hide resolved
var parseTag = require('./parse-tag');
// re-used obj for quick lookups of components
var empty = Object.create ? Object.create(null) : {};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/rayd/html-parse-stringify2/issues"
},
"dependencies": {
"void-elements": "^2.0.1"
"void-elements": "^3.1.0"
},
"devDependencies": {
"jshint": "^2.5.10",
Expand Down
17 changes: 17 additions & 0 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,3 +534,20 @@ test('simple speed sanity check', function (t) {

t.end();
});

test('ReDoS vulnerability reported by Sam Sanoop of Snyk', function (t) {
var start = Date.now();
// reported problematic string
/*jshint -W110 */
HTML.parse(
"<!''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''!"
);
// other variant
HTML.parse(
'<!""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""!'
);
var duration = Date.now() - start;

t.ok(duration < 100, 'should not hang');
t.end();
});
adrai marked this conversation as resolved.
Show resolved Hide resolved