-
-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle extremely long and terrible patterns more gracefully
Reported by @nstarke, thanks
- Loading branch information
Showing
2 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
var t = require('tap') | ||
|
||
var minimatch = require('../') | ||
|
||
// utility function for generating long strings | ||
var genstr = function (len, chr) { | ||
var result = '' | ||
for (var i = 0; i <= len; i++) { | ||
result = result + chr | ||
} | ||
|
||
return result | ||
} | ||
|
||
var exploit = '!(' + genstr(1024 * 15, '\\') + 'A)' | ||
|
||
// within the limits, and valid match | ||
t.ok(minimatch('A', exploit)) | ||
|
||
// within the limits, but results in an invalid regexp | ||
exploit = '[!(' + genstr(1024 * 15, '\\') + 'A' | ||
t.notOk(minimatch('A', exploit)) | ||
|
||
t.throws(function () { | ||
// too long, throws TypeError | ||
exploit = '!(' + genstr(1024 * 64, '\\') + 'A)' | ||
minimatch('A', exploit) | ||
}, TypeError) |
6944abf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you elaborate a bit on the issue that is addressed here? I'm assuming this is the fix to a
RegExp DoS issue
that npm warns about.It says reported by @nstarke, but I could not find a GitHub issue, and I would like to understand how serious this is before going on a PR spree of packages that use an old minimatch dependency.
6944abf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is fixing the regexp dos issue.
There was not a github issue because this was reported privately, as it was a potential security hazard that was not made public until a fix was available.