CVE-2025-54881: Mermaid Cross-Site Scripting Vulnerability

MODERATE
Advisory Identifier: GHSA-7rqq-prvp-x9jh
CWE-79
Published
Advisory Summary

CVE-2025-54881 is a MODERATE cross-site scripting vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting Mermaid libraries in the npm ecosystem. The issue involves mermaid improperly sanitizes sequence diagram labels leading to xss. Remediation is available by upgrading affected packages to version 11.10.0, 10.9.4.

CVE-2025-54881 at a Glance

CVE Identifier CVE-2025-54881
GHSA Identifier GHSA-7rqq-prvp-x9jh
Severity MODERATE
CVSS v3.1 Base Score N/A
CWE Classification CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Affected Product Mermaid
Package Ecosystem npm
Published Date
Last Updated

How to Fix CVE-2025-54881

To remediate this vulnerability, upgrade all affected Mermaid dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

mermaid fixed: 11.10.0
npm install mermaid@11.10.0
mermaid fixed: 10.9.4
npm install mermaid@10.9.4
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls mermaid

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2025-54881, inspect your project dependencies using npm:

npm ls mermaid

Analyze the terminal output to locate any version of Mermaid in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 11.10.0), your application is affected.

Note: The npm ls mermaid command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), where the product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. In Mermaid, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Summary In the default configuration of mermaid 11.9.0, user supplied input for sequence diagram labels is passed to `innerHTML` during calculation of element size, causing XSS. ### Details Sequence diagram node labels with KaTeX delimiters are passed through `calculateMathMLDimensions`. This method passes the full label to `innerHTML` which allows allows malicious users to inject arbitrary HTML and cause XSS when mermaid-js is used in it's default configuration (with KaTeX support enabled). The vulnerability lies here: ```ts export const calculateMathMLDimensions = async (text: string, config: MermaidConfig) => { text = await renderKatex(text, config); const divElem = document.createElement('div'); divElem.innerHTML = text; // XSS sink, text has not been sanitized. divElem.id = 'katex-temp'; divElem.style.visibility = 'hidden'; divElem.style.position = 'absolute'; divElem.style.top = '0'; const body = document.querySelector('body'); body?.insertAdjacentElement('beforeend', divElem); const dim = { width: divElem.clientWidth, height: divElem.clientHeight }; divElem.remove(); return dim; }; ``` The `calculateMathMLDimensions` method was introduced in 5c69e5fdb004a6d0a2abe97e23d26e223a059832 two years ago, which was released in [Mermaid 10.9.0](https://github.com/mermaid-js/mermaid/releases/tag/v10.9.0). ### PoC Render the following diagram and observe the modified DOM. ``` sequenceDiagram participant A as Alice<img src="x" onerror="document.write(`xss on ${document.domain}`)">$$\\text{Alice}$$ A->>John: Hello John, how are you? Alice-)John: See you later! ``` Here is a PoC on mermaid.live: https://mermaid.live/edit#pako:eNpVUMtOwzAQ_BWzyoFKaRTyaFILiio4IK7ckA-1km1iKbaLY6spUf4dJ0AF68uOZ2dm7REqXSNQ6PHDoarwWfDGcMkUudaJGysqceLKkj3hPdl3osJ7IRvSm-qBwcCAaIXGaONRrSsnUdnobITF28PQ954lwXglai25UNNhxWAXBMyXxcGOi-3kL_5k79e73atuFSUv2HWazH1IWn0m3CC5aPf4b3p2WK--BW-4DJCOWzQ3TM0HQmiMqIFa4zAEicZv4iGMsw0D26JEBtS3NR656ywDpiYv869_11r-Ko12TQv0yLveI3eqfcjP111HUNVonrRTFuhdsVgAHWEAmuRxlG7SuEzKMi-yJAnhAjTLIk_EcbFJtuk2y9MphM8lM47KIp--AOZghtU ### Impact XSS on all sites that use mermaid and render user supplied diagrams without further sanitization. ### Remediation The value of the `text` argument for the `calculateMathMLDimensions` method needs to be sanitized before getting passed on to `innerHTML`.

CVE-2025-54881 Affected Mermaid Versions

2 component(s)
Fixed Versions:
11.10.010.9.4
Product / Package Ecosystem Affected Versions Fixed Version
mermaid
npm
≥ 11.0.0-alpha.1
< 11.10.0
11.10.0
mermaid
npm
≥ 10.9.0-rc.1
< 10.9.4
10.9.4

References

Frequently Asked Questions

