Mermaid: Improper sanitization of configuration leads to CSS injection

説明

Impact

Mermaid's default configuration allows injecting CSS that applies outside of the Mermaid diagram via the fontFamily, themeCSS, and altFontFamily configuration options.

Live demo: mermaid.live

Example code:

%%{init: {"fontFamily": "x;a{b} :not(&){background:green !important} c{d}"}}%%
flowchart LR
    A --> B

The injected CSS exploits stylis's & (scope reference) handling. :not(&) escapes the #mermaid-xxx automatic scoping, applying styles to all page elements. Global at-rules (@font-face, @keyframes, @counter-style) are also injectable as stylis hoists them to top level.

This allows page defacement and DOM attribute exfiltration via CSS :has() selectors.

Patches

Workarounds

If you can't upgrade mermaid, you can set the secure config value in the mermaid config to avoid allowing diagrams to modify fontFamily, themeCSS, altFontFamily, and themeVariables.

Setting "securityLevel": "sandbox" will also prevent this.

Credits

Reported by @zsxsoft on behalf of @KeenSecurityLab

基本情報

タイプ
reviewed
深刻度
medium
GitHub 上のアドバイザリ
アドバイザリを開く ↗
リポジトリのアドバイザリ
リポジトリのアドバイザリを開く ↗
ソースコード
ソースを見る ↗
公開(アドバイザリ)
2026-05-11 19:37:00 UTC
更新
2026-06-09 10:29:19 UTC
GitHub レビュー済み
2026-05-11 19:37:00 UTC
NVD で公開
2026-05-29

EPSS Score

Score Percentile
0.06% 18.17%

CVSS Scores

Base score Version Severity Vector
5.3 4.0
CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:L/VA:N/SC:L/SI:L/SA:L クリックして展開
攻撃ベクター (AV:N)
インターネットや社内 WAN など、ルーティングされたネットワーク越しに遠隔から踏み台にしうる。
攻撃の複雑さ (AC:L)
手順が短く、再現性が高い。
攻撃要件 (AT:N)
到達性以外に、追加のインフラ条件やデータ前提は要らない。
必要な権限 (PR:N)
昇格やログインなしで踏み台にしうる。
ユーザーの関与 (UI:P)
リンクのクリック、インストール承認など、一度の人の判断が要る。
脆弱システムの機密性への影響 (VC:N)
脆弱な対象から機微情報が読まれうる余地はほとんどない。
脆弱システムの完全性への影響 (VI:L)
レコードや設定の一部が歪められうるが、システム全体の信頼は保たれやすい。
脆弱システムの可用性への影響 (VA:N)
業務を止めるほどの停止や劣化は想定しにくい。
後続システムの機密性への影響 (SC:L)
下流の一部資産について限定的な漏えいが起きうる。
後続システムの完全性への影響 (SI:L)
下流の一部コンポーネントで改ざんが起きうるが、全体信頼は保たれやすい。
後続システムの可用性への影響 (SA:L)
下流で遅延や部分停止が起きうるが、運用で緩和しやすい。

Identifiers

CWEs

CWE id Name
CWE-94 Improper Control of Generation of Code ('Code Injection')

Credits

  • zsxsoft (reporter)
  • KeenSecurityLab (sponsor)
  • aloisklink (remediation_developer)

Affected packages (2)

Vulnerable version ranges and first patched releases as published by GitHub.

Ecosystem Package Vulnerable range First patched Vulnerable functions
npm mermaid >= 11.0.0-alpha.1, <= 11.14.0 11.15.0
npm mermaid <= 10.9.5 10.9.6

References

cvelogic Threat Intelligence