Mermaid: Improper sanitization of `classDefs` in diagrams leads to CSS injection
Moderate severity
GitHub Reviewed
Published
May 11, 2026
in
mermaid-js/mermaid
•
Updated May 11, 2026
Package
Affected versions
>= 11.0.0-alpha.1, <= 11.14.0
<= 10.9.5
Patched versions
11.15.0
10.9.6
Description
Published to the GitHub Advisory Database
May 11, 2026
Reviewed
May 11, 2026
Last updated
May 11, 2026
Details
The state diagram and any other diagram type that routes user-controlled style strings through createCssStyles parser for Mermaid v11.14.0 and earlier captures
classDefvalues with an unrestricted regex:The value passes unsanitized through
addStyleClass()->createCssStyles()->style.innerHTML(mermaidAPI.ts:418). A}in the value closes the generated CSS selector, and everything after becomes a new CSS rule on the page.PoC
Live demo:
https://mermaid.live/edit#pako:eNpFjzFvgzAQhf-KdVNbEcBgMHhtlkqtOnSJKi8ONsYKBmRMlRTx3-skanvTfbp7996t0IxSAYPZC6_2Rmgn7O4rQ00v5nmvWnRG29OKjqI5aTcug9wZK7RiaHH9A4fO-4kliVXSiFibqbvEzWjvnHxo_fI6vR3e6cGXyX2qTcvhcYMItDMSmHeLisAqZ8UVYeUDQhx8p6ziwEIrhTtx4MNVM4nhcxztrywE0h2wVvRzoGWS_z_8rahBKvcckntgmN5OAFvhDIzUNCZZQXCR5nVaZkUEF2BVFpOcEkoxxhUuyRbB980yjStapKHqoKFlhvPtB7BFZEU
Patches
This has been patched in:
Workarounds
Setting
"securityLevel": "sandbox"will prevent this, by rendering the mermaid diagram in a sandboxed<iframe>.Impact
Enables page defacement, user tracking via
url()callbacks, and DOM attribute exfiltration via CSS:has()selectors.References