{"id":"CVE-2025-54881","aliases":["EUVD-2025-28574","GHSA-7rqq-prvp-x9jh","UBUNTU-CVE-2025-54881"],"status":"published","title":"Mermaid improperly sanitizes of sequence diagram labels leading to XSS","description":"Mermaid is a JavaScript based diagramming and charting tool that uses Markdown-inspired text definitions and a renderer to create and modify complex diagrams. In the default configuration of mermaid 10.9.0-rc.1 to 11.9.0, user supplied input for sequence diagram labels is passed to innerHTML during calculation of element size, causing XSS.","severity":{"version":"4.0","score":5.3,"vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N","level":"medium","assessor":"cna","from":"cve"},"epss":{"day":"2026-11-11","score":0.00862,"percentile":0.59006,"model":"v2026.06.15"},"facts":{"in_kev":false,"known_exploited":false,"public_exploit":false,"fix_available":true},"cwes":["CWE-79"],"published":"2025-08-19T17:04:29Z","modified":"2026-10-28T02:30:43Z","fixes":[{"ecosystem":"npm","package":"mermaid","fixed_in":["11.10.0","10.9.4"],"sources":["ghsa","osv"]}],"affected":[{"source":"ghsa","ecosystem":"npm","package":"mermaid","ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"11.0.0-alpha.1"},{"fixed":"11.10.0"}]}]},{"source":"ghsa","ecosystem":"npm","package":"mermaid","ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"10.9.0-rc.1"},{"fixed":"10.9.4"}]}]},{"source":"osv","ecosystem":"npm","package":"mermaid","ranges":[{"type":"SEMVER","events":[{"introduced":"11.0.0-alpha.1"},{"fixed":"11.10.0"}]}]},{"source":"osv","ecosystem":"npm","package":"mermaid","ranges":[{"type":"SEMVER","events":[{"introduced":"10.9.0-rc.1"},{"fixed":"10.9.4"}]}]},{"source":"osv","ecosystem":"Ubuntu:22.04:LTS","package":"node-mermaid","ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"0"}]}],"versions":["8.7.0+ds+~cs27.17.17-3","8.13.3+ds+~cs26.13.21-1","8.13.3+ds+~cs26.13.21-2","8.13.8+~cs10.4.16-1"]},{"source":"osv","ecosystem":"Ubuntu:26.10","package":"node-mermaid","ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"0"}]}],"versions":["9.2.2+~2.0.0-1","9.2.2+~2.0.0-2"]}],"products":[{"vendor":"mermaid-js","product":"mermaid"}],"references":[{"url":"https://github.com/mermaid-js/mermaid/security/advisories/GHSA-7rqq-prvp-x9jh","tags":["x_refsource_CONFIRM","advisory","web","report"]},{"url":"https://github.com/mermaid-js/mermaid/commit/5c69e5fdb004a6d0a2abe97e23d26e223a059832","tags":["x_refsource_MISC","fix","web","report"]},{"url":"https://github.com/mermaid-js/mermaid/commit/685516a85ec1df64cefd4fd15f26533be87d458e","tags":["x_refsource_MISC","fix","web","report"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2025-54881","tags":["advisory"]},{"url":"https://github.com/advisories/GHSA-7rqq-prvp-x9jh"},{"url":"https://github.com/CVEProject/cvelistV5/tree/main/cves/2025/54xxx/CVE-2025-54881.json","tags":["advisory"]},{"url":"https://github.com/mermaid-js/mermaid","tags":["package"]},{"url":"https://ubuntu.com/security/CVE-2025-54881","tags":["report"]},{"url":"https://www.cve.org/CVERecord?id=CVE-2025-54881","tags":["report"]}],"sources":{"cve":[{"id":"CVE-2025-54881","title":"Mermaid improperly sanitizes of sequence diagram labels leading to XSS","description":"Mermaid is a JavaScript based diagramming and charting tool that uses Markdown-inspired text definitions and a renderer to create and modify complex diagrams. In the default configuration of mermaid 10.9.0-rc.1 to 11.9.0, user supplied input for sequence diagram labels is passed to innerHTML during calculation of element size, causing XSS.","status":"published","published":"2025-08-19T17:04:29.453Z","modified":"2025-08-19T18:14:04.599Z","cvss":[{"version":"4.0","score":5.3,"vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N","level":"medium","assessor":"cna"}],"cwes":["CWE-79"],"updated_at":"2026-11-02T14:32:27.28543Z"}],"euvd":[{"id":"EUVD-2025-28574","description":"Mermaid is a JavaScript based diagramming and charting tool that uses Markdown-inspired text definitions and a renderer to create and modify complex diagrams. In the default configuration of mermaid 10.9.0-rc.1 to 11.9.0, user supplied input for sequence diagram labels is passed to innerHTML during calculation of element size, causing XSS.","status":"published","published":"2025-08-19T17:04:29Z","modified":"2025-08-19T18:14:04Z","cvss":[{"version":"4.0","score":5.3,"vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N","level":"medium"}],"updated_at":"2026-11-02T20:31:55.90596Z"}],"ghsa":[{"id":"GHSA-7rqq-prvp-x9jh","title":"Mermaid improperly sanitizes sequence diagram labels leading to XSS","description":"### Summary\nIn the default configuration of mermaid 11.9.0, user supplied input for sequence diagram labels is passed to `innerHTML` during calculation of element size, causing XSS.\n\n### Details\nSequence diagram node labels with KaTeX delimiters are passed through `calculateMathMLDimensions`. This method passes the full label to `innerHTML` which allows allows malicious users to inject arbitrary HTML and cause XSS when mermaid-js is used in it's default configuration (with KaTeX support enabled). \n\nThe vulnerability lies here:\n\n```ts\nexport const calculateMathMLDimensions = async (text: string, config: MermaidConfig) =\u003e {\n  text = await renderKatex(text, config);\n  const divElem = document.createElement('div');\n  divElem.innerHTML = text; // XSS sink, text has not been sanitized.\n  divElem.id = 'katex-temp';\n  divElem.style.visibility = 'hidden';\n  divElem.style.position = 'absolute';\n  divElem.style.top = '0';\n  const body = document.querySelector('body');\n  body?.insertAdjacentElement('beforeend', divElem);\n  const dim = { width: divElem.clientWidth, height: divElem.clientHeight };\n  divElem.remove();\n  return dim;\n};\n```\n\nThe `calculateMathMLDimensions` method was introduced in 5c69e5fdb004a6d0a2abe97e23d26e223a059832 two years ago, which was released in [Mermaid 10.9.0](https://github.com/mermaid-js/mermaid/releases/tag/v10.9.0).\n\n### PoC\nRender the following diagram and observe the modified DOM.\n\n```\nsequenceDiagram\n    participant A as Alice\u003cimg src=\"x\" onerror=\"document.write(`xss on ${document.domain}`)\"\u003e$$\\\\text{Alice}$$\n    A-\u003e\u003eJohn: Hello John, how are you?\n    Alice-)John: See you later!\n```\n\nHere is a PoC on mermaid.live: https://mermaid.live/edit#pako:eNpVUMtOwzAQ_BWzyoFKaRTyaFILiio4IK7ckA-1km1iKbaLY6spUf4dJ0AF68uOZ2dm7REqXSNQ6PHDoarwWfDGcMkUudaJGysqceLKkj3hPdl3osJ7IRvSm-qBwcCAaIXGaONRrSsnUdnobITF28PQ954lwXglai25UNNhxWAXBMyXxcGOi-3kL_5k79e73atuFSUv2HWazH1IWn0m3CC5aPf4b3p2WK--BW-4DJCOWzQ3TM0HQmiMqIFa4zAEicZv4iGMsw0D26JEBtS3NR656ywDpiYv869_11r-Ko12TQv0yLveI3eqfcjP111HUNVonrRTFuhdsVgAHWEAmuRxlG7SuEzKMi-yJAnhAjTLIk_EcbFJtuk2y9MphM8lM47KIp--AOZghtU\n\n### Impact\nXSS on all sites that use mermaid and render user supplied diagrams without further sanitization.\n\n### Remediation\nThe value of the `text` argument for the `calculateMathMLDimensions` method needs to be sanitized before getting passed on to `innerHTML`.","status":"published","published":"2025-08-19T20:16:58Z","modified":"2025-09-04T12:53:43Z","cvss":[{"version":"4.0","score":5.3,"vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N","level":"medium"}],"cwes":["CWE-79"],"updated_at":"2026-11-02T14:38:55.953734Z"}],"nvd":[{"id":"CVE-2025-54881","description":"Mermaid is a JavaScript based diagramming and charting tool that uses Markdown-inspired text definitions and a renderer to create and modify complex diagrams. In the default configuration of mermaid 10.9.0-rc.1 to 11.9.0, user supplied input for sequence diagram labels is passed to innerHTML during calculation of element size, causing XSS.","status":"published","published":"2025-08-19T17:15:41.247Z","modified":"2026-06-17T09:40:51.563Z","cvss":[{"version":"4.0","score":5.3,"vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X","level":"medium","assessor":"secondary"}],"cwes":["CWE-79"],"updated_at":"2026-11-02T14:11:24.730342Z"}],"osv":[{"id":"CVE-2025-54881","title":"Mermaid improperly sanitizes of sequence diagram labels leading to XSS","description":"Mermaid is a JavaScript based diagramming and charting tool that uses Markdown-inspired text definitions and a renderer to create and modify complex diagrams. In the default configuration of mermaid 10.9.0-rc.1 to 11.9.0, user supplied input for sequence diagram labels is passed to innerHTML during calculation of element size, causing XSS.","status":"published","published":"2025-08-19T17:04:29.453Z","modified":"2026-10-28T02:30:43.025831849Z","cvss":[{"version":"4.0","score":5.3,"vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N","level":"medium"}],"cwes":["CWE-79"],"updated_at":"2026-11-02T15:44:50.863921Z"},{"id":"GHSA-7rqq-prvp-x9jh","title":"Mermaid improperly sanitizes sequence diagram labels leading to XSS","description":"### Summary\nIn the default configuration of mermaid 11.9.0, user supplied input for sequence diagram labels is passed to `innerHTML` during calculation of element size, causing XSS.\n\n### Details\nSequence diagram node labels with KaTeX delimiters are passed through `calculateMathMLDimensions`. This method passes the full label to `innerHTML` which allows allows malicious users to inject arbitrary HTML and cause XSS when mermaid-js is used in it's default configuration (with KaTeX support enabled). \n\nThe vulnerability lies here:\n\n```ts\nexport const calculateMathMLDimensions = async (text: string, config: MermaidConfig) =\u003e {\n  text = await renderKatex(text, config);\n  const divElem = document.createElement('div');\n  divElem.innerHTML = text; // XSS sink, text has not been sanitized.\n  divElem.id = 'katex-temp';\n  divElem.style.visibility = 'hidden';\n  divElem.style.position = 'absolute';\n  divElem.style.top = '0';\n  const body = document.querySelector('body');\n  body?.insertAdjacentElement('beforeend', divElem);\n  const dim = { width: divElem.clientWidth, height: divElem.clientHeight };\n  divElem.remove();\n  return dim;\n};\n```\n\nThe `calculateMathMLDimensions` method was introduced in 5c69e5fdb004a6d0a2abe97e23d26e223a059832 two years ago, which was released in [Mermaid 10.9.0](https://github.com/mermaid-js/mermaid/releases/tag/v10.9.0).\n\n### PoC\nRender the following diagram and observe the modified DOM.\n\n```\nsequenceDiagram\n    participant A as Alice\u003cimg src=\"x\" onerror=\"document.write(`xss on ${document.domain}`)\"\u003e$$\\\\text{Alice}$$\n    A-\u003e\u003eJohn: Hello John, how are you?\n    Alice-)John: See you later!\n```\n\nHere is a PoC on mermaid.live: https://mermaid.live/edit#pako:eNpVUMtOwzAQ_BWzyoFKaRTyaFILiio4IK7ckA-1km1iKbaLY6spUf4dJ0AF68uOZ2dm7REqXSNQ6PHDoarwWfDGcMkUudaJGysqceLKkj3hPdl3osJ7IRvSm-qBwcCAaIXGaONRrSsnUdnobITF28PQ954lwXglai25UNNhxWAXBMyXxcGOi-3kL_5k79e73atuFSUv2HWazH1IWn0m3CC5aPf4b3p2WK--BW-4DJCOWzQ3TM0HQmiMqIFa4zAEicZv4iGMsw0D26JEBtS3NR656ywDpiYv869_11r-Ko12TQv0yLveI3eqfcjP111HUNVonrRTFuhdsVgAHWEAmuRxlG7SuEzKMi-yJAnhAjTLIk_EcbFJtuk2y9MphM8lM47KIp--AOZghtU\n\n### Impact\nXSS on all sites that use mermaid and render user supplied diagrams without further sanitization.\n\n### Remediation\nThe value of the `text` argument for the `calculateMathMLDimensions` method needs to be sanitized before getting passed on to `innerHTML`.","status":"published","published":"2025-08-19T20:16:58Z","modified":"2026-08-07T08:12:11.518764754Z","cvss":[{"version":"4.0","score":5.3,"vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N","level":"medium"}],"cwes":["CWE-79"],"updated_at":"2026-11-02T15:46:41.349637Z"},{"id":"UBUNTU-CVE-2025-54881","description":"Mermaid is a JavaScript based diagramming and charting tool that uses Markdown-inspired text definitions and a renderer to create and modify complex diagrams. In the default configuration of mermaid 10.9.0-rc.1 to 11.9.0, user supplied input for sequence diagram labels is passed to innerHTML during calculation of element size, causing XSS.","status":"published","published":"2025-08-19T17:15:00Z","modified":"2026-10-17T12:58:37.978592128Z","cvss":[{"version":"4.0","score":5.3,"vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N","level":"medium"}],"updated_at":"2026-11-02T16:55:50.817402Z"}]}}
