[core] Fix ReDoS Vulnerability in code-uri.js by Replacing Vulnerable Regex #699
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
freecodecamp.cn/client/commonFramework/code-uri.js
Line 113 in b09a3a0
Line 113 in
f977402
`${"demo": "${demoOptions.demo.replace(/\.(.*)$/, '.js')}"}`
PoC Files and Comparisons:
https://gist.github.com/cecechen04/8f27d864bd97af29921895afe7f7ab8c
To evaluate the performance of this inefficient regular expression matching with varying input contents, the following commands can be executed within every PoC folder:
In the most severe case, on my machine, the maliciously crafted string took the following time, and caused CPU usage to reach 94% 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:
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).
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