From 3e671ee6e055cd94473522f1a22d55ab147d1256 Mon Sep 17 00:00:00 2001 From: David Wiesen Date: Sun, 22 Mar 2026 21:50:43 -0700 Subject: [PATCH] Reuse PowerShell parsing for execpolicy matching --- codex-rs/core/src/exec_policy.rs | 7 +++++++ .../src/command_safety/windows_safe_commands.rs | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/codex-rs/core/src/exec_policy.rs b/codex-rs/core/src/exec_policy.rs index 2a2fbacdbe..cf032fd82c 100644 --- a/codex-rs/core/src/exec_policy.rs +++ b/codex-rs/core/src/exec_policy.rs @@ -36,6 +36,7 @@ use crate::config::Config; use crate::powershell::extract_powershell_command; use crate::sandboxing::SandboxPermissions; use crate::tools::sandboxing::ExecApprovalRequirement; +use codex_shell_command::command_safety::windows_safe_commands::parse_powershell_command_sequence; use codex_utils_absolute_path::AbsolutePathBuf; use shlex::split as shlex_split; use shlex::try_join as shlex_try_join; @@ -629,6 +630,12 @@ fn commands_for_exec_policy(command: &[String]) -> (Vec>, bool) { return (commands, false); } + if let Some(commands) = parse_powershell_command_sequence(command) + && !commands.is_empty() + { + return (commands, false); + } + if let Some(single_command) = parse_shell_lc_single_command_prefix(command) { return (vec![single_command], true); } diff --git a/codex-rs/shell-command/src/command_safety/windows_safe_commands.rs b/codex-rs/shell-command/src/command_safety/windows_safe_commands.rs index ac479a4d2c..19711831e1 100644 --- a/codex-rs/shell-command/src/command_safety/windows_safe_commands.rs +++ b/codex-rs/shell-command/src/command_safety/windows_safe_commands.rs @@ -31,6 +31,12 @@ fn try_parse_powershell_command_sequence(command: &[String]) -> Option Option>> { + try_parse_powershell_command_sequence(command) +} + /// Parses a PowerShell invocation into discrete command vectors, rejecting unsafe patterns. fn parse_powershell_invocation(executable: &str, args: &[String]) -> Option>> { if args.is_empty() {