Executive brief
Mermaid is a popular JavaScript library used to create diagrams from text descriptions. A flaw in how it processes sequence diagram labels allows attackers to inject malicious code that executes in the browser of anyone viewing the diagram. Sites that accept and display user-provided diagrams are at risk of account compromise or malware distribution.
Technical details
The vulnerability is a Cross-Site Scripting (XSS) flaw in the calculateMathMLDimensions function, which processes sequence diagram labels with KaTeX mathematical notation. The function calls renderKatex() on user-supplied text, then directly assigns the output to element.innerHTML without sanitization, allowing arbitrary HTML and JavaScript injection. The attack vector is network-based: an attacker crafts a malicious diagram (e.g., with an img tag containing an onerror handler) and tricks a user into viewing it on a site running vulnerable Mermaid. No authentication is required, but user interaction (viewing the diagram) is necessary. Successful exploitation allows arbitrary JavaScript execution in the victim's browser context. Patches are available in Mermaid 10.9.4 and 11.10.0.
Affected products
- Mermaid Mermaid 11.0.0-alpha.1 to 11.9.x (fixed in 11.10.0); 10.9.0-rc.1 to 10.9.3 (fixed in 10.9.4)
Timeline
- 2025-08-19: disclosed: GHSA-7rqq-prvp-x9jh published