-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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 the regular expression for function clean
in utils.js
#4770
Conversation
hey @boneskull someone from the team asked @yetingli to open a PR with a security fix; do you guys plan on merging it sometime soon? |
This PR hasn't had any recent activity, and I'm labeling it |
I am voting for this to be merged ASAP. |
Reported in huntr https://www.huntr.dev/bounties/1d8a3d95-d199-4129-a6ad-8eafe5e77b9e/ Please |
@yetingli We missed it. Sorry for the late response. @mochajs/core I will merge this in a few days after CLA. After merging this PR, I will add a test for ReDos. |
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.
LGTM
Hi @outsideris, thank you for your response! And I have signed the CLA. Please |
@yetingli Okay, It's my first time using Huntr. I will try it after merging this. |
Which mocha version has this fix? 10.0.0 is still giving the same issue. |
@outsideris sorry to bother, but can a new version be published with this fix? Our security tools are complaining... |
@sauravlikhar @heidemn-faro the fix is now published in version 10.1.0 |
is it fixed??? 10.2.0 is still giving this error |
Description of the Change
Fix the regular expression for function
clean
inutils.js
to avoid potential Regular Expression Denial of Service (ReDoS) vulnerabilities.Alternate Designs
The ReDoS vulnerabilities of the regex
/^function(?:\s*|\s+[^(]*)\([^)]*\)\s*\{((?:.|\n)*?)\s*\}$|^\([^)]*\)\s*=>\s*(?:\{((?:.|\n)*?)\s*\}|((?:.|\n)*))$/
are mainly due to the overlapped sub-patterns\s+[^(]*
and((?:.|\n)*?)\s*
.We can ignore
\s
first, because in the end, we can also deal with\s
using thetrim
function (see the code below)mocha/lib/utils.js
Line 92 in 8421974
So I am willing to suggest that you replace the ReDoS-vulnerable regex
/^function(?:\s*|\s+[^(]*)\([^)]*\)\s*\{((?:.|\n)*?)\s*\}$|^\([^)]*\)\s*=>\s*(?:\{((?:.|\n)*?)\s*\}|((?:.|\n)*))$/
with the safe regex/^function(?:\s*|\s[^(]*)\([^)]*\)\s*\{((?:.|\n)*?)\}$|^\([^)]*\)\s*=>\s*(?:\{((?:.|\n)*?)\}|((?:.|\n)*))$/
Benefits
It achieves functional equivalence and is not subject to ReDoS attacks.
Applicable issues
See the link https://www.huntr.dev/bounties/1d8a3d95-d199-4129-a6ad-8eafe5e77b9e/