mermaid
Affected
- introduced
11.0.0-alpha.1, fixed11.15.0(semver)
Fixed versions
11.15.0
Fix
- Fixed version
11.15.0npm install [email protected]
Advisory
Also known as: CVE-2026-41148
Mermaid: Improper sanitization of classDefs in diagrams leads to CSS injection
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")}
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.
Medium Basis: The source's own band: MODERATE
11.0.0-alpha.1, fixed 11.15.0 (semver)11.15.0
11.15.0npm install [email protected]0, fixed 10.9.6 (semver)10.9.6
10.9.6npm install [email protected]Fix commands are the export's own generic commands. Ojuju never runs them. Check them against your setup first.
Check your own computer: guard packages check
Source: GitHub Advisory Database (reviewed advisories) · CC BY 4.0