CVE-2026-41159
JSON

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 packageVersionsReported by
mermaid-js mermaid>= 11.0.0-alpha.1, < 11.15.0, < 10.9.6CVE List
mermaid (npm)from 11.0.0-alpha.1 before 11.15.0, before 10.9.6GitHub Advisory Database
mermaid_project mermaidbefore 10.9.6, from 11.0.0 before 11.15.0NVD

All scores

GitHub_M5.3medium CVSS:4.0CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:L/VA:N/SC:L/SI:L/SA:L
GitHubmedium CVSS:4.0CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:L/VA:N/SC:L/SI:L/SA:L
NVD5.3medium CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L

Classification

CWE-94

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
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

SourceRecordLicence
CVE ListCVE-2026-41159 changed 2026-07-01CVE Terms of Use
GitHub Advisory DatabaseGHSA-87f9-hvmw-gh4p changed 2026-09-10CC-BY-4.0
NVDCVE-2026-41159 changed 2026-07-21Public domain