mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Apply remote platform semantics to exec safety checks (#42113)
## Why Unified exec can run commands on an OS that differs from the Codex host. Using host path and shell semantics for approval checks can therefore miss dangerous Windows and PowerShell commands sent to a remote executor. ## What changed - Thread the executor platform through command parsing, executable-name normalization, and dangerous-command classification. Legacy executors fall back to the host platform, while unknown reported platforms use Windows rules conservatively. - Bound model-facing `exec_command` rejection messages and avoid echoing the rejected command into the error. - Keep deterministic process IDs reserved after release so rejected test commands cannot reuse an earlier ID. ## Testing - Add coverage that a long dangerous PowerShell command targeting a remote Windows executor is rejected with a bounded response. - Verify deterministic process IDs advance after release. GitOrigin-RevId: a26b4a63ea3d6df7140032b88b3e7aec0b85b948
This commit is contained in:
1 parent
c7c824dce4
commit
1f4c47343a
9 files changed
+259
-113
No files matched your search
@@ -43,6 +43,7 @@ use codex_tools::ToolName;
|
||||
use codex_tools::ToolSpec;
|
||||
use codex_utils_output_truncation::approx_token_count;
|
||||
use codex_utils_path_uri::PathConvention;
|
||||
use codex_utils_string::truncate_middle_chars;
|
||||
|
||||
use super::super::shell_spec::CommandToolOptions;
|
||||
use super::super::shell_spec::create_exec_command_tool_with_environment_id;
|
||||
@@ -52,6 +53,9 @@ use super::get_command;
|
||||
use super::post_unified_exec_tool_use_payload;
|
||||
use super::shell_mode_for_environment;
|
||||
|
||||
// A byte limit is a conservative hard token bound even for byte-fallback tokenizers.
|
||||
const EXEC_COMMAND_REJECTION_MAX_BYTES: usize = 900;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub(crate) struct ExecCommandHandlerOptions {
|
||||
pub(crate) allow_login_shell: bool,
|
||||
@@ -276,8 +280,6 @@ impl ExecCommandHandler {
|
||||
.map_err(FunctionCallError::RespondToModel)?;
|
||||
let command = resolved_command.command;
|
||||
let shell_type = resolved_command.shell_type;
|
||||
let command_for_display = codex_shell_command::parse_command::shlex_join(&command);
|
||||
|
||||
let ExecCommandArgs {
|
||||
mut tty,
|
||||
yield_time_ms,
|
||||
@@ -454,9 +456,13 @@ impl ExecCommandHandler {
|
||||
hook_command: Some(hook_command),
|
||||
}))
|
||||
}
|
||||
Err(err) => Err(FunctionCallError::RespondToModel(format!(
|
||||
"exec_command failed for `{command_for_display}`: {err:?}"
|
||||
))),
|
||||
Err(err) => {
|
||||
let message = format!("exec_command failed: {err:?}");
|
||||
Err(FunctionCallError::RespondToModel(truncate_middle_chars(
|
||||
&message,
|
||||
EXEC_COMMAND_REJECTION_MAX_BYTES,
|
||||
)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user