Executive brief
Mermaid is a popular JavaScript library used to generate charts and diagrams from text. A vulnerability in how it handles diagram styles allows an attacker to inject malicious CSS code into a web page. This could lead to page defacement, unauthorized tracking of users, or the theft of sensitive information displayed on the page.
Technical details
A CSS injection vulnerability exists in Mermaid's state diagram and other diagram types that utilize the createCssStyles parser. The root cause is an unrestricted regular expression used to capture classDef values, which fails to sanitize user-controlled style strings. By including a closing brace '}' in a class definition, an attacker can break out of the intended CSS selector and inject arbitrary CSS rules. This can be exploited to perform page defacement, track users via URL callbacks, or exfiltrate DOM attributes using CSS selectors like :has(). The vulnerability is patched in versions 11.15.0 and 10.9.6.
Affected products
- mermaid-js mermaid >= 11.0.0-alpha.1, <= 11.14.0; <= 10.9.5
Timeline
- 2026-05-11: disclosed
- 2026-05-11: advisory
- 2026-05-11: patched