mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Require approval for input to escalated terminals (#40978)
## What changed - Add the `write_stdin_approval` feature flag, disabled by default, to require a fresh approval before sending non-empty input to an escalated unified-exec terminal. - Route these reviews through hooks, Guardian, app-server, and the TUI as `writeStdin` approvals while keeping the parent command item unchanged. - Preserve the terminal environment, launch directory, and escalation state across turns, and revalidate the process identity after approval before writing input. ## Testing - Cover approval routing, policy decisions, process reuse, terminal identity preservation, app-server events, analytics, and TUI rendering. GitOrigin-RevId: 4ba29eaae6208e934737ba078c96e589c7c2164d
This commit is contained in:
1 parent
21ff2e802c
commit
a57b398351
41 files changed
+861
-169
No files matched your search
@@ -117,6 +117,7 @@ use codex_sandboxing::policy_transforms::intersect_permission_profiles;
|
||||
use codex_shell_command::parse_command::shlex_join;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use codex_utils_path_uri::LegacyAppPathString;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use std::time::SystemTime;
|
||||
@@ -630,26 +631,46 @@ pub(crate) async fn apply_bespoke_event_handling(
|
||||
parsed_cmd,
|
||||
..
|
||||
} = ev;
|
||||
let command_actions = parsed_cmd
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(|parsed| V2ParsedCommand::from_core_with_cwd(parsed, &cwd))
|
||||
.collect::<Vec<_>>();
|
||||
let cwd_uri = match PathUri::try_from(cwd.clone()) {
|
||||
Ok(cwd) => cwd,
|
||||
Err(err) => {
|
||||
error!(%err, "invalid command approval cwd");
|
||||
if let Err(err) = conversation
|
||||
.submit(Op::ExecApproval {
|
||||
id: approval_id.unwrap_or(call_id),
|
||||
turn_id: Some(turn_id),
|
||||
decision: ReviewDecision::denied("invalid command approval cwd"),
|
||||
})
|
||||
.await
|
||||
{
|
||||
error!(%err, "failed to reject invalid command approval");
|
||||
}
|
||||
return;
|
||||
}
|
||||
};
|
||||
let command_presentation =
|
||||
CommandExecutionPresentation::from_raw(&command, &parsed_cmd, &cwd_uri);
|
||||
// Approval requests retain the exact command; only history is redacted.
|
||||
let command_actions = match cwd_uri.to_abs_path() {
|
||||
Ok(native_cwd) => parsed_cmd
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(|parsed| V2ParsedCommand::from_core_with_cwd(parsed, &native_cwd))
|
||||
.collect(),
|
||||
Err(_) => vec![V2ParsedCommand::Unknown {
|
||||
command: shlex_join(&command),
|
||||
}],
|
||||
};
|
||||
let presentation = if let Some(network_approval_context) =
|
||||
network_approval_context.map(V2NetworkApprovalContext::from)
|
||||
{
|
||||
CommandExecutionApprovalPresentation::Network(network_approval_context)
|
||||
} else {
|
||||
let command_presentation = CommandExecutionPresentation::from_raw(
|
||||
&command,
|
||||
&parsed_cmd,
|
||||
&cwd.clone().into(),
|
||||
);
|
||||
let completion_item = CommandExecutionCompletionItem {
|
||||
plugin_id,
|
||||
script_path,
|
||||
command: command_presentation.command,
|
||||
cwd: cwd.clone().into(),
|
||||
cwd: cwd.clone(),
|
||||
command_actions: command_presentation.command_actions,
|
||||
};
|
||||
CommandExecutionApprovalPresentation::Command(completion_item)
|
||||
|
||||
Reference in new issue
Block a user