CVE-2021-36753 (published 2021-07-15T20:15Z)

sharkdp BAT before 0.18.2 executes less.exe from the current working directory.

Severity: MEDIUM
CVSS v2 base score: 4.6 (AV:L/AC:L/Au:N/C:P/I:P/A:P)
CVSS v3 base score: 7.8, HIGH (CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-427
cwe_name: Uncontrolled Search Path Element
description: The product uses a fixed or controlled search path to find resources, but one or more locations in that path can be under the control of unintended actors.
extended_description: 
            Although this weakness can occur with any type of resource, it is frequently introduced when a product uses a directory search path to find executables or code libraries, but the path contains a directory that can be modified by an attacker, such as "/tmp" or the current working directory.
            In Windows-based systems, when the LoadLibrary or LoadLibraryEx function is called with a DLL name that does not contain a fully qualified path, the function follows a search order that includes two path elements that might be uncontrolled:
               
                  the directory from which the program has been loaded
                  the current working directory
               
            In some cases, the attack can be conducted remotely, such as when SMB or WebDAV network shares are used.
	    One or more locations in that path could include the Windows drive root or its subdirectories. This often exists in Linux-based code assuming the controlled nature of the root directory (/) or its subdirectories (/etc, etc), or a code that recursively accesses the parent directory.  In Windows, the drive root and some of its subdirectories have weak permissions by default, which makes them uncontrolled.
            In some Unix-based systems, a PATH might be created that contains an empty element, e.g. by splicing an empty variable into the PATH. This empty element can be interpreted as equivalent to the current working directory, which might be an untrusted search element.
            In software package management frameworks (e.g., npm, RubyGems, or PyPi), the framework may identify dependencies on third-party libraries or other packages, then consult a repository that contains the desired package. The framework may search a public repository before a private repository. This could be exploited by attackers by placing a malicious package in the public repository that has the same name as a package from the private repository. The search path might not be directly under control of the developer relying on the framework, but this search order effectively contains an untrusted element.
         
         

Fix information:
repo_url: https://github.com/sharkdp/bat
commit_details: repo_url: https://github.com/sharkdp/bat
author: David Peter
author_date: 2021-07-12 20:03:31+02:00
msg: Fix for Windows: do not run binaries from CWD

This fixes a bug on Windows where `Command::new` would also run
executables from the current working directory, possibly resulting in
accidental runs of programs called `less`.
repository: repo_url: https://github.com/sharkdp/bat
repo_name: sharkdp/bat
description: A cat(1) clone with wings.
repo_language: Rust
owner: sharkdp
file_changes: filename: Cargo.lock
change_type: ModificationType.MODIFY
diff: @@ -1,5 +1,7 @@
 # This file is automatically @generated by Cargo.
 # It is not intended for manual editing.
+version = 3
+
 [[package]]
 name = "adler"
 version = "1.0.2"
@@ -97,6 +99,7 @@ dependencies = [
  "error-chain",
  "git2",
  "globset",
+ "grep-cli",
  "lazy_static",
  "nix",
  "path_abs",
@@ -487,6 +490,23 @@ dependencies = [
  "regex",
 ]
 
+[[package]]
+name = "grep-cli"
+version = "0.1.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2dd110c34bb4460d0de5062413b773e385cbf8a85a63fc535590110a09e79e8a"
+dependencies = [
+ "atty",
+ "bstr",
+ "globset",
+ "lazy_static",
+ "log",
+ "regex",
+ "same-file",
+ "termcolor",
+ "winapi-util",
+]
+
 [[package]]
 name = "hashbrown"
 version = "0.9.1"
@@ -1143,6 +1163,15 @@ dependencies = [
  "winapi",
 ]
 
+[[package]]
+name = "termcolor"
+version = "1.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
+dependencies = [
+ "winapi-util",
+]
+
 [[package]]
 name = "terminal_size"
 version = "0.1.16"

programming_language: CoffeeScript
filename: Cargo.toml
change_type: ModificationType.MODIFY
diff: @@ -51,6 +51,7 @@ path_abs = { version = "0.5", default-features = false }
 clircle = "0.3"
 bugreport = "0.4"
 dirs-next = { version = "2.0.0", optional = true }
+grep-cli = "0.1.6"
 
 [dependencies.git2]
 version = "0.13"

programming_language: Lua
filename: less.rs
change_type: ModificationType.MODIFY
diff: @@ -4,7 +4,9 @@ use std::ffi::OsStr;
 use std::process::Command;
 
 pub fn retrieve_less_version(less_path: &dyn AsRef<OsStr>) -> Option<usize> {
-    let cmd = Command::new(less_path).arg("--version").output().ok()?;
+    let resolved_path = grep_cli::resolve_binary(less_path.as_ref()).ok()?;
+
+    let cmd = Command::new(resolved_path).arg("--version").output().ok()?;
     parse_less_version(&cmd.stdout)
 }
 

programming_language: Rust
filename: output.rs
change_type: ModificationType.MODIFY
diff: @@ -63,7 +63,14 @@ impl OutputType {
             return Err(ErrorKind::InvalidPagerValueBat.into());
         }
 
-        let mut p = Command::new(&pager.bin);
+        let resolved_path = match grep_cli::resolve_binary(&pager.bin) {
+            Ok(path) => path,
+            Err(_) => {
+                return Ok(OutputType::stdout());
+            }
+        };
+
+        let mut p = Command::new(resolved_path);
         let args = pager.args;
 
         if pager.kind == PagerKind::Less {

programming_language: Rust