CVE-2026-41148: CWE-94: Improper Control of Generation of Code ('Code Injection') in mermaid-js mermaid
Mermaid is a JavaScript tool that uses Markdown-inspired text to create and modify diagrams and charts. Versions 10.9.5 and prior, in addition to 11.0.0-alpha.1 through 11.12.0 are vulnerable to CSS injection through improper sanitization. The state diagram (and any other diagram type that routes user-controlled style strings through the createCssStyles parser) captures classDef values using an unrestricted regex that matches everything up to a newline. That value then flows unsanitized through addStyleClass() into createCssStyles() and is assigned to style.innerHTML, so a closing brace (}) in the value terminates the generated CSS selector and turns everything after it into a new CSS rule on the page. This enables page defacement, user tracking via url() callbacks, and DOM attribute exfiltration. This issue has been fixed in versions 10.9.6 and 11.15.0. If developers are unable to immediately upgrade, they can work around this issue by setting "securityLevel": "sandbox", which prevents the issue by rendering the mermaid diagram in a sandboxed <iframe>.
AI Analysis
Technical Summary
Mermaid-js mermaid versions <=10.9.5 and 11.0.0-alpha.1 through 11.12.0 suffer from a CSS injection vulnerability due to improper sanitization of classDef values routed through the createCssStyles parser. The vulnerability arises because the regex capturing classDef values is unrestricted and allows injection of closing braces, which terminate CSS selectors and inject new CSS rules. This can be exploited to perform page defacement, user tracking via CSS url() callbacks, and exfiltration of DOM attributes. The vulnerability is identified as CWE-94 (Improper Control of Generation of Code). It is fixed in versions 10.9.6 and 11.15.0. Developers unable to upgrade immediately can mitigate by enabling the "securityLevel": "sandbox" setting, which uses a sandboxed iframe for rendering.
Potential Impact
Exploitation of this vulnerability allows an attacker to inject arbitrary CSS into pages rendering mermaid diagrams, which can lead to visual defacement of the page, tracking users through CSS url() callbacks, and exfiltration of DOM attributes. The CVSS 4.0 base score is 5.3 (medium severity), reflecting network attack vector, low complexity, no privileges required, user interaction needed, and limited impact on confidentiality, integrity, and availability.
Mitigation Recommendations
A fix is available in mermaid versions 10.9.6 and 11.15.0. Users and developers should upgrade to these versions to remediate the vulnerability. If immediate upgrade is not feasible, setting the configuration option "securityLevel" to "sandbox" provides a temporary workaround by rendering diagrams inside a sandboxed iframe, preventing CSS injection exploitation.
CVE-2026-41148: CWE-94: Improper Control of Generation of Code ('Code Injection') in mermaid-js mermaid
Description
Mermaid is a JavaScript tool that uses Markdown-inspired text to create and modify diagrams and charts. Versions 10.9.5 and prior, in addition to 11.0.0-alpha.1 through 11.12.0 are vulnerable to CSS injection through improper sanitization. The state diagram (and any other diagram type that routes user-controlled style strings through the createCssStyles parser) captures classDef values using an unrestricted regex that matches everything up to a newline. That value then flows unsanitized through addStyleClass() into createCssStyles() and is assigned to style.innerHTML, so a closing brace (}) in the value terminates the generated CSS selector and turns everything after it into a new CSS rule on the page. This enables page defacement, user tracking via url() callbacks, and DOM attribute exfiltration. This issue has been fixed in versions 10.9.6 and 11.15.0. If developers are unable to immediately upgrade, they can work around this issue by setting "securityLevel": "sandbox", which prevents the issue by rendering the mermaid diagram in a sandboxed <iframe>.
CVSS v4.0
Score 5.3medium
Affected software
pkg:npm/mermaid-js/mermaidRun on your own infrastructure? Check whether these packages are installed with threat-finder — our free open-source scanner.
Weaknesses
AI-Powered Analysis
Machine-generated threat intelligence
Technical Analysis
Mermaid-js mermaid versions <=10.9.5 and 11.0.0-alpha.1 through 11.12.0 suffer from a CSS injection vulnerability due to improper sanitization of classDef values routed through the createCssStyles parser. The vulnerability arises because the regex capturing classDef values is unrestricted and allows injection of closing braces, which terminate CSS selectors and inject new CSS rules. This can be exploited to perform page defacement, user tracking via CSS url() callbacks, and exfiltration of DOM attributes. The vulnerability is identified as CWE-94 (Improper Control of Generation of Code). It is fixed in versions 10.9.6 and 11.15.0. Developers unable to upgrade immediately can mitigate by enabling the "securityLevel": "sandbox" setting, which uses a sandboxed iframe for rendering.
Potential Impact
Exploitation of this vulnerability allows an attacker to inject arbitrary CSS into pages rendering mermaid diagrams, which can lead to visual defacement of the page, tracking users through CSS url() callbacks, and exfiltration of DOM attributes. The CVSS 4.0 base score is 5.3 (medium severity), reflecting network attack vector, low complexity, no privileges required, user interaction needed, and limited impact on confidentiality, integrity, and availability.
Mitigation Recommendations
A fix is available in mermaid versions 10.9.6 and 11.15.0. Users and developers should upgrade to these versions to remediate the vulnerability. If immediate upgrade is not feasible, setting the configuration option "securityLevel" to "sandbox" provides a temporary workaround by rendering diagrams inside a sandboxed iframe, preventing CSS injection exploitation.
Technical Details
- Data Version
- 5.2
- Assigner Short Name
- GitHub_M
- Date Reserved
- 2026-04-17T12:59:15.739Z
- Cvss Version
- 4.0
- State
- PUBLISHED
- Remediation Level
- null
Threat ID: 6a10d8e4e1370fbb485de040
Added to database: 05/22/2026, 22:29:56 UTC
Last enriched: 05/30/2026, 20:20:36 UTC
Last updated: 07/31/2026, 19:22:58 UTC
Views: 115
Community Reviews
0 reviewsCrowdsource mitigation strategies, share intel context, and vote on the most helpful responses. Sign in to add your voice and help keep defenders ahead.
Want to contribute mitigation steps or threat intel context? Sign in or create an account to join the community discussion.
Actions
Updates to AI analysis require Pro Console access. Upgrade inside Console → Billing.
Need more coverage?
Upgrade to Pro Console for AI refresh and higher limits.
For incident response and remediation, OffSeq services can help resolve threats faster.
Latest Threats
Check if your credentials are on the dark web
Instant breach scanning across billions of leaked records. Free tier available.