The vulnerability is a cross-site scripting (XSS) issue in the beautiful-mermaid library, caused by improper handling of user-controlled input within Mermaid diagrams. The analysis of the patch commit 68f3ab8c9658e7f4a3b749e06a6b96e4c3f55db1 reveals that user-defined styles from style and classDef directives were being interpolated directly into SVG attributes without sanitization. This allowed an attacker to break out of the intended attribute context and inject arbitrary SVG attributes, such as event handlers (onmouseover, onclick), leading to script execution.
The two functions responsible for this vulnerable behavior are renderNodeShape and renderNodeLabel in src/renderer.ts. These functions took style properties like fill, stroke, stroke-width, and color from the inlineStyle object and embedded them in the generated SVG. The fix applied in the patch involves wrapping these potentially malicious values with an escapeXml() utility function, which neutralizes characters that have special meaning in XML/HTML, thus preventing the injection.