# CVE-2021-35513: Mermaid cross-site scripting in antiscript feature

Source: https://junglewise.ai/threats/cve-2021-35513-mermaid-cross-site-scripting-in-antiscript-feature  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2021-12-10. Updated: 2026-09-25  
License: CC BY 4.0 with a link back

CVE-2021-35513 · Severity: low · CVSS 3.1 · Published 2021-12-10

Mermaid is a JavaScript library used to create diagrams and flowcharts from text descriptions. The antiscript security feature, which is meant to block malicious JavaScript code, fails to properly sanitize javascript: URLs, allowing attackers to inject arbitrary JavaScript that executes in users' browsers. This could enable credential theft, session hijacking, or malware distribution to anyone viewing a diagram created by an attacker.

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

## Quick answers

**Is CVE-2021-35513 exploited in the wild?** No. Junglewise Threat Intelligence has no report of CVE-2021-35513 being exploited in the wild.

**How severe is CVE-2021-35513?** Low severity, with a CVSS score of 3.1, published 10 December 2021.

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

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

**How is CVE-2021-35513 attacked?** It is attacked over the network.

**Am I affected by CVE-2021-35513?** 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.11.0 or later

  ```sh
  npm install mermaid@8.11.0
  ```


## Technical details

Mermaid is a diagram rendering library for web applications. The vulnerability is a stored/reflected XSS flaw in the antiscript option, which claims to block malicious script content. The root cause is inadequate sanitization of javascript: URLs in diagram elements (such as links in SVG nodes). An attacker can craft a malicious diagram definition containing javascript: protocol URLs that execute arbitrary JavaScript when a user views the rendered diagram in a browser. No authentication is required; the attack vector is network-based and requires user interaction (opening/viewing the diagram). The vulnerability was patched in version 8.11.0, which adds proper filtering of javascript: URLs when antiscript mode is enabled. The fix involves stripping javascript: protocol handlers before rendering diagram elements.

## Affected products

- mermaid-js mermaid before 8.11.0

## Identifiers

- CVE-2021-35513
- GHSA-4f6x-49g2-99fm

## Timeline

- 2021-06-27: disclosed: Vulnerability reported and discussed in GitHub issue #2122
- 2021-06-27: patched: Fix merged in PR #2123
- 2021-12-10: advisory: GitHub Security Advisory GHSA-4f6x-49g2-99fm published

## References

- [https://github.com/mermaid-js/mermaid/issues/2122](https://github.com/mermaid-js/mermaid/issues/2122)
- [https://github.com/mermaid-js/mermaid/pull/2123](https://github.com/mermaid-js/mermaid/pull/2123)
- [https://github.com/mermaid-js/mermaid/pull/2123/commits/3d22fa5d2435de5acc18de6f88474a6e8675a60e](https://github.com/mermaid-js/mermaid/pull/2123/commits/3d22fa5d2435de5acc18de6f88474a6e8675a60e)
- [https://github.com/mermaid-js/mermaid/releases/tag/8.11.0-rc2](https://github.com/mermaid-js/mermaid/releases/tag/8.11.0-rc2)

## 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)
