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

[Security] Fix ReDoS #1164

Merged
merged 1 commit into from
Oct 8, 2024
Merged

[Security] Fix ReDoS #1164

merged 1 commit into from
Oct 8, 2024

Conversation

ready-research
Copy link
Contributor

@ready-research ready-research commented Sep 11, 2021

Fix ReDoS

Reported in https://www.huntr.dev/bounties/423e2208-6064-4150-b6f5-22f15f540259/, you can access this using GitHub.
Please validate using Mark as valid and also confirm the fix. Thank you.

Update:

This does not fix ReDoS, more over issue was not confirmed at least against Node.js 20. Though it does improve performance.
Correct description for this change is

Improve regex to handle nested comments more efficiently, ensure that the regex does not backtrack excessively

Copy link
Collaborator

@jsdevel jsdevel left a comment

Choose a reason for hiding this comment

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

please add a test

@lagden
Copy link
Contributor

lagden commented Oct 4, 2021

done here: #1169

@ready-research
Copy link
Contributor Author

Please validate the above huntr link using Mark as valid and also confirm the fix. Thank you.

@aartichella
Copy link

aartichella commented Oct 29, 2021

Hi @jsdevel , could you give an update on when this might be merged. This has an impact on our project.

@jsdevel
Copy link
Collaborator

jsdevel commented Nov 3, 2021

@ready-research @aartichella i need a test added with this change and the build needs to pass.

@smokhov
Copy link
Contributor

smokhov commented Jan 14, 2022

@jsdevel - A test was already merged from #1177 / #1169. Just need to merge the fix itself and respond to @ready-research to "mark as valid" in their form.

@jsdevel
Copy link
Collaborator

jsdevel commented Jun 15, 2022

@ready-research please rebase/get the build to pass.

@w666
Copy link
Collaborator

w666 commented Jul 17, 2024

Hi All,

Provided links on PRs do not contain any test, so I don't really get it.
As @jsdevel requested it requires a test.

@w666 w666 self-requested a review July 17, 2024 08:03
@smokhov
Copy link
Contributor

smokhov commented Sep 30, 2024

Hi All,

Provided links on PRs do not contain any test, so I don't really get it. As @jsdevel requested it requires a test.

Odd, I really thought the mentioned PR(s) really provided a test.

@w666 -- what kind of test and in which file would be suitable for this? I could maybe look into creating a test, but I am not at all an expert here. Does handleResponse() itself have a test? Would the test be in client-test.js, server-response-event-test.js, or some place elsewhere?

@w666
Copy link
Collaborator

w666 commented Sep 30, 2024

Hi @smokhov,

I looked on this PR again, then on the example code provided on the huntr.dev, then double checked locally the provided fix and then unfixed code. In both cases it works about the same way.

I will investigate this CVE when I have time, but at this point there is not enough evidence.

Please correct me if I am wrong.

Example below: first is not fixed code, then provided fix

image

@smokhov
Copy link
Contributor

smokhov commented Oct 4, 2024

It grows consistently from your samples. The fixed code's lowest 308/395 ms is 23% improvement. The other two are more significant 33-37%. It is possible it were worse before #1177 were merged? The higher you go is where it becomes more problematic (assuming busy environments with lots calls, but tbf I am not sure how prevalent those are to be DoS'ed...).

Overall, however, the fix is an improvement in runtime, if a proper test is provided, IMO it should be merged, but otherwise will leave it up to you to make the final determination.

@w666
Copy link
Collaborator

w666 commented Oct 7, 2024

Okay, looked into it, provided description and the example on huntr is not redos, it does not fix the issue, maybe it was the case some time ago, but not now.

The real redos issue looks like this

let regexp = /^(\d+)*$/;

let str = "012345678901234567890123456789z";

console.log(regexp.test(str));

it consumes 100% cpu and runs for a very long time.
I agree that provided solution work a bit faster, but still need to take look on other options.

@w666
Copy link
Collaborator

w666 commented Oct 7, 2024

Description for this PR should be like

Improve regex to handle nested comments more efficiently, ensure that the regex does not backtrack excessively

@w666
Copy link
Collaborator

w666 commented Oct 7, 2024

I think files in Dummy__should_ignore_commented_envelope_in_response validate that regex still works. So, yeah, fix can be accepted, we already have a test.

Will keep this PR open for a bit, just in case.

@w666 w666 merged commit c53d0c8 into vpulim:master Oct 8, 2024
w666 added a commit that referenced this pull request Oct 8, 2024
w666 added a commit that referenced this pull request Oct 8, 2024
@w666
Copy link
Collaborator

w666 commented Oct 8, 2024

I had to revert this commit because it there was an error in the regex, somehow missed that.

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.

6 participants