Skip to content

[core] Potential ReDoS Vulnerability in init.js: Inefficient Regex May Cause Denial of Service #700

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

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

cecechen04
Copy link

Steps to reproduce

Hello,

I am writing to report a potential Regular Expression Denial of Service (ReDoS) vulnerability or Inefficient Regular Expression in the project. When using specially crafted input strings in the context, it may lead to extremely high CPU usage, application freezing, or denial of service attacks.

Location of Issue:

The vulnerability is related to a regular expression used in the following validation file, which may result in significantly prolonged execution times under certain conditions.

return value.replace(/<form[^>]*>/, function(val) {

Line 49 in b09a3a0

return value.replace(/<form[^>]*>/, function(val) {

Line 55 in b09a3a0

Line Code
49 `${"demo": "${value.replace(/<form[^>]*>/, function(val) {"}`
55 `${"demo": "${value.replace(/<form[^>]*>/, function(val) {"}`

PoC Files and Comparisons:

https://gist.github.com/cecechen04/d63319db739771c2f90a93449210f5ce

To evaluate the performance of this inefficient regular expression matching with varying input contents, the following commands can be executed within every PoC folder:

$ npm install # Install necessary dependencies for the minimal proof of concept environment.
$ time node poc.js # Run the script with maliciously constructed string and record the running time.
$ time node normal_string.js # Run the script with normal strings of same length and record the running time.

In the most severe case, on my machine, the maliciously crafted string took the following time, and caused CPU usage to reach 97% during program execution:

real    0m20.093s  
user    0m19.600s  
sys     0m0.040s

However, a normal string of the same length only took the following time:

real    0m0.054s  
user    0m0.030s  
sys     0m0.010s

This reveals a significant efficiency problem with the regular expression used in the program under certain conditions.

Proposed Solution:

A simple strategy could be to limit the length of the string being matched by the regular expression, thereby preventing excessive time consumption during regex matching. To completely avoid the issue, the pathological part of the regular expression that causes catastrophic backtracking should be modified.

Background Information:
Here are some real-world examples of issues caused by ReDoS vulnerabilities:

  1. In 2019, Cloudflare experienced a service disruption lasting approximately 27 minutes due to a ReDoS vulnerability that allowed crafted input to overwhelm regex processing, resulting in significant performance degradation and temporary service outage (source: Cloudflare Incident Report).

  2. Stack Overflow was affected by a ReDoS vulnerability in 2016, causing multiple instances of service degradation and temporary outages of up to 34 minutes during peak traffic periods due to inefficient regular expression patterns (source: Stack Overflow Incident Report).
    Thank you for your attention to this matter. Your evaluation and response to this potential security concern would be greatly appreciated.

Best regards,

Search keywords: ReDoS

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.

1 participant