CVE-2021-29369 (published 2021-05-03T12:15Z)

The gnuplot package prior to version 0.1.0 for Node.js allows code execution via shell metacharacters in Gnuplot commands.

Severity: HIGH
CVSS v2 base score: 7.5 (AV:N/AC:L/Au:N/C:P/I:P/A:P)
CVSS v3 base score: 9.8, CRITICAL (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-78
cwe_name: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
description: The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component.
extended_description: 
		   This weakness can lead to a vulnerability in environments in which the attacker does not have direct access to the operating system, such as in web applications. Alternately, if the weakness occurs in a privileged program, it could allow the attacker to specify commands that normally would not be accessible, or to call alternate commands with privileges that the attacker does not have. The problem is exacerbated if the compromised process does not follow the principle of least privilege, because the attacker-controlled commands may run with special system privileges that increases the amount of damage.
            There are at least two subtypes of OS command injection:
               
				 The application intends to execute a single, fixed program that is under its own control. It intends to use externally-supplied inputs as arguments to that program. For example, the program might use system("nslookup [HOSTNAME]") to run nslookup and allow the user to supply a HOSTNAME, which is used as an argument. Attackers cannot prevent nslookup from executing. However, if the program does not remove command separators from the HOSTNAME argument, attackers could place the separators into the arguments, which allows them to execute their own program after nslookup has finished executing.
				 The application accepts an input that it uses to fully select which program to run, as well as which commands to use. The application simply redirects this entire command to the operating system. For example, the program might use "exec([COMMAND])" to execute the [COMMAND] that was supplied by the user. If the COMMAND is under attacker control, then the attacker can execute arbitrary commands or programs. If the command is being executed using functions like exec() and CreateProcess(), the attacker might not be able to combine multiple commands together in the same line.
               
            From a weakness standpoint, these variants represent distinct programmer errors. In the first variant, the programmer clearly intends that input from untrusted parties will be part of the arguments in the command to be executed. In the second variant, the programmer does not intend for the command to be accessible to any untrusted party, but the programmer probably has not accounted for alternate ways in which malicious attackers can provide input.
         
         

Fix information:
repo_url: https://github.com/rkesters/gnuplot
commit_details: repo_url: https://github.com/rkesters/gnuplot
author: Robert Kesterson
author_date: 2021-01-22 15:14:05-05:00
msg: validate filename
repository: repo_url: https://github.com/rkesters/gnuplot
repo_name: rkesters/gnuplot
description: Node gnuplot
repo_language: TypeScript
owner: rkesters
file_changes: filename: package-lock.json
change_type: ModificationType.MODIFY
diff: @@ -406,8 +406,7 @@
     "escape-string-regexp": {
       "version": "1.0.5",
       "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
-      "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
-      "dev": true
+      "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ="
     },
     "esprima": {
       "version": "4.0.1",
@@ -421,6 +420,21 @@
       "integrity": "sha1-wBzKqa5LiXxtDD4hCuUvPHqEQ3U=",
       "dev": true
     },
+    "filename-reserved-regex": {
+      "version": "2.0.0",
+      "resolved": "https://registry.npmjs.org/filename-reserved-regex/-/filename-reserved-regex-2.0.0.tgz",
+      "integrity": "sha1-q/c9+rc10EVECr/qLZHzieu/oik="
+    },
+    "filenamify": {
+      "version": "4.2.0",
+      "resolved": "https://registry.npmjs.org/filenamify/-/filenamify-4.2.0.tgz",
+      "integrity": "sha512-pkgE+4p7N1n7QieOopmn3TqJaefjdWXwEkj2XLZJLKfOgcQKkn11ahvGNgTD8mLggexLiDFQxeTs14xVU22XPA==",
+      "requires": {
+        "filename-reserved-regex": "^2.0.0",
+        "strip-outer": "^1.0.1",
+        "trim-repeated": "^1.0.0"
+      }
+    },
     "fill-range": {
       "version": "7.0.1",
       "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
@@ -986,6 +1000,14 @@
       "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=",
       "dev": true
     },
+    "strip-outer": {
+      "version": "1.0.1",
+      "resolved": "https://registry.npmjs.org/strip-outer/-/strip-outer-1.0.1.tgz",
+      "integrity": "sha512-k55yxKHwaXnpYGsOzg4Vl8+tDrWylxDEpknGjhTiZB8dFRU5rTo9CAzeycivxV3s+zlTKwrs6WxMxR95n26kwg==",
+      "requires": {
+        "escape-string-regexp": "^1.0.2"
+      }
+    },
     "supports-color": {
       "version": "6.0.0",
       "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-6.0.0.tgz",
@@ -1004,6 +1026,14 @@
         "is-number": "^7.0.0"
       }
     },
+    "trim-repeated": {
+      "version": "1.0.0",
+      "resolved": "https://registry.npmjs.org/trim-repeated/-/trim-repeated-1.0.0.tgz",
+      "integrity": "sha1-42RqLqTokTEr9+rObPsFOAvAHCE=",
+      "requires": {
+        "escape-string-regexp": "^1.0.2"
+      }
+    },
     "ts-node": {
       "version": "8.10.2",
       "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-8.10.2.tgz",

programming_language: JavaScript
filename: package.json
change_type: ModificationType.MODIFY
diff: @@ -54,6 +54,7 @@
     "typescript": "^4.0.5"
   },
   "dependencies": {
+    "filenamify": "^4.2.0",
     "lodash": "^4.17.15"
   }
 }

programming_language: JavaScript
filename: index.ts
change_type: ModificationType.MODIFY
diff: @@ -354,11 +354,17 @@ function plotCallack(options: PlotOptions) {
   gnuplot.stdin.end();
 }
 
+import validFilename from "filenamify";
+
 /**
  * Plots data to a PDF file. If it does not exist, the PDF file will
  * be created, otherwise this plot will be appended as a new page.
  */
 export function plot(options: PlotOptions): Promise<boolean> | void {
+  const f = validFilename.path(options.filename);
+  if (f !== options.filename) {
+    throw new Error(`invalid filename of '${options.filename}' -- ${f}`);
+  }
   if (options.finish) {
     return plotCallack(options);
   }

programming_language: TypeScript
filename: test.ts
change_type: ModificationType.MODIFY
diff: @@ -6,6 +6,7 @@ import "mocha";
 
 import { plot } from "./index";
 import { expect as should } from "chai";
+import { fail } from "assert";
 
 function handleResult(
   error: any,
@@ -55,6 +56,22 @@ describe("Plot tests", function () {
   // });
 
   describe("PNG output", function () {
+    it("bad filename ", async () => {
+      let passed = false;
+      try {
+        const ploted = await plot({
+          data: [3, 1, 2, 3, 4],
+          filename: __dirname + "/test/output1.png & frog > frog.txt",
+          format: "png",
+        });
+      } catch (e) {
+        should(e.message).contain("invalid filename of");
+        passed = true;
+      }
+      if (!passed) {
+        fail();
+      }
+    });
     it("Async Output1", async () => {
       const ploted = await plot({
         data: [3, 1, 2, 3, 4],

programming_language: TypeScript