mirror of
https://github.com/openai/codex.git
synced 2026-09-14 11:57:03 +00:00
Reuse PowerShell parsing for execpolicy matching
This commit is contained in:
@@ -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<Vec<String>>, 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);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,12 @@ fn try_parse_powershell_command_sequence(command: &[String]) -> Option<Vec<Vec<S
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse a PowerShell wrapper into the underlying command sequence when the
|
||||
/// script is simple enough to recover stable argv tokens.
|
||||
pub fn parse_powershell_command_sequence(command: &[String]) -> Option<Vec<Vec<String>>> {
|
||||
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<Vec<Vec<String>>> {
|
||||
if args.is_empty() {
|
||||
|
||||
Reference in New Issue
Block a user