Regular Expression Denial of Service in markdown
Summary
GHSA-wx77-rp39-c6vg: Regular Expression Denial of Service in markdown. Affects markdown versions >= 0.0.0. No fix is published. How to fix ↓
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
The markdown package is an npm package used for converting Markdown syntax to HTML. It provides a convenient way to parse and render Markdown content. However, all versions of markdown are vulnerable to Regular Expression Denial of Service (ReDoS). The vulnerability specifically affects the markdown.toHTML() function, which exhibits degraded performance when parsing long strings containing underscores. This can potentially lead to a Denial of Service if the parser accepts user input.
Vulnerability Detail
The Regular Expression Denial of Service (ReDoS) vulnerability in the markdown package arises from inefficient regular expressions used in the markdown.toHTML() function. When processing long strings with underscores, the regular expressions can cause the function to exhibit significantly degraded performance. This can be exploited by an attacker to craft malicious input that triggers a ReDoS attack, leading to a denial of service condition. The severity of this vulnerability is considered low.
How To Fix
No fixed version is published for this vulnerability.
Tip — Not sure whether your app is affected? Vulert can check the versions your app actually runs. Scan free →
Workaround
As there is no fix available, a possible workaround is to sanitize user input before passing it to the markdown.toHTML() function. This can involve validating and limiting the length of input strings, as well as removing any potentially malicious characters or patterns. Here is an example of how to sanitize user input in JavaScript:
function sanitizeInput(input) {
// Validate and limit input length
if (input.length > MAX_LENGTH) {
throw new Error('Input length exceeds maximum limit');
}
// Remove underscores
const sanitizedInput = input.replace(/_/g, '');
return sanitizedInput;
}
Conclusion
The markdown package is vulnerable to a Regular Expression Denial of Service (ReDoS) issue, which can lead to a denial of service if user input is accepted by the markdown.toHTML() function. Currently, there is no fix available, and it is recommended to use an alternative package until a fix is released. Sanitizing user input can help mitigate the risk of this vulnerability. For further support on vulnerability remediation, you can reach out to DevNack.com.
See every vulnerability recorded for markdown →
FAQ
The vulnerability is a Regular Expression Denial of Service (ReDoS) issue in the markdown package. It occurs when parsing long strings containing underscores, leading to significantly degraded performance and potential denial of service.
The impact of this vulnerability is a potential denial of service if the markdown.toHTML() function accepts user input. An attacker can craft malicious input to trigger a ReDoS attack, causing the function to consume excessive resources and slow down or crash the application.
No, there is currently no fix available for this vulnerability in the markdown package. It is recommended to use an alternative package until a fix is released.
To mitigate the risk, you can sanitize user input before passing it to the markdown.toHTML() function. This involves validating and limiting the length of input strings, as well as removing any potentially malicious characters or patterns.
You can find more information about this vulnerability in the official GitHub advisory database. Visit the following link: https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2020/09/GHSA-wx77-rp39-c6vg/GHSA-wx77-rp39-c6vg.json
References
Related vulnerabilities
Recent vulnerabilities recorded for markdown.