-
Notifications
You must be signed in to change notification settings - Fork 82
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
A ReDoS vulnerability can be exploited after version 0.2.0 #117
Comments
Thank you for raising this issue. Have added this to the Readme for the project until it is resolved. Any ideas for resolving thie welcome. I assume this can still be caught when setting an executor and max CPU time? |
Yes. The cause of the problem is the defect of the regular engine. This link can be referenced: https://checkmarx.com/wp-content/uploads/2015/03/ReDoS-Attacks.pdf |
Hi @mxro , is there any plan to fix this in near term? It is listed under https://nvd.nist.gov/vuln/detail/CVE-2021-40660#match-8086489 Thank you |
Thanks for reaching out! I guess the way forward here would be to replace the RegEx with more deterministic logic? |
Yes, such complex RegEx is vulnerable. Out of curiosity about the reason of injecting interruption call by using POISON_PILLS, is this for the purpose of terminating script execution to cap cpu time? |
Yes, it's injecting a bit of code that triggers the test for how much CPU time is used. However, there is an additional fallback the sandbox provides, in that it can do a hard shutdown of the thread as well. But using the injected statements should be smoother. |
@mxro I didn't know the exact reason such as ReDoS, but I knew that "POISONPIL + Comments" was the cause. I don't know this approach is a real solution to this vulnerability, but I'm leaving a post in case it helps. |
@asilism Thank you for the idea! So that would mean moving to delight-nashorn-sandbox/src/main/java/delight/nashornsandbox/internal/JsSanitizer.java Line 279 in 23ba3d7
? |
@mxro 1 ) Does RemoveComments function completely remove all of comments line ? |
@mxro I found that this issue was not resolved in version 0.2.4.Excuse me, when will the problem be solved? If multiple lines of non-function code are transferred, \n is not added to the end of the line after beautifyJs processing. |
I think it should!
Pretty sure the RegEx would need to be changed. |
@huzongxin1994 Yes, this issue is still open. Looking for good ideas to fix the Regex or avoid the problem altogether! |
Modify the regular expression or split the regular logic, I think it's a better solution.Can you tell me more about what this regularity \n(?![\W]*(//.+[\W]+)else) means, and then we're trying to deal with it together?The \n(?![\W](//.+[\W]+)*else) regular expression triggers a backtracking trap. |
@huzongxin1994 This link @SugarP1g shared earlier describes the backtracking vulnerability: https://checkmarx.com/wp-content/uploads/2015/03/ReDoS-Attacks.pdf By avoiding it altogether, I was thinking of if there could be a solution that doesn't use a regular expression at all! |
When can this question be updated? Thank you. |
@mxro Hello, sorry to interrupt, I think if this problem can not change the regular expression in the short term, removing the comment may be a good way, I am removing the comment, dos attack no longer exists. |
You can also set timeout limits for regular expressions and ask users to modify the corresponding JS code. |
Like this:
|
@MrLi2018 Thank you for your suggestion. That looks promising. Could you provide a few more details? Where would we use the new class? |
@mxro Hello, I'm sorry I won't submit open source code on GitHub. I can only communicate in this way.The above class can be used to break the infinite backtracking of regular expressions, and I've written a simple example you can refer to, and I think it can solve this problem.
Or you can use a separate thread, but I think you can use the sandbox to set the thread pool at build time.As follows:
|
Thank you @MrLi2018 for the further clarifications! I've included this in PR #139. I would be very grateful for one or more reviews confirming this addresses the identified security issues. Thanks for @SugarP1g for initially identifying this - I've tried to model the unit test as closely as possible to what you have submitted. |
Thank you for your contribution to the sandbox, but another way is to use Hyperscan to parse regulars, because it's not a backtracking mechanism, but it seems that you need to modify the regulars, and if you want to remove the regulars, it seems that unless we can get involved in the JS loop itself. @mxro |
Fix released to Maven central with version |
@mxro Does this mean that there is a fix to CVE-2021-40660? |
@gregorywaynepower Yes, absolutely! Not sure how I can get the CVE closed though?! |
I can do some digging on how to update an existing GitHub Security Advisory Contribution. Edit: Looks like you can make a pull request to this file and add a |
Thanks heaps for the information ❤ - submitted a PR 👆 |
Please note this has been merged in the advisory database - thanks for your help @gregorywaynepower github/advisory-database#3256 |
Fantastic news @mxro ! Thanks for taking this on. |
There is a weak expression can be exploited to launch a DOS attack.
Execution stack is as follow:
POC:
Run result:
The text was updated successfully, but these errors were encountered: