Review terminal input against retained permissions (#41328)

## Why

An existing terminal keeps the sandbox, network settings, and grants it had at launch. Later `write_stdin` calls must account for that retained authority, including when permissions change between turns.

## What changed

- Capture each terminal's effective launch permissions and compare them with the current environment before accepting non-empty input.
- Request approval when the terminal bypassed the sandbox, retains additional grants, strict auto-review is active, or its sandbox or network settings differ from the current policy.
- Reject input when current denied-read or environment-owned network restrictions cannot be enforced by the existing terminal, while keeping empty polls and non-TTY interrupts available without review.
- Include the effective sandbox mode and user-visible additional grants in `write_stdin` approval actions without exposing host-owned grant paths.

## Testing

Added unit and end-to-end coverage for retained cross-turn grants, strict auto-review, sandbox and network policy changes, denied reads, Windows sandbox backends, and private grant redaction.

GitOrigin-RevId: e2d71daf9358474c885998786c4928069100711c
This commit is contained in:
jif authored and copyberry committed 2026-08-28 11:38:03 +00:00
1 parent 31d338a1ea
commit 5eea8d0dd3
17 files changed
+959 -61

No files matched your search

+4 -3
View File
@@ -53,6 +53,7 @@ mod process;
mod process_manager;
mod process_state;
mod shell_snapshot;
mod stdin_approval;
pub(crate) fn set_deterministic_process_ids_for_tests(enabled: bool) {
process_manager::set_deterministic_process_ids_for_tests(enabled);
@@ -64,6 +65,8 @@ pub(crate) use process::NoopSpawnLifecycle;
pub(crate) use process::SpawnLifecycle;
pub(crate) use process::SpawnLifecycleHandle;
pub(crate) use process::UnifiedExecProcess;
pub(crate) use stdin_approval::TerminalPermissions;
pub(crate) use stdin_approval::TerminalSandboxSource;
pub(crate) const MIN_YIELD_TIME_MS: u64 = 250;
pub(crate) const WINDOWS_INITIAL_EXEC_YIELD_TIME_FLOOR_MS: u64 = 10_000;
@@ -185,9 +188,7 @@ struct ProcessEntry {
hook_command: String,
tty: bool,
environment_id: String,
// The successful launch bypassed sandboxing required by its ambient policy.
// Preserve this across turns so subsequent stdin writes can require approval.
escalated: bool,
permissions: TerminalPermissions,
network_approval: Option<DeferredNetworkApproval>,
session: Weak<Session>,
last_used: tokio::time::Instant,