From 94f1a946ae57640ef5a59c8208cac52225ed91fa Mon Sep 17 00:00:00 2001 From: Michael Bolin Date: Mon, 21 Jul 2025 17:08:51 -0700 Subject: [PATCH] fix --- codex-rs/core/src/is_safe_command.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/codex-rs/core/src/is_safe_command.rs b/codex-rs/core/src/is_safe_command.rs index 98c41dbdc2..482c843b2e 100644 --- a/codex-rs/core/src/is_safe_command.rs +++ b/codex-rs/core/src/is_safe_command.rs @@ -23,9 +23,9 @@ fn is_safe_to_call_with_exec(command: &[String]) -> bool { let cmd0 = command.first().map(String::as_str); match cmd0 { - Some( - "cat" | "cd" | "echo" | "grep" | "head" | "ls" | "pwd" | "rg" | "tail" | "wc" | "which", - ) => true, + Some("cat" | "cd" | "echo" | "grep" | "head" | "ls" | "pwd" | "tail" | "wc" | "which") => { + true + } Some("find") => { // Certain options to `find` can delete files, write to files, or @@ -46,6 +46,24 @@ fn is_safe_to_call_with_exec(command: &[String]) -> bool { .any(|arg| UNSAFE_FIND_OPTIONS.contains(&arg.as_str())) } + // Ripgrep + Some("rg") => { + const UNSAFE_RIPGREP_OPTIONS_WITH_ARGS: &[&str] = &[ + // Takes an arbitrary command that is executed for each match. + "--pre", + // Takes a command that can be used to obtain the local hostname. + "--hostname-bin", + ]; + const UNSAFE_RIPGREP_OPTIONS_WITHOUT_ARGS: &[&str] = &["--search-zip", "-z"]; + + !command.iter().any(|arg| { + UNSAFE_RIPGREP_OPTIONS_WITHOUT_ARGS.contains(&arg.as_str()) + || UNSAFE_RIPGREP_OPTIONS_WITH_ARGS + .iter() + .any(|&opt| arg == opt || arg.starts_with(&format!("{opt}="))) + }) + } + // Git Some("git") => matches!( command.get(1).map(String::as_str),