Skip to content

Commit c7274a4

Browse files
committed
fixing reported ReDoS
1 parent 3a3ed62 commit c7274a4

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ properties:
135135

136136
## changelog
137137

138+
- `2.0.1` Addressing a reported regular expression denial of service issue reported by [Sam Sanoop](https://twitter.com/snoopysecurity) of [Snyk](https://snyk.io/) THANK YOU!. The issue was that sending certain input would cause one of the regular expressions we used to lock up and not finish, freezing the process. See the test that was added for details. To be clear, this lib wasn't meant for parsing non-well formed HTML. But, better safe than sorry! So we're fixing it.
138139
- `2.0.0` updated to more modern dependencies/build system. Switched to prettier, etc. No big feature differences, just new build system/project structure. Added support for top level text nodes thanks to @jperl. Added support for comments thanks to @pconerly.
139140
- `1.0.0 - 1.0.3` no big changes, bug fixes and speed improvements.
140141

src/parse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const tagRE = /<[a-zA-Z\-\!\/](?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])*>/g
1+
const tagRE = /<[a-zA-Z\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g
22
import parseTag from './parse-tag'
33

44
// re-used obj for quick lookups of components

test/parse.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,3 +766,19 @@ test('simple speed sanity check', function (t) {
766766

767767
t.end()
768768
})
769+
770+
test('ReDoS vulnerability reported by Sam Sanoop of Snyk', function (t) {
771+
const start = Date.now()
772+
// reported problematic string
773+
HTML.parse(
774+
"<!''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''!"
775+
)
776+
// other variant
777+
HTML.parse(
778+
'<!""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""!'
779+
)
780+
const duration = Date.now() - start
781+
782+
t.ok(duration < 100, 'should not hang')
783+
t.end()
784+
})

0 commit comments

Comments
 (0)