Vulnerabilities in pkg:npm/madge

PACKAGE
Advisory Identifier: GHSA-753c-phhg-cj29
Advisory Summary

CVE-2021-23352 is a HIGH madge vulnerable to command injection vulnerability (CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')) affecting Madge libraries in the npm ecosystem. The issue involves madge vulnerable to command injection. Remediation is available by upgrading affected packages to version 4.0.1.

1 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:npm/madge

1 Known Advisory Record(s)

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

Advisory ID CVE / NVD Severity Summary
GHSA-753c-phhg-cj29 CVE-2021-23352 HIGH Madge vulnerable to command injection

CVE-2021-23352 at a Glance

CVE Identifier CVE-2021-23352
GHSA Identifier GHSA-753c-phhg-cj29
Severity HIGH
CVSS v3.1 Base Score N/A
CWE Classification CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
Affected Product Madge
Package Ecosystem npm
Published Date
Last Updated

How to Fix CVE-2021-23352

To remediate this vulnerability, upgrade all affected Madge dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

madge fixed: 4.0.1
npm install madge@4.0.1
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 madge

How to Check if You Are Affected

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

npm ls madge

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

Note: The npm ls madge 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-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where the product constructs all or part of an sql command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended sql command when it is sent to a downstream component. without sufficient removal or quoting of sql syntax in user-controllable inputs, the generated sql query can cause those inputs to be interpreted as sql instead of ordinary user data. In Madge, 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

This affects the package madge before 4.0.1. It is possible to specify a custom Graphviz path via the graphVizPath option parameter which, when the .image(), .svg() or .dot() functions are called, is executed by the childprocess.exec function. ### PoC ```js const madge = require('madge'); madge('..', {graphVizPath: "touch HELLO;"}) .then((res) => res.svg()) .then((writtenImagePath) => { console.log('Image written to ' + writtenImagePath); }); ```

CVE-2021-23352 Affected Madge Versions

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

References

Frequently Asked Questions

What is CVE-2021-23352?
CVE-2021-23352 is a security vulnerability in Madge involving Madge vulnerable to command injection under CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
Which Madge versions are affected?
Affected versions include releases prior to 4.0.1 across affected packages: madge.
What version fixes CVE-2021-23352?
Upgrading to 4.0.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is madge affected?
Yes, madge is affected in releases prior to 4.0.1. Upgrade your dependency to 4.0.1 or later.
What CWE is associated with CVE-2021-23352?
CVE-2021-23352 is classified under CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') (The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data.).
How can I check npm dependencies for CVE-2021-23352?
Run the dependency tree command: 'npm ls madge'. 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-753c-phhg-cj29",
  "modified" : "2023-09-06T23:33:10Z",
  "published" : "2021-03-12T23:01:49Z",
  "aliases" : [ "CVE-2021-23352" ],
  "summary" : "Madge vulnerable to command injection",
  "details" : "This affects the package madge before 4.0.1. It is possible to specify a custom Graphviz path via the graphVizPath option parameter which, when the .image(), .svg() or .dot() functions are called, is executed by the childprocess.exec function.\n\n### PoC\n```js\nconst madge = require('madge'); \nmadge('..', {graphVizPath: \"touch HELLO;\"}) .then((res) => res.svg()) .then((writtenImagePath) => { console.log('Image written to ' + writtenImagePath); });\n```",
  "severity" : [ ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "madge"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "4.0.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-23352"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pahen/madge/commit/da5cbc9ab30372d687fa7c324b22af7ffa5c6332"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pahen/madge/blob/master/lib/graph.js#L27"
  }, {
    "type" : "WEB",
    "url" : "https://snyk.io/vuln/SNYK-JS-MADGE-1082875"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-77", "CWE-89" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-03-12T21:10:53Z",
    "nvd_published_at" : "2021-03-09T19:15:00Z"
  }
}