5.3medium
Mermaid: Improper sanitization of configuration leads to CSS injection
- Severity
- 5.3medium CVSS:4.0 by GitHub_M
- Exploit likelihood
- 0.49% (higher than 43% of CVEs; EPSS, by FIRST)
- Published
- Last changed
- Assigned by
- GitHub_M
- Also known as
- GHSA-87f9-hvmw-gh4p
Description
Mermaid is a JavaScript tool that uses Markdown-inspired text to create and modify diagrams and charts. Prior to 10.9.6 and 11.15.0, Mermaid's default configuration allows injecting CSS that applies outside of the Mermaid diagram via the fontFamily, themeCSS, and altFontFamily configuration options. The injected CSS exploits stylis's & (scope reference) handling. :not(&) escapes the #mermaid-xxx automatic 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. This vulnerability is fixed in 10.9.6 and 11.15.0.
Affected
| Product or package | Versions | Reported by |
|---|---|---|
| mermaid-js mermaid | >= 11.0.0-alpha.1, < 11.15.0, < 10.9.6 | CVE List |
| mermaid (npm) | from 11.0.0-alpha.1 before 11.15.0, before 10.9.6 | GitHub Advisory Database |
| mermaid_project mermaid | before 10.9.6, from 11.0.0 before 11.15.0 | NVD |
All scores
| GitHub_M | 5.3medium CVSS:4.0 | CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:L/VA:N/SC:L/SI:L/SA:L |
| GitHub | medium CVSS:4.0 | CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:L/VA:N/SC:L/SI:L/SA:L |
| NVD | 5.3medium CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L |
Classification
SSVC (CISA-ADP): exploitation none, automatable no, technical impact partial.
What each source says
CVE List
Mermaid is a JavaScript tool that uses Markdown-inspired text to create and modify diagrams and charts. Prior to 10.9.6 and 11.15.0, Mermaid's default configuration allows injecting CSS that applies outside of the Mermaid diagram via the fontFamily, themeCSS, and altFontFamily configuration options. The injected CSS exploits stylis's & (scope reference) handling. :not(&) escapes the #mermaid-xxx automatic 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. This vulnerability is fixed in 10.9.6 and 11.15.0.
GitHub Advisory Database
Impact
Mermaid's default configuration allows injecting CSS that applies outside of the Mermaid diagram via the fontFamily, themeCSS, and altFontFamily configuration options.
Live demo: mermaid.live
Example code:
%%{init: {"fontFamily": "x;a{b} :not(&){background:green !important} c{d}"}}%%
flowchart LR
A --> B
The injected CSS exploits stylis's & (scope reference) handling. :not(&) escapes the #mermaid-xxx automatic 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
- v11.15.0 (see 64769738d5b59211e1decb471ffbaca8afec51aa)
- v10.9.6 (see a9d9f0d8eb790349121508688cd338253fd80d76)
Workarounds
If you can't upgrade mermaid, you can set the secure config value in the mermaid config to avoid allowing diagrams to modify fontFamily, themeCSS, altFontFamily, and themeVariables.
Setting "securityLevel": "sandbox" will also prevent this.
Credits
Reported by @zsxsoft on behalf of @KeenSecurityLab
NVD (es)
Mermaid es una herramienta de JavaScript que utiliza texto inspirado en Markdown para crear y modificar diagramas y gráficos. Antes de las versiones 10.9.6 y 11.15.0, la configuración predeterminada de Mermaid permite inyectar CSS que se aplica fuera del diagrama de Mermaid a través de las opciones de configuración fontFamily, themeCSS y altFontFamily. El CSS inyectado explota el manejo de & (referencia de ámbito) de stylis. :not(&) escapa el alcance automático #mermaid-xxx, aplicando estilos a todos los elementos de la página. Las reglas globales at-rules (@font-face, @keyframes, @counter-style) también son inyectables, ya que stylis las eleva al nivel superior. Esto permite la desfiguración de la página y la exfiltración de atributos del DOM a través de selectores CSS :has(). Esta vulnerabilidad se corrige en las versiones 10.9.6 y 11.15.0.
References
Sources
| Source | Record | Licence |
|---|---|---|
| CVE List | CVE-2026-41159 changed 2026-07-01 | CVE Terms of Use |
| GitHub Advisory Database | GHSA-87f9-hvmw-gh4p changed 2026-09-10 | CC-BY-4.0 |
| NVD | CVE-2026-41159 changed 2026-07-21 | Public domain |