Potential ReDoS Vulnerability or Inefficient Regular Expression in Project: Need for Assessment and Mitigation #5958
Labels
Status: Triage
Needs to be verified, categorized, etc
Type: Bug / Error
Something isn't working or is incorrect
Description
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.
mermaid/packages/mermaid/src/diagrams/state/stateDb.js
Line 465 in 47601ac
mermaid/packages/mermaid/src/diagrams/gantt/ganttDb.js
Line 674 in 47601ac
PoC Files and Comparisons:
PoC_1.zip
PoC_2.zip
To evaluate the performance of this inefficient regular expression matching with varying input contents, the following commands can be executed within every PoC_i folder:
In the most severe case, on my machine, the maliciously crafted string took the following time, and caused CPU usage to reach 98% during program execution:
However, a normal string of the same length only took the following time:
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:
Thank you for your attention to this matter. Your evaluation and response to this potential security concern would be greatly appreciated.
Best regards,
Steps to reproduce
Please refer to the previous text.
Screenshots
No response
Code Sample
No response
Setup
Suggested Solutions
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: