summaryrefslogtreecommitdiffstats
path: root/crates/cli/src/lib.rs
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2021-01-11 13:44:07 -0500
committerAndrew Gallant <jamslam@gmail.com>2021-01-11 14:20:54 -0500
commitaecc0ea126da438924505abe4e8cf9fcdc246e3f (patch)
treea85e3507b5a06d3e61ea31d1a38bb0768f46fbea /crates/cli/src/lib.rs
parenta6d05475fb353c756e88f605fd5366a67943e591 (diff)
cli: fix arbitrary execution of program bugag/fix-cve-2021-3013
This fixes a bug only present on Windows that would permit someoen to execute an arbitrary program if they crafted an appropriate directory tree. Namely, if someone put an executable named 'xz.exe' in the root of a directory tree and one ran 'rg -z foo' from the root of that tree, then the 'xz.exe' executable in that tree would execute if there are any 'xz' files anywhere in the tree. The root cause of this problem is that 'CreateProcess' on Windows will implicitly look in the current working directory for an executable when it is given a relative path to a program. Rust's standard library allows this behavior to occur, so we work around it here. We work around it by explicitly resolving programs like 'xz' via 'PATH'. That way, we only ever pass an absolute path to 'CreateProcess', which avoids the implicit behavior of checking the current working directory. This fix doesn't apply to non-Windows systems as it is believed to only impact Windows. In theory, the bug could apply on Unix if '.' is in one's PATH, but at that point, you reap what you sow. While the extent to which this is a security problem isn't clear, I think users generally expect to be able to download or clone repositories from the Internet and run ripgrep on them without fear of anything too awful happening. Being able to execute an arbitrary program probably violates that expectation. Therefore, CVE-2021-3013[1] was created for this issue. We apply the same logic to the --pre command, since the --pre command is likely in a user's config file and it would be surprising for something that the user is searching to modify which preprocessor command is used. The --pre and -z/--search-zip flags are the only two ways that ripgrep will invoke external programs, so this should cover any possible exploitable cases of this bug. [1] - https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-3013
Diffstat (limited to 'crates/cli/src/lib.rs')
-rw-r--r--crates/cli/src/lib.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs
index 9fe1cf3c..5453ccce 100644
--- a/crates/cli/src/lib.rs
+++ b/crates/cli/src/lib.rs
@@ -179,8 +179,8 @@ mod process;
mod wtr;
pub use decompress::{
- DecompressionMatcher, DecompressionMatcherBuilder, DecompressionReader,
- DecompressionReaderBuilder,
+ resolve_binary, DecompressionMatcher, DecompressionMatcherBuilder,
+ DecompressionReader, DecompressionReaderBuilder,
};
pub use escape::{escape, escape_os, unescape, unescape_os};
pub use human::{parse_human_readable_size, ParseSizeError};