CVE-2021-34078 (published 2022-06-02T14:15Z)

lifion-verify-dependencies through 1.1.0 is vulnerable to OS command injection via a crafted dependency name on the scanned project's package.json file.

Severity: HIGH
CVSS v2 base score: 9.3 (AV:N/AC:M/Au:N/C:C/I:C/A:C)
CVSS v3 base score: 8.8, HIGH (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/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/lifion/lifion-verify-deps
commit_details: repo_url: https://github.com/lifion/lifion-verify-deps
author: ecksteij
author_date: 2021-02-24 16:00:22-05:00
msg: Add validation for npm module name
repository: repo_url: https://github.com/lifion/lifion-verify-deps
repo_name: lifion/lifion-verify-deps
description: Checks that installed NPM modules are the latest currently available version.
repo_language: JavaScript
owner: lifion
file_changes: filename: index.js
change_type: ModificationType.MODIFY
diff: @@ -9,10 +9,19 @@ const path = require('path');
 const semver = require('semver');
 const { exec } = require('child_process');
 const { promisify } = require('util');
+const validatePackageName = require('validate-npm-package-name');
 
 const execAsync = promisify(exec);
 
+function isValidNpmPackageName(name) {
+  const { errors } = validatePackageName(name);
+  if (errors) {
+    throw new Error(`NPM package name: "${name}" is invalid. ${errors}`);
+  }
+}
+
 async function getLatestVersions(name) {
+  isValidNpmPackageName(name);
   const { stdout } = await execAsync(`npm view ${name} versions --json`);
   try {
     return JSON.parse(stdout);
@@ -22,6 +31,7 @@ async function getLatestVersions(name) {
 }
 
 async function getLatestTag(name) {
+  isValidNpmPackageName(name);
   try {
     const { stdout } = await execAsync(`npm view ${name} dist-tags --json`);
     const { latest } = JSON.parse(stdout);

programming_language: TypeScript
filename: index.test.js
change_type: ModificationType.MODIFY
diff: @@ -345,6 +345,14 @@ describe('lib/index', () => {
     expect(logger.info).toHaveBeenNthCalledWith(6, `Upgraded dependencies:\n["1.0.0"]`);
     expect(logger.info).toHaveBeenNthCalledWith(7, `Upgraded development dependencies:\n["1.0.0"]`);
   });
+
+  test('throw error when npm module name is invalid', async () => {
+    mockExports.dependencies = { 'bad name Dependency': '1.2.3' };
+    mockExecAsync.mockImplementationOnce(mock);
+    await expect(verifyDeps({ autoUpgrade: true, dir, logger })).rejects.toThrow(
+      'NPM package name: "bad name Dependency" is invalid. name can only contain URL-friendly characters'
+    );
+  });
 });
 
 module.exports = mockExports;

programming_language: TypeScript
filename: package-lock.json
change_type: ModificationType.MODIFY
diff: @@ -1565,6 +1565,11 @@
       "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==",
       "dev": true
     },
+    "builtins": {
+      "version": "1.0.3",
+      "resolved": "https://registry.npmjs.org/builtins/-/builtins-1.0.3.tgz",
+      "integrity": "sha1-y5T662HIaWRR2zZTThQi+U8K7og="
+    },
     "cache-base": {
       "version": "1.0.1",
       "resolved": "https://registry.npmjs.org/cache-base/-/cache-base-1.0.1.tgz",
@@ -8779,6 +8784,14 @@
         "spdx-expression-parse": "^3.0.0"
       }
     },
+    "validate-npm-package-name": {
+      "version": "3.0.0",
+      "resolved": "https://registry.npmjs.org/validate-npm-package-name/-/validate-npm-package-name-3.0.0.tgz",
+      "integrity": "sha1-X6kS2B630MdK/BQN5zF/DKffQ34=",
+      "requires": {
+        "builtins": "^1.0.3"
+      }
+    },
     "verror": {
       "version": "1.10.0",
       "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz",

programming_language: JavaScript
filename: package.json
change_type: ModificationType.MODIFY
diff: @@ -48,7 +48,8 @@
   "dependencies": {
     "chalk": "^3.0.0",
     "minimist": "^1.2.5",
-    "semver": "^7.3.4"
+    "semver": "^7.3.4",
+    "validate-npm-package-name": "^3.0.0"
   },
   "devDependencies": {
     "auto-changelog": "^1.16.4",

programming_language: JavaScript