Skip to main content
CVE Vulnerability Database
Vulnerability Database/CVE-2025-54881

CVE-2025-54881: Mermaid XSS Vulnerability

CVE-2025-54881 is a cross-site scripting flaw in Mermaid that allows attackers to inject malicious scripts through sequence diagram labels. This article covers the technical details, affected versions, and mitigation.

Published:

CVE-2025-54881 Overview

CVE-2025-54881 is a Cross-Site Scripting (XSS) vulnerability affecting Mermaid, a JavaScript-based diagramming and charting tool that renders Markdown-inspired text definitions into diagrams. In the default configuration of Mermaid versions 10.9.0-rc.1 through 11.9.0, user-supplied input for sequence diagram labels is passed to innerHTML during element size calculation. Attackers can inject malicious HTML or JavaScript through crafted sequence diagram content that executes in the victim's browser context. The flaw is categorized under CWE-79: Improper Neutralization of Input During Web Page Generation.

Critical Impact

Applications that render untrusted Mermaid diagrams can execute attacker-controlled scripts in user browsers, leading to session theft, credential harvesting, or unauthorized actions against the hosting application.

Affected Products

  • Mermaid 10.9.0-rc.1 through 11.9.0
  • Applications embedding vulnerable Mermaid versions for client-side diagram rendering
  • Documentation platforms, wikis, and note-taking tools that render user-supplied Mermaid content

Discovery Timeline

  • 2025-08-19 - CVE-2025-54881 published to NVD
  • 2026-06-17 - Last updated in NVD database

Technical Details for CVE-2025-54881

Vulnerability Analysis

Mermaid parses text-based diagram definitions and renders them as SVG within the browser. During sequence diagram processing, the library calculates rendered element dimensions by inserting label text into a temporary DOM node via innerHTML. Because the label content is not sanitized before assignment, any HTML markup embedded in a label is parsed as live DOM.

An attacker who can submit a sequence diagram definition to a vulnerable application can supply a label containing <img>, <svg>, or other elements with event handlers. When Mermaid measures the element size, the browser evaluates the injected markup and fires attacker-controlled JavaScript. The vulnerability requires user interaction, such as loading a page or opening a document that renders the diagram.

Root Cause

The root cause is direct assignment of untrusted input to the innerHTML property during the label sizing routine, without passing the content through DOMPurify or an equivalent sanitizer. The default configuration path does not enforce securityLevel: 'strict' behavior for the sizing helper, so labels bypass the sanitization applied elsewhere in the render pipeline.

Attack Vector

Exploitation is network-based and requires no privileges. An attacker submits a sequence diagram definition to any application that renders Mermaid client-side. When another user views the rendered page, the injected script executes in that user's browser session, inheriting the origin of the hosting application.

typescript
// Security patch in packages/mermaid/src/diagrams/common/common.ts
 import DOMPurify from 'dompurify';
-// @ts-ignore @types/katex does not work
-import katex from 'katex';
 import { MermaidConfig } from '../../config.type.js';
 
 export const lineBreakRegex = /<br\s*\/?>/gi;
// Source: https://github.com/mermaid-js/mermaid/commit/5c69e5fdb004a6d0a2abe97e23d26e223a059832

The upstream fix refactors rendering functions to properly sanitize and asynchronously process vertex data. The patched flow renderer converts synchronous label handling into an async pipeline that passes content through DOMPurify before insertion:

javascript
// Security patch in packages/mermaid/src/diagrams/flowchart/flowRenderer-v2.js
-export const addVertices = function (vert, g, svgId, root, doc, diagObj) {
+export const addVertices = async function (vert, g, svgId, root, doc, diagObj) {
   const svg = root.select(`[id="${svgId}"]`);
   const keys = Object.keys(vert);
 
-  keys.forEach(function (id) {
+  for (const id of keys) {
     const vertex = vert[id];
// Source: https://github.com/mermaid-js/mermaid/commit/5c69e5fdb004a6d0a2abe97e23d26e223a059832

Detection Methods for CVE-2025-54881

Indicators of Compromise

  • Sequence diagram source containing HTML tags such as <img onerror=, <svg onload=, or <script> inside participant labels or messages
  • Unexpected outbound requests from browsers rendering user-generated Mermaid content, particularly to attacker-controlled domains
  • JavaScript errors or console warnings from Mermaid rendering routines that reference unexpected DOM insertion

Detection Strategies

  • Scan repositories, wikis, and content stores for Mermaid code blocks containing HTML event handler attributes (onerror, onload, onclick) within label text
  • Inventory front-end dependencies to identify applications shipping Mermaid versions between 10.9.0-rc.1 and 11.9.0
  • Deploy Content Security Policy (CSP) reporting to capture inline script or event handler violations triggered by rendered diagrams

Monitoring Recommendations

  • Log and review user-submitted diagram content in collaborative platforms for anomalous HTML markup
  • Monitor browser telemetry and CSP violation reports for unexpected script execution originating from diagram render paths
  • Track Software Composition Analysis (SCA) output for the mermaid npm package to flag vulnerable versions in production builds

How to Mitigate CVE-2025-54881

Immediate Actions Required

  • Upgrade Mermaid to a version later than 11.9.0 that contains the fix referenced in GHSA-7rqq-prvp-x9jh
  • Audit applications that render Mermaid diagrams from untrusted sources and restrict submission until patched
  • Enforce a strict Content Security Policy that blocks inline event handlers and unauthorized script origins

Patch Information

The Mermaid maintainers published fixes in commits 5c69e5f and 685516a. The advisory GHSA-7rqq-prvp-x9jh documents the affected version range and remediation guidance. Update the mermaid dependency through npm or yarn and rebuild affected front-end bundles.

Workarounds

  • Configure Mermaid with securityLevel: 'strict' to force sanitization of user-supplied content where the configuration honors it
  • Pre-sanitize diagram source on the server using an HTML-aware sanitizer before passing it to the Mermaid renderer
  • Disable client-side Mermaid rendering for content submitted by untrusted or unauthenticated users until the patched version is deployed
bash
# Update Mermaid to a patched release
npm install mermaid@latest

# Verify installed version is above 11.9.0
npm ls mermaid

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Default Legacy - Prefooter | Experience the World’s Most Advanced Cybersecurity Platform

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.