What is CVE-2025-54881?
CVE-2025-54881 is a security vulnerability in Mermaid involving Mermaid improperly sanitizes sequence diagram labels leading to XSS under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
Which Mermaid versions are affected?
Affected versions include releases prior to 11.10.0, 10.9.4 across affected packages: mermaid.
What version fixes CVE-2025-54881?
Upgrading to 11.10.0, 10.9.4 (or the latest patched release for your respective branch) resolves the vulnerability.
Is mermaid affected?
Yes, mermaid is affected in releases prior to 11.10.0, 10.9.4. Upgrade your dependency to 11.10.0, 10.9.4 or later.
What CWE is associated with CVE-2025-54881?
CVE-2025-54881 is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.).
How can I check npm dependencies for CVE-2025-54881?
Run the dependency tree command: 'npm ls mermaid'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-7rqq-prvp-x9jh",
  "modified" : "2025-08-22T22:52:04Z",
  "published" : "2025-08-19T20:16:58Z",
  "aliases" : [ "CVE-2025-54881" ],
  "summary" : "Mermaid improperly sanitizes sequence diagram labels leading to XSS",
  "details" : "### Summary\nIn the default configuration of mermaid 11.9.0, user supplied input for sequence diagram labels is passed to `innerHTML` during calculation of element size, causing XSS.\n\n### Details\nSequence diagram node labels with KaTeX delimiters are passed through `calculateMathMLDimensions`. This method passes the full label to `innerHTML` which allows allows malicious users to inject arbitrary HTML and cause XSS when mermaid-js is used in it's default configuration (with KaTeX support enabled). \n\nThe vulnerability lies here:\n\n```ts\nexport const calculateMathMLDimensions = async (text: string, config: MermaidConfig) => {\n  text = await renderKatex(text, config);\n  const divElem = document.createElement('div');\n  divElem.innerHTML = text; // XSS sink, text has not been sanitized.\n  divElem.id = 'katex-temp';\n  divElem.style.visibility = 'hidden';\n  divElem.style.position = 'absolute';\n  divElem.style.top = '0';\n  const body = document.querySelector('body');\n  body?.insertAdjacentElement('beforeend', divElem);\n  const dim = { width: divElem.clientWidth, height: divElem.clientHeight };\n  divElem.remove();\n  return dim;\n};\n```\n\nThe `calculateMathMLDimensions` method was introduced in 5c69e5fdb004a6d0a2abe97e23d26e223a059832 two years ago, which was released in [Mermaid 10.9.0](https://github.com/mermaid-js/mermaid/releases/tag/v10.9.0).\n\n### PoC\nRender the following diagram and observe the modified DOM.\n\n```\nsequenceDiagram\n    participant A as Alice<img src=\"x\" onerror=\"document.write(`xss on ${document.domain}`)\">$$\\\\text{Alice}$$\n    A->>John: Hello John, how are you?\n    Alice-)John: See you later!\n```\n\nHere is a PoC on mermaid.live: https://mermaid.live/edit#pako:eNpVUMtOwzAQ_BWzyoFKaRTyaFILiio4IK7ckA-1km1iKbaLY6spUf4dJ0AF68uOZ2dm7REqXSNQ6PHDoarwWfDGcMkUudaJGysqceLKkj3hPdl3osJ7IRvSm-qBwcCAaIXGaONRrSsnUdnobITF28PQ954lwXglai25UNNhxWAXBMyXxcGOi-3kL_5k79e73atuFSUv2HWazH1IWn0m3CC5aPf4b3p2WK--BW-4DJCOWzQ3TM0HQmiMqIFa4zAEicZv4iGMsw0D26JEBtS3NR656ywDpiYv869_11r-Ko12TQv0yLveI3eqfcjP111HUNVonrRTFuhdsVgAHWEAmuRxlG7SuEzKMi-yJAnhAjTLIk_EcbFJtuk2y9MphM8lM47KIp--AOZghtU\n\n### Impact\nXSS on all sites that use mermaid and render user supplied diagrams without further sanitization.\n\n### Remediation\nThe value of the `text` argument for the `calculateMathMLDimensions` method needs to be sanitized before getting passed on to `innerHTML`.",
  "severity" : [ {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "mermaid"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "11.0.0-alpha.1"
      }, {
        "fixed" : "11.10.0"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "mermaid"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "10.9.0-rc.1"
      }, {
        "fixed" : "10.9.4"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/mermaid-js/mermaid/security/advisories/GHSA-7rqq-prvp-x9jh"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2025-54881"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/mermaid-js/mermaid/commit/5c69e5fdb004a6d0a2abe97e23d26e223a059832"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/mermaid-js/mermaid/commit/685516a85ec1df64cefd4fd15f26533be87d458e"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/mermaid-js/mermaid"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-79" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2025-08-19T20:16:58Z",
    "nvd_published_at" : "2025-08-19T17:15:41Z"
  }
}