CVE-2021-43861 Incorrect sanitisation function leads to `XSS`
Attackers can execute arbitrary JavaScript on victims' machines via malicious diagrams in the Mermaid library.
- Exploited in the wild
- Not known
- Login needed
- An administrator
- Attackable
- Over the internet
- Victim action needed
- Not needed
- Fix
- Available
What is CVE-2021-43861?
CVE-2021-43861 is a high-severity cross-site scripting vulnerability in mermaid-js mermaid, published on 30 Dec 2021. An attacker needs administrator access to exploit it, with no action from the victim.
Official description
Mermaid is a Javascript based diagramming and charting tool that uses Markdown-inspired text definitions and a renderer to create and modify complex diagrams. Prior to version 8.13.8, malicious diagrams can run javascript code at diagram readers' machines. Users should upgrade to version 8.13.8 to receive a patch. There are no known workarounds aside from upgrading.
Which versions are affected by CVE-2021-43861?
2 open source packages ship an affected version, including mermaid. It affects 1 product.
| Package | Affected | Fixed in |
|---|---|---|
mermaid npm | All versions | 8.13.8 |
mermaid npm | All versions | 8.13.8 |
Products include Mermaid Project Mermaid.
How do I fix CVE-2021-43861?
Upgrade mermaid to 8.13.8 or later.
Escape output for the context it lands in and set a strict Content Security Policy. Upgrading the affected component is the real fix. More about Cross-site scripting.
Is CVE-2021-43861 being exploited?
There is no known exploitation of CVE-2021-43861 in the wild and no public exploit code.
Other vulnerabilities in mermaid-js mermaid
- CVE-2021-35513 Cross-site Scripting in Mermaid
- CVE-2026-41150 Mermaid Gantt Charts are vulnerable to an Infinite Loop DoS
- CVE-2026-41159 Mermaid: Improper sanitization of configuration leads to CSS injection
- CVE-2025-54880 Mermaid does not properly sanitize architecture diagram iconText leading to XSS
- CVE-2022-31108 Arbitrary `CSS` injection into the generated graph affecting the container HTML in mermaid.js
Sources
Also known as DEBIAN-CVE-2021-43861, GHSA-p3rp-vmj9-gv6v, UBUNTU-CVE-2021-43861.