CVE-2022-22984 (TypeScript, published 2022-11-30T13:15Z)
Description: 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.
Severity: nan (CVSS v3 base score: 6.3)
Weakness: CWE-78 \u2014 Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
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.
Repository: https://github.com/snyk/snyk-gradle-plugin
Files changed:
.snyk
lib/index.ts
lib/sub-process.ts
package.json
test/functional/gradle-plugin.spec.ts
Commit message: fix: escape child process arguments


Vulnerable code:
const isWin = /^win/.test(os.platform());
const quot = isWin ? '"' : "'";

export function formatArgWithWhiteSpace(arg: string): string {
  if (/\s/.test(arg)) {
    return quot + arg + quot;
  }
  return arg;
}

    if (!fs.existsSync(path.resolve(root, targetFile))) {
      throw new Error('File not found: "' + targetFile + '"');
    const formattedTargetFile = formatArgWithWhiteSpace(targetFile);
    args.push(formattedTargetFile);
    args.push(
      `-Pconfiguration=${quot}${options['configuration-matching']}${quot}`,
    );
    args.push(
      `-PconfAttr=${quot}${options['configuration-attributes']}${quot}`,
    );
    const formattedInitScript = formatArgWithWhiteSpace(
      path.resolve(options.initScript),
    );
  args.push('-I ' + initGradlePath);
      `-Pconfiguration=${quot}^$1$$${quot}`,
      args[i] = `-Pconfiguration=${quot}^${args[i + 1]}$${quot}`;
  return args;
import * as os from 'os';

const isWin = /^win/.test(os.platform());
const quot = isWin ? '"' : "'";
      '-I /tmp/init.gradle',
      `-Pconfiguration=${quot}confRegex${quot}`,
      '-I /tmp/init.gradle',
      `-Pconfiguration=${quot}confRegex${quot}`,
      '-I /tmp/init.gradle',
      '-I /tmp/init.gradle',
      `-Pconfiguration=${quot}^compile$${quot}`,
        '-I /tmp/init.gradle',
        `-Pconfiguration=${quot}^compile$${quot}`,
        '', // this is a harmless artifact of argument transformation

Fixed code:
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
version: v1.25.0
# ignores vulnerabilities until expiry date; change duration by modifying expiry date
ignore:
  'snyk:lic:npm:shescape:MPL-2.0':
    - '*':
        reason: Snyk CLI handles MPL-2.0 by appending dependency to snyk --about
        expires: 2122-12-14T13:33:15.042Z
        created: 2022-11-14T13:33:15.045Z
patch: {}
    (options as api.SingleSubprojectInspectOptions).subProject = subProject;
    const resolvedTargetFilePath = path.resolve(root, targetFile);
    if (!fs.existsSync(resolvedTargetFilePath)) {
      throw new Error('File not found: "' + resolvedTargetFilePath + '"');
    args.push(resolvedTargetFilePath);
    args.push(`-Pconfiguration=${options['configuration-matching']}`);
    args.push(`-PconfAttr=${options['configuration-attributes']}`);
    const formattedInitScript = path.resolve(options.initScript);
  args.push('-I', initGradlePath);
      `-Pconfiguration=^$1$$`,
      args[i] = `-Pconfiguration=^${args[i + 1]}$`;
  return args.filter(Boolean);
import { quoteAll } from 'shescape';
  args = quoteAll(args, spawnOptions);
    "shescape": "1.6.1",
      '-I',
      '/tmp/init.gradle',
      `-Pconfiguration=confRegex`,
      '-I',
      '/tmp/init.gradle',
      `-Pconfiguration=confRegex`,
      '-I',
      '/tmp/init.gradle',
      '-I',
      '/tmp/init.gradle',
      `-Pconfiguration=^compile$`,
        '-I',
        '/tmp/init.gradle',
        `-Pconfiguration=^compile$`,