Mermaid: Improper sanitization of configuration leads to CSS injection
Moderate severity
GitHub Reviewed
Published
May 11, 2026
in
mermaid-js/mermaid
•
Updated May 12, 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 12, 2026
Impact
Mermaid's default configuration allows injecting CSS that applies outside of the Mermaid diagram via the
fontFamily,themeCSS, andaltFontFamilyconfiguration options.Live demo: mermaid.live
Example code:
The injected CSS exploits stylis's
&(scope reference) handling.:not(&)escapes the#mermaid-xxxautomatic scoping, applying styles to all page elements. Global at-rules (@font-face,@keyframes,@counter-style) are also injectable as stylis hoists them to top level.This allows page defacement and DOM attribute exfiltration via CSS
:has()selectors.Patches
Workarounds
If you can't upgrade mermaid, you can set the
secureconfig value in the mermaid config to avoid allowing diagrams to modifyfontFamily,themeCSS,altFontFamily, andthemeVariables.Setting
"securityLevel": "sandbox"will also prevent this.Credits
Reported by @zsxsoft on behalf of @KeenSecurityLab
References