fix(markdown.js): use proposed fixes using negative look-ahead #14296
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "github/fork/jmeis/jm/7128"
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?
https://github.com/codemirror/codemirror5/issues/7128
I've verified that the first one doesn't solve the problem (the given problematic input is still overly slow to match) and actually changes the meaning of the regexp (removing the optional space and randomly adding a newline to the negative set). I haven't looked deeply into the other changes but they also don't look very convincing.
@marijnhI was also skeptical. I asked@ShiyuBanzhouto clarify the proposed fixes or if we can close the issue.CodeMirror Markdown Mode ReDoS Vulnerability Fixes
Overview
This document demonstrates that the improved regular expressions successfully prevent ReDoS attacks while maintaining the original functionality of CodeMirror's Markdown mode.
Fixed Regular Expressions
1. Trailing Spaces Check
Original (Vulnerable):
Fixed:
Attack String:
" ".repeat(100000) + "@"Vulnerability Analysis:
+quantifier causing exponential backtracking@characterFix Analysis:
{1,100}prevents excessive backtracking(?=$)ensures end-of-line without backtrackingPerformance Test:
2. Image/Link Prefix Check
Original (Vulnerable):
Fixed:
Attack String:
"[".repeat(100000) + "]"Vulnerability Analysis:
[^\]]*causes catastrophic backtracking[charactersFix Analysis:
{0,1000}limits backtracking\nprevents cross-line matching(?= ?(?:\(|\[))ensures proper termination3. Link Suffix Check
Original (Vulnerable):
Fixed:
Attack String:
"(".repeat(100000) + "\n@"Vulnerability Analysis:
.*?still causes massive backtracking with complex patternsFix Analysis:
[^()\n\\]prevent nested bracket issues\\.for legitimate escapes4. Angle-Bracket Email Check
Original (Vulnerable):
Fixed:
Attack String:
"^\u0000@".repeat(100000) + "\u0000"Vulnerability Analysis:
Fix Analysis:
5. Nested Link Check
Original (Vulnerable):
Fixed:
Attack String:
"()]" + " [".repeat(100000) + "◎\n@◎"Vulnerability Analysis:
Fix Analysis:
(?=...)eliminates capture group backtrackingFunctionality Preservation Tests
Test Case 1: Legitimate Trailing Spaces
Test Case 2: Valid Image Links
Test Case 3: Normal Links
Test Case 4: Email Links
Test Case 5: Nested References
ReDoS Attack Prevention Validation
Performance Comparison
Attack String Testing
Conclusion
The improved regular expressions successfully:
The fixes use defensive regex techniques:
{1,100},{0,1000})(?=...))[^\]\n])These changes make CodeMirror's Markdown mode safe from ReDoS vulnerabilities while maintaining full compatibility with existing functionality.
@ShiyuBanzhouI updated the PR based on your comment. One of the tests fail because the regex/\((?:[^()\n\\]|\\.){0,1000}\)| ?\[(?:[^\[\]\n\\]|\\.){0,1000}\]/does not support links with nested parenthesis.How does changing that plain suffix to a lookahead affect the complexity of the match? It seems like the regexp engine will have to do pretty much exactly the same thing in both situations.
Markdown does indeed support nested parentheses in link targets. I think we'll want to do the right thing at least for one level of nesting.
restored source branch
github/fork/jmeis/jm/7128Pull request closed