mermaid cross-site scripting in diagram rendering

Severity: info · Published 2020-09-02

Mermaid is a popular JavaScript library used to generate diagrams (flowcharts, sequence diagrams, etc.) from text input, commonly embedded in web applications and documentation. Versions before 8.2.3 fail to properly encode user input, allowing attackers to inject malicious HTML and JavaScript code that executes in the browser. An attacker could exploit this to steal session cookies, redirect users to phishing sites, or perform actions on behalf of legitimate users.

Technologies: mermaid (npm). Vendors: npm.

Quick answers

Is This vulnerability exploited in the wild?
No. Junglewise Threat Intelligence has no report of This vulnerability being exploited in the wild.
How severe is This vulnerability?
Informational severity, published 2 September 2020.
Which products and versions are affected?
mermaid (npm) SEMVER:introduced=0,fixed=8.2.3.
Is there a fix for This vulnerability?
Yes. mermaid (npm): upgrade to 8.2.3 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.
How is This vulnerability attacked?
It is attacked over the network.
Am I affected?
Check whether you run mermaid (npm) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

How to fix

  • mermaid (npm): upgrade to 8.2.3 or later
    npm install mermaid@8.2.3

Technical details

This is a classic Cross-Site Scripting (CWE-79) vulnerability in mermaid's diagram rendering engine. The vulnerability stems from improper output encoding when processing user-supplied diagram text; malicious payloads such as HTML img tags with onerror event handlers are rendered as executable code rather than escaped text. The attack vector is network-based and requires user interaction (the user must input or view a diagram containing the malicious payload). An attacker can execute arbitrary JavaScript in the context of the victim's browser session. The fix is available in version 8.2.3 and later.

Affected products

  • mermaid-js mermaid before 8.2.3

Timeline

  • 2020-09-02: disclosed
  • 2020: patched: fix released in version 8.2.3

References

This page as Markdown. Free to reuse under CC BY 4.0 with a link back.