Vulnerabilities in pkg:npm/mdx-mermaid

PACKAGE
Advisory Identifier: GHSA-rvgm-35jw-q628
Advisory Summary

CVE-2022-36036 is a LOW (CVSS 3.6) improper control of generation of vulnerability (CWE-94: Improper Control of Generation of Code ('Code Injection')) affecting Mdx mermaid libraries in the npm ecosystem. The issue involves improper control of generation of code ('code injection') in mdx-mermaid. Remediation is available by upgrading affected packages to version 1.3.0, 2.0.0-rc2.

1 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:npm/mdx-mermaid

1 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:npm/mdx-mermaid. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-rvgm-35jw-q628 CVE-2022-36036 LOW Improper Control of Generation of Code ('Code Injection') in mdx-mermaid

CVE-2022-36036 at a Glance

CVE Identifier CVE-2022-36036
GHSA Identifier GHSA-rvgm-35jw-q628
Severity LOW
CVSS v3.1 Base Score 3.6
CWE Classification CWE-94: Improper Control of Generation of Code ('Code Injection')
Affected Product Mdx mermaid
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 3.6

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

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

How to Fix CVE-2022-36036

To remediate this vulnerability, upgrade all affected Mdx 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.

mdx-mermaid fixed: 1.3.0
npm install mdx-mermaid@1.3.0
mdx-mermaid fixed: 2.0.0-rc2
npm install mdx-mermaid@2.0.0-rc2
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 mdx-mermaid

How to Check if You Are Affected

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

npm ls mdx-mermaid

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

Note: The npm ls mdx-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-94: Improper Control of Generation of Code ('Code Injection'), where the product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment. In Mdx 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 Arbitary javascript injection Modify any mermaid code blocks with the following code and the code inside will execute when the component is loaded by MDXjs ``` ` + (function () { // Put Javascript code here return '' }()) + ` ``` The block below shows a valid mermaid code block ````md ```mermaid graph TD; A-->B; A-->C; B-->D; C-->D; ``` ```` The same block but with the exploit added ````md ```mermaid ` + (function () { alert('vulnerable') return '' }()) + ` graph TD; A-->B; A-->C; B-->D; C-->D; ``` ```` ### Patches 1.3.0 and 2.0.0-rc2 ### Workarounds None known

CVE-2022-36036 Affected Mdx mermaid Versions

2 component(s)
Fixed Versions:
1.3.02.0.0-rc2
Product / Package Ecosystem Affected Versions Fixed Version
mdx-mermaid
npm
< 1.3.0
1.3.0
mdx-mermaid
npm
≥ 2.0.0-rc1
< 2.0.0-rc2
All 1 versions
2.0.0-rc1
2.0.0-rc2

References

Frequently Asked Questions

What is CVE-2022-36036?
CVE-2022-36036 is a security vulnerability in Mdx mermaid involving Improper Control of Generation of Code ('Code Injection') in mdx-mermaid under CWE-94: Improper Control of Generation of Code ('Code Injection').
Which Mdx mermaid versions are affected?
Affected versions include releases prior to 1.3.0, 2.0.0-rc2 across affected packages: mdx-mermaid.
What version fixes CVE-2022-36036?
Upgrading to 1.3.0, 2.0.0-rc2 (or the latest patched release for your respective branch) resolves the vulnerability.
Is mdx-mermaid affected?
Yes, mdx-mermaid is affected in releases prior to 1.3.0, 2.0.0-rc2. Upgrade your dependency to 1.3.0, 2.0.0-rc2 or later.
What is the CVSS score of CVE-2022-36036?
CVE-2022-36036 has a CVSS v3.1 base score of 3.6 (LOW) with vector string CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:L/I:L/A:N.
What CWE is associated with CVE-2022-36036?
CVE-2022-36036 is classified under CWE-94: Improper Control of Generation of Code ('Code Injection') (The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.).
How can I check npm dependencies for CVE-2022-36036?
Run the dependency tree command: 'npm ls mdx-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-rvgm-35jw-q628",
  "modified" : "2022-09-08T14:12:04Z",
  "published" : "2022-08-31T22:26:11Z",
  "aliases" : [ "CVE-2022-36036" ],
  "summary" : "Improper Control of Generation of Code ('Code Injection') in mdx-mermaid",
  "details" : "### Impact\n\nArbitary javascript injection\n\nModify any mermaid code blocks with the following code and the code inside will execute when the component is loaded by MDXjs\n\n```\n` + (function () {\n  // Put Javascript code here\n  return ''\n}()) + `\n```\n\nThe block below shows a valid mermaid code block\n\n````md\n```mermaid\ngraph TD;\n    A-->B;\n    A-->C;\n    B-->D;\n    C-->D;\n```\n````\n\nThe same block but with the exploit added\n\n````md\n```mermaid\n` + (function () {\n  alert('vulnerable')\n  return ''\n}()) + `\ngraph TD;\n    A-->B;\n    A-->C;\n    B-->D;\n    C-->D;\n```\n````\n\n### Patches\n1.3.0 and 2.0.0-rc2\n\n### Workarounds\nNone known",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:L/I:L/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "mdx-mermaid"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.3.0"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "mdx-mermaid"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.0.0-rc1"
      }, {
        "fixed" : "2.0.0-rc2"
      } ]
    } ],
    "versions" : [ "2.0.0-rc1" ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/sjwall/mdx-mermaid/security/advisories/GHSA-rvgm-35jw-q628"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-36036"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/sjwall/mdx-mermaid/commit/f2b99386660fd13316823529c3f1314ebbcdfd2a"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/sjwall/mdx-mermaid"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-94" ],
    "severity" : "LOW",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-08-31T22:26:11Z",
    "nvd_published_at" : "2022-08-29T18:15:00Z"
  }
}