CVE-2025-54881: Mermaid improperly sanitizes sequence diagram labels leading to XSS
N/A
Basic Information
Technical Details
| Package Name | Ecosystem | Vulnerable Versions | First Patched Version |
|---|---|---|---|
| mermaid | npm | >= 10.9.0-rc.1, < 11.10.0 | 11.10.0 |
Vulnerability Intelligence
Miggo AI
Root Cause Analysis
The vulnerability exists because user-provided input is passed to the innerHTML property in multiple locations without proper sanitization. The core of the vulnerability is in the calculateMathMLDimensions function, which is explicitly mentioned in the vulnerability description. This function is responsible for calculating the dimensions of KaTeX-rendered text by creating a temporary DOM element and setting its innerHTML. The initial implementation did not sanitize the input, allowing for XSS.
The fixing commit 685516a85ec1df64cefd4fd15f26533be87d458e addresses this by introducing a new function, renderKatexSanitized, which wraps the original KaTeX rendering logic with a call to sanitizeText. This new sanitized function is then used in calculateMathMLDimensions and other places where KaTeX output is rendered, such as drawKatex and addHtmlSpan.
Additionally, the fixing commit applies sanitizeText in other functions like addHtmlLabel that were also found to be using innerHTML with potentially unsafe user input. By analyzing the changes in the fixing commit, I was able to identify all the functions that were sinks for this XSS vulnerability.