Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix(agent-tools): prompt for a cmd command word that contains a caret (#9315) (#9316)
James Dam0817df90d146
diff --git a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/cmdscan.rs b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/cmdscan.rsindex f91472784..df27d8298 100644--- a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/cmdscan.rs+++ b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/cmdscan.rs@@ -915,6 +915,14 @@ fn scan_segment(seg: &str, bases: &mut BTreeSet<String>, kind: ShellKind, depth:if word != "[" && word != "[[" && word.contains(['=', '$', '*', '?', '[']) {return false;}+ // cmd strips `^` before it runs the command word, so `cm^d` runs+ // `cmd` and `se^t PATH=x` is `set`: the escaped text would dodge the+ // checks below and become a grant that covers the real command+ // (#9315). The tokens no longer say whether the caret was quoted+ // (where cmd keeps it), so any caret in the command word prompts.+ if kind == ShellKind::Cmd && word.contains('^') {+ return false;+ }// Windows resolves `SSH` and `ssh.exe` to `ssh`, so the POSIX list is// matched by that name too.if OPAQUE.contains(&base.as_str())@@ -1621,6 +1629,20 @@ mod tests {);}+ /// janhq/jan#9315: the caret also escapes the command word, so `cm^d`+ /// runs `cmd` and must not become a grantable base of its own.+ #[test]+ fn cmd_caret_in_command_word_is_opaque() {+ for command in ["se^t PATH=C:\\evil& git status", "cm^d /c rm x", "r^d /s /q C:\\"] {+ assert_eq!(scan_command_as(command, ShellKind::Cmd), CommandScan::Opaque, "{command}");+ }+ // POSIX shells read `^` literally.+ assert_eq!(+ scan_command_as("cm^d /c rm x", ShellKind::Posix),+ CommandScan::Bases(set(&["cm^d"]))+ );+ }+#[test]fn empty_command_has_no_bases() {assert_eq!(bases(""), set(&[]));