CVE-2020-15123 (published 2020-07-20T18:15Z)

In codecov (npm package) before version 3.7.1 the upload method has a command injection vulnerability. Clients of the codecov-node library are unlikely to be aware of this, so they might unwittingly write code that contains a vulnerability. A similar CVE (CVE-2020-7597 for GHSA-5q88-cjfq-g2mh) was issued but the fix was incomplete. It only blocked &, and command injection is still possible using backticks instead to bypass the sanitizer. The attack surface is low in this case. Particularly in the standard use of codecov, where the module is used directly in a build pipeline, not built against as a library in another application that may supply malicious input and perform command injection.

Severity: MEDIUM
CVSS v2 base score: 6.8 (AV:N/AC:M/Au:N/C:P/I:P/A:P)
CVSS v3 base score: 9.3, CRITICAL (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:N)

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/codecov/codecov-node
commit_details: repo_url: https://github.com/codecov/codecov-node
author: Joe Becher
author_date: 2020-07-17 12:20:03-04:00
msg: Switch from execSync to execFileSync (#180)

* Switch from execSync to execFileSync

* Call existsSync instead of executing `if`

* Trigger a build

* I think this fixes linux and macos...

* Only add more_patterns of it has a value. Correct windows.

* Remove default value to more_patterns, change windows to winPatterns

* Try a colon.

* Let's try not using MinGw...

* What are the chances that Windows has a find?

* Put it back

* Reverting Windows side so this can me merged in time if needed.

* Reverting Windows side so this can me merged in time if needed.

* Update lib/codecov.js

Co-authored-by: Guillaume St-Pierre <guillaume@codecov.io>

* Update lib/codecov.js

Co-authored-by: Guillaume St-Pierre <guillaume@codecov.io>

* Set initial values

Co-authored-by: Guillaume St-Pierre <guillaume@codecov.io>
repository: repo_url: https://github.com/codecov/codecov-node
repo_name: codecov/codecov-node
description: Global coverage report uploader for Codecov in NodeJS
repo_language: JavaScript
owner: codecov
file_changes: filename: .gitignore
change_type: ModificationType.ADD
diff: @@ -0,0 +1,7 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+
+.idea/
\ No newline at end of file

programming_language: Markdown
filename: README.md
change_type: ModificationType.MODIFY
diff: @@ -116,3 +116,5 @@ If you're seeing an **HTTP 400 error when uploading reports to S3**, make sure y
 - v3.6.3 Fix for AWS Codebuild & package updates
 - v3.6.4 Fix Cirrus CI
 - v3.7.0 Remove the X-Amz-Acl: public-read header
+
+.

programming_language: Markdown
filename: codecov.js
change_type: ModificationType.MODIFY
diff: @@ -4,21 +4,23 @@ var request = require('teeny-request').teenyRequest
 var urlgrey = require('urlgrey')
 var jsYaml = require('js-yaml')
 var walk = require('ignore-walk')
+var execFileSync = require('child_process').execFileSync
 var execSync = require('child_process').execSync
 
 var detectProvider = require('./detect')
 
 var version = 'v' + require('../package.json').version
 
-var patterns,
-  more_patterns = ''
+var patterns = ''
+var more_patterns = ''
+var winPatterns = ''
 
 var isWindows =
   process.platform.match(/win32/) || process.platform.match(/win64/)
 
 if (!isWindows) {
-  patterns =
-    "-type f \\( -name '*coverage.*' " +
+  patterns = (
+    "-type f -name '*coverage.*' " +
     "-or -name 'nosetests.xml' " +
     "-or -name 'jacoco*.xml' " +
     "-or -name 'clover.xml' " +
@@ -29,7 +31,7 @@ if (!isWindows) {
     "-or -name '*.lcov' " +
     "-or -name 'gcov.info' " +
     "-or -name '*.gcov' " +
-    "-or -name '*.lst' \\) " +
+    "-or -name '*.lst' " +
     "-not -name '*.sh' " +
     "-not -name '*.data' " +
     "-not -name '*.py' " +
@@ -76,9 +78,10 @@ if (!isWindows) {
     "-not -path '*/$bower_components/*' " +
     "-not -path '*/node_modules/*' " +
     "-not -path '*/conftest_*.c.gcov'"
+  ).split(' ')
 } else {
-  patterns =
-    '/a-d /b /s *coverage.* ' +
+  winPatterns = (
+    '/a:-d /b /s *coverage.* ' +
     '/s nosetests.xml ' +
     '/s jacoco*.xml ' +
     '/s clover.xml ' +
@@ -136,6 +139,7 @@ if (!isWindows) {
     '| findstr /i /v \\\\$bower_components\\ ' +
     '| findstr /i /v \\node_modules\\ ' +
     '| findstr /i /v \\conftest_.*\\.c\\.gcov '
+  ).split(' ')
 }
 
 var sendToCodecovV2 = function(
@@ -355,7 +359,7 @@ var upload = function(args, on_success, on_failure) {
   console.log('==> Building file structure')
   try {
     upload +=
-      execSync('git ls-files || hg locate', { cwd: root })
+      execFileSync('git', ['ls-files', '||', 'hg', 'locate'], { cwd: root })
         .toString()
         .trim() + '\n<<<<<< network\n'
   } catch (err) {
@@ -414,7 +418,7 @@ var upload = function(args, on_success, on_failure) {
       }
       debug.push(gcov)
       console.log('    $ ' + gcov)
-      execSync(gcov)
+      execFileSync(gcov)
     } catch (e) {
       console.log('    Failed to run gcov command.')
     }
@@ -431,19 +435,23 @@ var upload = function(args, on_success, on_failure) {
       .toString()
       .trim()
   } else {
-    bowerrc = execSync('if exist .bowerrc type .bowerrc', { cwd: root })
-      .toString()
-      .trim()
+    bowerrc = fs.existsSync('.bowerrc')
   }
   if (bowerrc) {
     bowerrc = JSON.parse(bowerrc).directory
     if (bowerrc) {
       if (!isWindows) {
-        more_patterns =
-          " -not -path '*/" + bowerrc.toString().replace(/\/$/, '') + "/*'"
+        more_patterns = (
+          " -not -path '*/" +
+          bowerrc.toString().replace(/\/$/, '') +
+          "/*'"
+        ).split(' ')
       } else {
-        more_patterns =
-          '| findstr /i /v \\' + bowerrc.toString().replace(/\/$/, '') + '\\'
+        more_patterns = (
+          '| findstr /i /v \\' +
+          bowerrc.toString().replace(/\/$/, '') +
+          '\\'
+        ).split(' ')
       }
     }
   }
@@ -474,15 +482,26 @@ var upload = function(args, on_success, on_failure) {
   } else if ((args.options.disable || '').split(',').indexOf('search') === -1) {
     console.log('==> Scanning for reports')
     var _files
+    var _findArgs
     if (!isWindows) {
-      _files = execSync('find ' + root + ' ' + patterns + more_patterns)
+      // @TODO support for a root directory
+      // It's not straightforward due to the nature of the find command
+      _findArgs = [root].concat(patterns)
+      if (more_patterns) {
+        _findArgs.concat(more_patterns)
+      }
+      _files = execFileSync('find', _findArgs)
         .toString()
         .trim()
         .split('\n')
     } else {
       // @TODO support for a root directory
       // It's not straightforward due to the nature of the dir command
-      _files = execSync('dir ' + patterns + more_patterns)
+      _findArgs = [root].concat(winPatterns)
+      if (more_patterns) {
+        _findArgs.concat(more_patterns)
+      }
+      _files = execSync('dir ' + winPatterns.join(' ') + more_patterns)
         .toString()
         .trim()
         .split('\r\n')

programming_language: JavaScript