Cross-Site Scripting (XSS) in mermaid (CVE-2025-54881)
Summary
Cross-site scripting in mermaid (CVE-2025-54881). Risk of unauthorized operations or information disclosure. Exploitable via innerHTML. Mitigation: upgrade to 10.9.4 or later.
Original description
The description as published by the source.
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:
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.
PoC
Render the following diagram and observe the modified DOM.
sequenceDiagram
participant A as Alice$$\\text{Alice}$$
A->>Joh…
Source: OSV.dev (Open Source Vulnerabilities) NVD GitHub Advisory OSV
Auto-generated summary
Assembled by SecPulse from the source data (CVSS, CWE, affected versions) using templates — no AI involved. Check the original description and references below for exact details.
A vulnerability tracked as CVE-2025-54881 has been found in mermaid.
Attackers can target a specific entry point like innerHTML over the network to misuse the product.
Risk of unauthorized operations or information disclosure.
What to do: upgrade mermaid to 10.9.4 or later.
If unsure, ask your IT team or search "mermaid CVE-2025-54881" on the vendor's site.
CVE-2025-54881 (mermaid) — CWE-79
Attack surface: innerHTML / calculateMathMLDimensions / text
Patched: 10.9.4 — apply immediately
Plan: 1) Audit SBOM/dependencies, 2) Stage→prod upgrade, 3) Add WAF/proxy monitoring on affected endpoints, 4) Hunt IOCs in logs.
Refs: see the GHSA / vendor advisory / patched release linked on this page.
Cross-site scripting (XSS) (CWE-79) exists in mermaid. Attackers reach the vulnerable code path via innerHTML.
Check the vendor advisory for the affected versions of mermaid. Attack surface: innerHTML / calculateMathMLDimensions / text.
Severity: ?. Risk of unauthorized operations or information disclosure.
Update to 10.9.4.
Until the patch is applied: disable the affected feature, apply WAF rules, or restrict access via network ACLs.
Search webserver/proxy logs for unusual request patterns matching this CVE's known IOCs. Run grep -r 'mermaid' . against your dependency files (package-lock.json, requirements.txt, go.sum) to find affected services.
Response actions
Concrete steps and command examples for SOC/SRE teams to execute in order
-
1Identify exposure identify
grep -r 'mermaid' . | grep -v node_modulesリポジトリと本番環境の依存ファイル (package-lock.json / requirements.txt / go.sum / Gemfile.lock 等) で
mermaidを grep し、稼働しているサービス・バージョンを把握する。 -
2Apply patch patch
Upgrade mermaid to 10.9.4ステージング環境で 10.9.4 に上げて回帰テスト → 本番反映。回帰テストはアプリの主要ハッピーパスを含めること。
-
3Post-deployment verification verify
Confirm patched version is live in productionパッチ適用後、ステージングで PoC または同等の悪用パターンを再現して脆弱性が閉じたことを確認。本番ではアクセスログ・WAF でアラート再発が無いか継続監視。
Affected packages
Fix status by distribution
Fixed packages published by each distribution for this CVE
- Ubuntu UBUNTU-CVE-2025-54881 node-mermaid
References
- advisory nvd.nist.gov
- package github.com
- web github.com
- web github.com
- web github.com