CVE-2022-25865 (published 2022-05-13T20:15Z)

The package workspace-tools before 0.18.4 are vulnerable to Command Injection via git argument injection. When calling the fetchRemoteBranch(remote: string, remoteBranch: string, cwd: string) function, both the remote and remoteBranch parameters are passed to the git fetch subcommand in a way that additional flags can be set. The additional flags can be used to perform a command injection.

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-88
cwe_name: Improper Neutralization of Argument Delimiters in a Command ('Argument Injection')
description: The product constructs a string for a command to be executed by a separate component
in another control sphere, but it does not properly delimit the
intended arguments, options, or switches within that command string.
extended_description: 
            When creating commands using interpolation into a string, developers may assume that only the arguments/options that they specify will be processed.  This assumption may be even stronger when the programmer has encoded the command in a way that prevents separate commands from being provided maliciously, e.g. in the case of shell metacharacters.  When constructing the command, the developer may use whitespace or other delimiters that are required to separate arguments when the command. However, if an attacker can provide an untrusted input that contains argument-separating delimiters, then the resulting command will have more arguments than intended by the developer.  The attacker may then be able to change the behavior of the command.  Depending on the functionality supported by the extraneous arguments, this may have security-relevant consequences.
         
         

Fix information:
repo_url: https://github.com/microsoft/workspace-tools
commit_details: repo_url: https://github.com/microsoft/workspace-tools
author: Kenneth Chau
author_date: 2022-04-20 09:47:57-07:00
msg: Fix git fetch - addresses a potential security concern regarding git fetch (#103)

* fixes a potential security issue where fetch --upload-pack can allow for command injection

* Change files
repository: repo_url: https://github.com/microsoft/workspace-tools
repo_name: microsoft/workspace-tools
description: JS Monorepo Workspace Tools
repo_language: TypeScript
owner: microsoft
file_changes: filename: workspace-tools-01b53966-7f59-4ab9-abd7-ac355a7ae3b1.json
change_type: ModificationType.ADD
diff: @@ -0,0 +1,7 @@
+{
+  "type": "patch",
+  "comment": "fixes a potential security issue where fetch --upload-pack can allow for command injection",
+  "packageName": "workspace-tools",
+  "email": "kchau@microsoft.com",
+  "dependentChangeType": "patch"
+}

programming_language: Markdown
filename: git.ts
change_type: ModificationType.MODIFY
diff: @@ -118,7 +118,7 @@ export function getUntrackedChanges(cwd: string) {
 }
 
 export function fetchRemote(remote: string, cwd: string) {
-  const results = git(["fetch", remote], { cwd });
+  const results = git(["fetch", "--", remote], { cwd });
 
   if (!results.success) {
     throw gitError(`Cannot fetch remote: ${remote}`);
@@ -126,7 +126,7 @@ export function fetchRemote(remote: string, cwd: string) {
 }
 
 export function fetchRemoteBranch(remote: string, remoteBranch: string, cwd: string) {
-  const results = git(["fetch", remote, remoteBranch], { cwd });
+  const results = git(["fetch", "--", remote, remoteBranch], { cwd });
 
   if (!results.success) {
     throw gitError(`Cannot fetch remote: ${remote} ${remoteBranch}`);

programming_language: TypeScript