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: Support single character extension. (issue #38) #39

Merged
merged 2 commits into from
Jul 20, 2021

Conversation

sttk
Copy link
Contributor

@sttk sttk commented Mar 28, 2021

This pr is to fix the issue #38.

lib/extension.js Outdated
@@ -1,7 +1,7 @@
var path = require('path');

var EXTRE = /\.[^.]*/g;
var LONGEXTRE = /^[.]?[^.]+([.].+[^.])$/;
var LONGEXTRE = /^[.]?[^.]+([.].*[^.])$/;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sttk will this cause a ReDOS issue? Maybe it needs to be this:

Suggested change
var LONGEXTRE = /^[.]?[^.]+([.].*[^.])$/;
var LONGEXTRE = /^[.]?[^.]+([.][^.]*[^.])$/;

image

Do you agree?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phated That regexp does not pass tests.

$ node
> /^[.]?[^.]+([.][^.]*[^.])$/.test('aaa.js')
true
> /^[.]?[^.]+([.][^.]*[^.])$/.test('aaa.bbb.js')
false
> /^[.]?[^.]+([.][^.]*[^.])$/.test('aaa..bbb.js')
false

And I checked the regexp /^[.]?[^.]+([.].*[^.])$/ with some tools, and the vulnerability was not detected.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sttk I don't think those tools work correctly because I submitted the ReDOS RegExp from gulpjs/glob-parent@f923116 and all the tools claim it is safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phated Because I don't know how to avoid ReDOS, I replaced regex processes in extension.js to alternative ways.

The following table is the benchmark result of extension.js before and after modification.

|                          | before            | after              |
|:-------------------------|------------------:|-------------------:|
| file.js                  | 3,465,168 ops/sec | 17,745,432 ops/sec |
| file.tmp.dot.js          | 1,453,870 ops/sec |  6,729,040 ops/sec |
| relative/path/to/file.js | 3,292,908 ops/sec | 14,813,461 ops/sec |

- Platform: Node.js 15.5.0 on Darwin 64-bit
- Machine: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz, 64GB

Copy link
Member

@phated phated left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sttk Amazing! Thank you! I'm sorry I completely missed your update that removed the RegExps.

I'll get this merged and released.

@phated phated merged commit 1258548 into gulpjs:master Jul 20, 2021
@sttk
Copy link
Contributor Author

sttk commented Jul 20, 2021

@phated Never mind. Thank you for merging this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants