GitHub Advisoryadvisory · npm
GHSA-87f9-hvmw-gh4p Mermaid: Improper sanitization of configuration leads to CSS injection
MEDIUM
Official page ↗
- Aliases
- CVE-2026-41159
- Ecosystem
- npm
- Packages
- mermaid
- Severity
- Moderate
- CVSS vector
- 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
- Weaknesses
- CWE-94
- Reviewed
- 2026-05-11
Affected packages
• npm mermaid: >= 11.0.0-alpha.1, < 11.15.0 → fixed in 11.15.0
• npm mermaid: < 10.9.6 → fixed in 10.9.6
Description
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
Related
Alias · CVE (1)
- CVE-2026-41159 Mermaid is a JavaScript tool that uses Markdown-inspired text to create and modify diagrams and charts. vulnerability
Weakness · CWE (1)
- CWE-94 Improper Control of Generation of Code weakness
References
- https://github.com/mermaid-js/mermaid/security/advisories/GHSA-87f9-hvmw-gh4p web
- https://nvd.nist.gov/vuln/detail/CVE-2026-41159 advisory
- https://github.com/mermaid-js/mermaid/commit/64769738d5b59211e1decb471ffbaca8afec51aa web
- https://github.com/mermaid-js/mermaid/commit/a9d9f0d8eb790349121508688cd338253fd80d76 web
- https://github.com/mermaid-js/mermaid package
- https://github.com/mermaid-js/mermaid/releases/tag/mermaid%4011.15.0 web
- https://github.com/mermaid-js/mermaid/releases/tag/[email protected] web
- https://github.com/mermaid-js/mermaid/releases/tag/v10.9.6 web