Skip to main content

CVE-2022-36036: CWE-94: Improper Control of Generation of Code ('Code Injection') in sjwall mdx-mermaid

Medium
Published: Mon Aug 29 2022 (08/29/2022, 17:20:10 UTC)
Source: CVE
Vendor/Project: sjwall
Product: mdx-mermaid

Description

mdx-mermaid provides plug and play access to Mermaid in MDX. There is a potential for an arbitrary javascript injection in versions less than 1.3.0 and 2.0.0-rc1. Modify any mermaid code blocks with arbitrary code and it will execute when the component is loaded by MDXjs. This vulnerability was patched in version(s) 1.3.0 and 2.0.0-rc2. There are currently no known workarounds.

AI-Powered Analysis

AILast updated: 06/21/2025, 23:52:43 UTC

Technical Analysis

CVE-2022-36036 is a code injection vulnerability classified under CWE-94 (Improper Control of Generation of Code) affecting the sjwall mdx-mermaid package. mdx-mermaid is a tool that integrates Mermaid diagrams into MDX (Markdown with JSX) environments, allowing users to embed and render Mermaid code blocks within MDX content. The vulnerability exists in versions prior to 1.3.0 and specifically in version 2.0.0-rc1. It allows an attacker to inject arbitrary JavaScript code by modifying Mermaid code blocks. When the vulnerable mdx-mermaid component loads these maliciously crafted Mermaid blocks, the injected JavaScript executes in the context of the MDXjs environment. This can lead to unauthorized code execution within applications that render MDX content using the affected versions of mdx-mermaid. The vulnerability was patched in versions 1.3.0 and 2.0.0-rc2. No known workarounds exist, and no exploits have been reported in the wild to date. The root cause is insufficient sanitization or validation of Mermaid code blocks before rendering, allowing arbitrary script injection. This vulnerability primarily impacts applications that dynamically render user-supplied or untrusted Mermaid diagrams via mdx-mermaid, potentially exposing them to cross-site scripting (XSS) or broader code execution risks depending on the application context.

Potential Impact

For European organizations, the impact of this vulnerability depends on their use of mdx-mermaid in web applications, documentation portals, or developer tools that render MDX content with Mermaid diagrams. Exploitation could lead to arbitrary JavaScript execution, resulting in data theft, session hijacking, or unauthorized actions within the affected application. This poses confidentiality and integrity risks, especially for organizations handling sensitive or proprietary information. Availability impact is limited but could occur if injected code disrupts application functionality. Since mdx-mermaid is often used in developer documentation or internal tools, exploitation could facilitate lateral movement or privilege escalation within corporate networks. The medium severity rating reflects the need for attacker control over Mermaid code blocks, which may require some level of access or user interaction to inject malicious content. However, the lack of authentication requirements for rendering MDX content in some deployments could increase exposure. European organizations relying on open-source documentation frameworks or developer portals integrating mdx-mermaid should prioritize remediation to prevent potential exploitation.

Mitigation Recommendations

1. Upgrade mdx-mermaid to version 1.3.0 or later, or 2.0.0-rc2 or later, as these versions contain the patch for this vulnerability. 2. Audit all applications and documentation sites using mdx-mermaid to identify affected versions. 3. Implement strict input validation and sanitization on Mermaid code blocks before rendering, especially if user-generated content is accepted. 4. Restrict the ability to modify Mermaid code blocks to trusted users only, minimizing the risk of malicious injection. 5. Employ Content Security Policy (CSP) headers to limit the execution of unauthorized scripts in web applications rendering MDX content. 6. Monitor logs and application behavior for unusual script execution or anomalies related to Mermaid rendering. 7. Educate developers and content creators about the risks of embedding untrusted Mermaid code and enforce secure content creation policies. 8. Consider isolating MDX rendering environments or sandboxing to contain potential code execution impacts.

Need more detailed analysis?Get Pro

Technical Details

Data Version
5.1
Assigner Short Name
GitHub_M
Date Reserved
2022-07-15T00:00:00.000Z
Cisa Enriched
true

Threat ID: 682d9849c4522896dcbf681b

Added to database: 5/21/2025, 9:09:29 AM

Last enriched: 6/21/2025, 11:52:43 PM

Last updated: 7/26/2025, 2:47:39 AM

Views: 14

Actions

PRO

Updates to AI analysis are available only with a Pro account. Contact root@offseq.com for access.

Please log in to the Console to use AI analysis features.

Need enhanced features?

Contact root@offseq.com for Pro access with improved analysis and higher rate limits.

Latest Threats