A ReDoS vulnerability has been identified in CodeMirror’s Markdown mode #7128
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
A ReDoS vulnerability has been identified in CodeMirror’s Markdown mode. Specially crafted input strings can trigger catastrophic backtracking in several regular expressions, causing the affected application to freeze or significantly degrade its performance. This vulnerability could be exploited in any environment (browser‐ or server‑side) that utilizes CodeMirror’s Markdown mode, leading to denial‑of‑service (DoS).
Details
Multiple regular expression patterns within the mode/markdown/markdown.js file are vulnerable to exponential backtracking. The problem lies in the use of greedy quantifiers (e.g., + or *) in combination with unbounded capture groups that must eventually match a terminating token. When provided with an extremely long string that fails to eventually match the pattern (e.g. due to an extra character at the end), the engine will backtrack excessively.
Below are a few representative vulnerable patterns along with the attack strings that trigger them:
Vulnerable Code:
Trigger Payload:
"" + " ".repeat(100000) + "@"Problem: The pattern
/ +$/uses a greedy quantifier with no length limit before the end-of-line anchor ($), causing exponential backtracking on an input consisting of 100,000 spaces followed by a non‑space character.Vulnerable Code:
Trigger Payload:
"" + "[".repeat(100000) + "]"Problem: The use of
[^\]]*is unbounded and can lead to catastrophic backtracking when fed with thousands of repetitive[characters.Vulnerable Code:
Trigger Payload:
"" + "(".repeat(100000) + "\n@"Problem: The non‑greedy
.*?still causes massive backtracking in this context due to the overall pattern complexity when the input consists of many repeated ( characters followed by a newline and non‑matching character.Vulnerable Code:
Trigger Payload:
"" + "^\u0000@".repeat(100000) + "\u0000"Problem: The unbounded character class
[^[> \\]+together with a similar pattern for matching the domain part causes the regex engine to overwork when facing repeated patterns that do not reach the closing angle bracket.Vulnerable Code:
Trigger Payload:
"" + "()]" + " [".repeat(100000) + "◎\n@◎"Problem: The use of unbounded
[^\]]*and\(.*\)further amplifies the risk of exponential backtracking with carefully crafted inputs.Proposed Fixes Using Negative Look-Ahead:
To mitigate the vulnerability, we suggest replacing the vulnerable regex patterns with ones that do not require catastrophic backtracking. For example:
PoC
Below are two proof‑of‑concept examples:
PoC via a Standalone HTML File
Save the following content as
poc.html, ensuring that it resides alongside your local copies of:lib/codemirror.js
mode/xml/xml.js
mode/markdown/markdown.js
Then open the file in a browser and observe the console output.
PoC via Existing Test Suite (test.js)
If you already use a test suite to run CodeMirror’s tests (as in your test.js file), append the following code in the end of test.js file.
Impact
Impact
Type: Regular-expression Denial of Service (ReDoS)
Affected Component: CodeMirror’s Markdown mode (v5.17.0 or earlier)
Who is Impacted:
Web applications that embed CodeMirror to allow users to edit Markdown content.
Server‑side renderers that reuse CodeMirror’s tokenizer.
Result: An attacker may provide a maliciously crafted Markdown input, causing the editor (or associated service) to freeze the CPU for several seconds or longer, leading to a denial of service.
Hello.
Affected: "v5.17.0 or earlier"
Base on the changelog, 5.17.0 has been released on 19-07-2016.
Can you confirm you tested this version ?
If so, can you confirm our PoC is working on the latest version (5.65.19) ?
Thanks
Snyk is reporting this as a vulnerability in the current version: https://security.snyk.io/vuln/SNYK-JS-CODEMIRROR-10494092
We could use a patch for it to satisfy our security requirements.
Hi team, at work we're also starting to receive Snyk security warnings (same link as
@lonnyhowardmentioned above) which is creating security tickets. Could you please let us know if there are plans to patch this?Also could you please let us know if CodeMirror 6 is also vulnerable?
CodeMirror 6 is not vulnerable. Since these are really minor vulnerabilities (at worse, you can make someone's browser tab slow), there are no plans to rewrite the version 5 Markdown mode to address this.
Thanks for the quick reply. Looks like the security scanner went too aggressive on rating the CVE's severity.
I'm using GraphiQL (the GraphQL IDE) which pulls in CodeMirror 5. I'll let those folks know there is a new version available.
Thanks for all your time maintaining this library!
mentioned in issue #4089
mentioned in merge request !14296
Hi
@ShiyuBanzhou.I made a PR with your proposed fixes, and@marijnhdoes not think they work. Can we close this?mentioned in issue #7139