CVE-2022-22984: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') (CWE-78)
value: The package snyk before 1.1064.0; the package snyk-mvn-plugin before 2.31.3; the package snyk-gradle-plugin before 3.24.5; the package @snyk/snyk-cocoapods-plugin before 2.5.3; the package snyk-sbt-plugin before 2.16.2; the package snyk-python-plugin before 1.24.2; the package snyk-docker-plugin before 5.6.5; the package @snyk/snyk-hex-plugin before 1.1.6 are vulnerable to Command Injection due to an incomplete fix for [CVE-2022-40764](https://security.snyk.io/vuln/SNYK-JS-SNYK-3037342). A successful exploit allows attackers to run arbitrary commands on the host system where the Snyk CLI is installed by passing in crafted command line flags. In order to exploit this vulnerability, a user would have to execute the snyk test command on untrusted files. In most cases, an attacker positioned to control the command line arguments to the Snyk CLI would already be positioned to execute arbitrary commands. However, this could be abused in specific scenarios, such as continuous integration pipelines, where developers can control the arguments passed to the Snyk CLI to leverage this component as part of a wider attack against an integration/build pipeline. This issue has been addressed in the latest Snyk Docker images available at https://hub.docker.com/r/snyk/snyk as of 2022-11-29. Images downloaded and built prior to that date should be updated. The issue has also been addressed in the Snyk TeamCity CI/CD plugin as of version v20221130.093605.
CWE 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.
CVSS v3 base score: 6.3
Published: 2022-11-30T13:15Z
Repository: https://github.com/snyk/snyk-docker-plugin
Language: TypeScript
Files changed: .snyk, lib/docker.ts, lib/sub-process.ts, package.json
Commit date: 2022-11-29 09:15:59 +0100
Commit message: fix: quote spawn args

Diff: diff --git a/.snyk b/.snyk
index 1d05d8d..4b826da 100644
--- a/.snyk
+++ b/.snyk
@@ -1,4 +1,10 @@
 # Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
-version: v1.7.1
-ignore: {}
+version: v1.25.0
+# ignores vulnerabilities until expiry date; change duration by modifying expiry date
+ignore:
+  'snyk:lic:npm:shescape:MPL-2.0':
+    - '*':
+        reason: None Given
+        expires: 2122-12-29T08:08:41.608Z
+        created: 2022-11-29T08:08:41.611Z
 patch: {}
diff --git a/lib/docker.ts b/lib/docker.ts
index c709c84..fbbaa8a 100644
--- a/lib/docker.ts
+++ b/lib/docker.ts
@@ -53,16 +53,16 @@ class Docker {
 
   public async pullCli(
     targetImage: string,
     options?: DockerOptions,
   ): Promise<subProcess.CmdOutput> {
-    const opts: string[] = ["pull", targetImage];
+    const args: string[] = ["pull", targetImage];
     if (options?.platform) {
-      opts.push(`--platform=${options.platform}`);
+      args.push(`--platform=${options.platform}`);
     }
 
-    return subProcess.execute("docker", opts);
+    return subProcess.execute("docker", args);
   }
 
   public async save(targetImage: string, destination: string) {
     const request = {
       path: `/images/${targetImage}/get?`,
diff --git a/lib/sub-process.ts b/lib/sub-process.ts
index 183b6ac..ff21c5d 100644
--- a/lib/sub-process.ts
+++ b/lib/sub-process.ts
@@ -1,22 +1,24 @@
 import * as childProcess from "child_process";
+import { quoteAll } from "shescape";
 
 export { execute, CmdOutput };
 interface CmdOutput {
   stdout: string;
   stderr: string;
 }
 
 function execute(
   command: string,
-  args?: string[],
+  args: string[],
   options?,
 ): Promise<CmdOutput> {
   const spawnOptions: any = { shell: true };
   if (options && options.cwd) {
     spawnOptions.cwd = options.cwd;
   }
+  args = quoteAll(args, spawnOptions);
 
   return new Promise((resolve, reject) => {
     let stdout = "";
     let stderr = "";
 
diff --git a/package.json b/package.json
index d12b52e..f680ef9 100644
--- a/package.json
+++ b/package.json
@@ -42,10 +42,11 @@
     "elfy": "^1.0.0",
     "event-loop-spinner": "^2.0.0",
     "gunzip-maybe": "^1.4.2",
     "mkdirp": "^1.0.4",
     "semver": "^7.3.4",
+    "shescape": "1.6.1",
     "snyk-nodejs-lockfile-parser": "1.40.0",
     "snyk-poetry-lockfile-parser": "^1.1.7",
     "tar-stream": "^2.1.0",
     "tmp": "^0.2.1",
     "tslib": "^1",

Vulnerable code: version: v1.7.1
ignore: {}
    const opts: string[] = ["pull", targetImage];
      opts.push(`--platform=${options.platform}`);
    return subProcess.execute("docker", opts);
  args?: string[],
Fixed code: version: v1.25.0
# ignores vulnerabilities until expiry date; change duration by modifying expiry date
ignore:
  'snyk:lic:npm:shescape:MPL-2.0':
    - '*':
        reason: None Given
        expires: 2122-12-29T08:08:41.608Z
        created: 2022-11-29T08:08:41.611Z
    const args: string[] = ["pull", targetImage];
      args.push(`--platform=${options.platform}`);
    return subProcess.execute("docker", args);
import { quoteAll } from "shescape";
  args: string[],
  args = quoteAll(args, spawnOptions);
    "shescape": "1.6.1",