# mermaid cross-site scripting in diagram rendering

Source: https://junglewise.ai/threats/mermaid-cross-site-scripting-in-diagram-rendering-f7b8e44e  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2020-09-02. Updated: 2026-09-25  
License: CC BY 4.0 with a link back

Severity: info · Published 2020-09-02

Mermaid is a popular JavaScript library used to generate diagrams (flowcharts, sequence diagrams, etc.) from text input, commonly embedded in web applications and documentation. Versions before 8.2.3 fail to properly encode user input, allowing attackers to inject malicious HTML and JavaScript code that executes in the browser. An attacker could exploit this to steal session cookies, redirect users to phishing sites, or perform actions on behalf of legitimate users.

Technologies: [mermaid (npm)](https://junglewise.ai/threats/technologies/mermaid). Vendors: [npm](https://junglewise.ai/threats/vendors/npm).

## Quick answers

**Is This vulnerability exploited in the wild?** No. Junglewise Threat Intelligence has no report of This vulnerability being exploited in the wild.

**How severe is This vulnerability?** Informational severity, published 2 September 2020.

**Which products and versions are affected?** mermaid (npm) SEMVER:introduced=0,fixed=8.2.3.

**Is there a fix for This vulnerability?** Yes. mermaid (npm): upgrade to 8.2.3 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**How is This vulnerability attacked?** It is attacked over the network.

**Am I affected?** Check whether you run mermaid (npm) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

## How to fix

- mermaid (npm): upgrade to 8.2.3 or later

  ```sh
  npm install mermaid@8.2.3
  ```


## Technical details

This is a classic Cross-Site Scripting (CWE-79) vulnerability in mermaid's diagram rendering engine. The vulnerability stems from improper output encoding when processing user-supplied diagram text; malicious payloads such as HTML img tags with onerror event handlers are rendered as executable code rather than escaped text. The attack vector is network-based and requires user interaction (the user must input or view a diagram containing the malicious payload). An attacker can execute arbitrary JavaScript in the context of the victim's browser session. The fix is available in version 8.2.3 and later.

## Affected products

- mermaid-js mermaid before 8.2.3

## Timeline

- 2020-09-02: disclosed
- 2020: patched: fix released in version 8.2.3

## References

- [https://github.com/knsv/mermaid/issues/847](https://github.com/knsv/mermaid/issues/847)
- [https://github.com/knsv/mermaid](https://github.com/knsv/mermaid)

## Related threats

- [Mermaid radar diagrams denial of service via unchecked ticks input](https://junglewise.ai/threats/cve-2026-71439-mermaid-radar-diagrams-denial-of-service-via-unchecked-ticks)
- [Mermaid prototype pollution in configuration APIs](https://junglewise.ai/threats/cve-2026-71438-mermaid-prototype-pollution-in-configuration-apis)
- [Mermaid prototype pollution in architecture-beta diagrams](https://junglewise.ai/threats/cve-2026-71437-mermaid-prototype-pollution-in-architecture-beta-diagrams)
- [Mermaid infinite loop in XY Charts axis processing](https://junglewise.ai/threats/cve-2026-71436-mermaid-infinite-loop-in-xy-charts-axis-processing)
- [Mermaid CSS injection via sibling combinators](https://junglewise.ai/threats/cve-2026-50159-mermaid-css-injection-via-sibling-combinators)
