CVE-2021-43861: Mermaid Cross-Site Scripting Vulnerability

HIGH
Advisory Identifier: GHSA-p3rp-vmj9-gv6v
CVSS 7.2
CWE-20 CWE-79
Published
Advisory Summary

CVE-2021-43861 is a HIGH (CVSS 7.2) cross-site scripting vulnerability (CWE-20: Improper Input Validation) affecting Mermaid libraries in the npm ecosystem. The issue involves incorrect sanitisation function leads to `xss` in mermaid. Remediation is available by upgrading affected packages to version 8.13.8.

CVE-2021-43861 at a Glance

CVE Identifier CVE-2021-43861
GHSA Identifier GHSA-p3rp-vmj9-gv6v
Severity HIGH
CVSS v3.1 Base Score 7.2
CWE Classification CWE-20: Improper Input Validation
Affected Product Mermaid
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 7.2

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required High (PR:H)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2021-43861

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: 8.13.8
npm install mermaid@8.13.8
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-2021-43861, 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 8.13.8), 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-20: Improper Input Validation, where the product receives input or data, but it does not validate or incorrectly validates that the input has the properties that are required to process the data safely and correctly. 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

### Impact Malicious diagrams can contain javascript code that can be run at diagram readers machines. ### Patches The users should upgrade to version 8.13.8 ### Workarounds You need to upgrade in order to avoid this issue.

CVE-2021-43861 Affected Mermaid Versions

1 component(s)
Fixed Versions:
8.13.8
Product / Package Ecosystem Affected Versions Fixed Version
mermaid
npm
< 8.13.8
8.13.8

References

Frequently Asked Questions

What is CVE-2021-43861?
CVE-2021-43861 is a security vulnerability in Mermaid involving Incorrect sanitisation function leads to `XSS` in mermaid under CWE-20: Improper Input Validation.
Which Mermaid versions are affected?
Affected versions include releases prior to 8.13.8 across affected packages: mermaid.
What version fixes CVE-2021-43861?
Upgrading to 8.13.8 (or the latest patched release for your respective branch) resolves the vulnerability.
Is mermaid affected?
Yes, mermaid is affected in releases prior to 8.13.8. Upgrade your dependency to 8.13.8 or later.
What is the CVSS score of CVE-2021-43861?
CVE-2021-43861 has a CVSS v3.1 base score of 7.2 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2021-43861?
CVE-2021-43861 is classified under CWE-20: Improper Input Validation (The product receives input or data, but it does not validate or incorrectly validates that the input has the properties that are required to process the data safely and correctly.).
How can I check npm dependencies for CVE-2021-43861?
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-p3rp-vmj9-gv6v",
  "modified" : "2022-01-06T19:02:22Z",
  "published" : "2022-01-06T19:45:59Z",
  "aliases" : [ "CVE-2021-43861" ],
  "summary" : "Incorrect sanitisation function leads to `XSS` in mermaid",
  "details" : "### Impact\nMalicious diagrams can contain javascript code that can be run at diagram readers machines.\n\n### Patches\nThe users should upgrade to version 8.13.8\n\n### Workarounds\nYou need to upgrade in order to avoid this issue.\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "mermaid"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "8.13.8"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/mermaid-js/mermaid/security/advisories/GHSA-p3rp-vmj9-gv6v"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-43861"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/mermaid-js/mermaid/commit/066b7a0d0bda274d94a2f2d21e4323dab5776d83"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/mermaid-js/mermaid"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/mermaid-js/mermaid/releases/tag/8.13.8"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-20", "CWE-79" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-01-06T19:02:22Z",
    "nvd_published_at" : "2021-12-30T14:15:00Z"
  }
}