NewApp Monitoring is liveSign up free
AgentbeamBeta
Open-source package vulnerability · npm

CVE-2026-41148: Mermaid: Improper sanitization of `classDefs` in diagrams leads to CSS injection

mediumCVSS 4.0 5.3GHSA-xcj9-5m2h-648r

Details The state diagram and any other diagram type that routes user-controlled style strings through createCssStyles parser for Mermaid v11.14.0 and earlier captures classDef values with an unrestricted regex: The value passes unsanitized through addStyleClass() - createCssStyles() - style.innerHTML (mermaidAPI.ts:418).

Published May 11, 2026 · Updated Jun 8, 2026

Affected packages

mermaid

Ecosystem
npm
Affected
>= 11.0.0-alpha.1, <= 11.14.0
Fixed in
11.15.0
Check
npm ls mermaid

mermaid

Ecosystem
npm
Affected
<= 10.9.5
Fixed in
10.9.6
Check
npm ls mermaid

Advisory details

From the GitHub Advisory Database (CC BY 4.0).

Details

The state diagram and any other diagram type that routes user-controlled style strings through createCssStyles parser for Mermaid v11.14.0 and earlier captures classDef values with an unrestricted regex:

// packages/mermaid/src/diagrams/state/parser/stateDiagram.jison:83
<CLASSDEFID>[^\n]*   { this.popState(); return 'CLASSDEF_STYLEOPTS' }

The value passes unsanitized through addStyleClass() -> createCssStyles() -> style.innerHTML (mermaidAPI.ts:418). A } in the value closes the generated CSS selector, and everything after becomes a new CSS rule on the page.

PoC

stateDiagram-v2 
      classDef x }*{ background-image: url("http://media.giphy.com/media/SggILpMXO7Xt6/giphy.gif")}

Live demo:

Patches

This has been patched in:

Workarounds

Setting `"securityLevel": "sandbox"` will prevent this, by rendering the mermaid diagram in a sandboxed <iframe>.

Impact

Enables page defacement, user tracking via url() callbacks, and DOM attribute exfiltration via CSS :has() selectors.

Credited to matejsmycka, aloisklink.

References

How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. No analysis has been written for this entry yet. Methodology

More npm vulnerabilities

All npm entries