Medium

Mermaid: Improper sanitization of configuration leads to CSS injection

  • Disclosed: 11.05.2026
  • Updated: 11.10.2026 10:22

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

Affected software

Click a technology to see all vulnerabilities affecting it.

PlatformPackageVulnerable versionsFixed in
npm package mermaid >= 11.0.0-alpha.1, < 11.15.0, < 10.9.6 11.15.0, 10.9.6

References

CVSS score -
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
Weakness (CWE)
CWE-94
Platform
npm
Package
mermaid
Disclosed
11.05.2026
Updated
11.10.2026 10:22

Sources and licenses

OSV / GitHub Advisory Database - GHSA-87f9-hvmw-gh4p - CC BY 4.0

Vulnerability history: mermaid

All published vulnerabilities of this package (npm package), newest first. Shows whether this is a one-off slip or a package that needs watching.

All (16) in the archive
Total entries
16
First → latest
09.2020 08.2026
Without a fix
0
Exploited in attacks
0

Severity breakdown

  • High 3
  • Medium 12
  • Low 1

Disclosures per year

  1. 2020: 1
  2. 2021: 1
  3. 2022: 2
  4. 2023: 0
  5. 2024: 1
  6. 2025: 2
  7. 2026: 9
Severity:
  1. Mermaid: Improper sanitization of configuration leads to CSS injection this entry
    Medium CVE-2026-41159 >= 11.0.0-alpha.1, < 11.15.0, < 10.9.6 11.15.0, 10.9.6
  2. High · 7.2 CVE-2021-43861 < 8.13.8 8.13.8
  3. High ghsa-w32g-5hqp-gg6q < 8.2.3 8.2.3

Know which vulnerabilities affect your application

With the DockRay integration and software inventory enabled, DockRay checks reported component versions against known vulnerabilities and notifies you about confirmed matches. Coverage depends on the supported technology and available advisory data.

Connect your application
DockRay newsletter

Application security in your inbox

Important vulnerabilities, actionable guidance and practical advice for your applications. Choose your technologies and follow what matters to your project.

  • A daily digest of new vulnerabilities, critical ones included.
  • Notifications about important updates.
  • Practical advice on application security and monitoring.

Leave empty to receive updates for every technology.

Free to subscribe. Unsubscribe with one click in any email.