diff --git a/codex-rs/cli/tests/doctor_path_safety.rs b/codex-rs/cli/tests/doctor_path_safety.rs index ea73fb115e..7447d6cc9a 100644 --- a/codex-rs/cli/tests/doctor_path_safety.rs +++ b/codex-rs/cli/tests/doctor_path_safety.rs @@ -256,7 +256,7 @@ async fn interactive_tmux_startup_does_not_execute_workspace_helpers() -> Result .chars() .filter(|character| !character.is_whitespace()) .collect(); - if text.contains("Doyoutrustthecontentsofthisdirectory?") { + if text.contains("Trustthisfolder?") { return Ok::<_, anyhow::Error>(()); } } diff --git a/codex-rs/tui/src/onboarding/onboarding_screen.rs b/codex-rs/tui/src/onboarding/onboarding_screen.rs index 756e231b50..846d56554e 100644 --- a/codex-rs/tui/src/onboarding/onboarding_screen.rs +++ b/codex-rs/tui/src/onboarding/onboarding_screen.rs @@ -177,6 +177,7 @@ impl OnboardingScreen { } }; steps.push(Step::TrustDirectory(TrustDirectoryWidget { + restricted: false, cwd, trust_target, show_windows_create_sandbox_hint, @@ -650,6 +651,7 @@ async fn persist_selected_trust( .find_map(|(index, step)| { if let Step::TrustDirectory(widget) = step && widget.selection == Some(TrustDirectorySelection::Trust) + && !widget.restricted { return Some((index, widget.trust_target.clone())); } @@ -783,6 +785,7 @@ mod tests { let mut onboarding_screen = OnboardingScreen { request_frame: FrameRequester::test_dummy(), steps: vec![Step::TrustDirectory(TrustDirectoryWidget { + restricted: false, cwd: PathBuf::from("/workspace/project"), trust_target: PathBuf::from("/workspace/project"), show_windows_create_sandbox_hint: false, @@ -841,11 +844,42 @@ mod tests { assert!(onboarding_screen.should_exit()); } + #[tokio::test] + async fn restricted_acceptance_and_cancellation_do_not_persist_trust() { + for key in [KeyCode::Enter, KeyCode::Esc] { + let mut screen = OnboardingScreen { + request_frame: FrameRequester::test_dummy(), + steps: vec![Step::TrustDirectory(TrustDirectoryWidget { + restricted: true, + cwd: PathBuf::from("/workspace/project"), + trust_target: PathBuf::from("/workspace/project"), + show_windows_create_sandbox_hint: false, + should_quit: false, + selection: None, + highlighted: TrustDirectorySelection::Trust, + error: None, + })], + remote_trust_key: Some("/workspace/project".to_string()), + is_done: false, + should_exit: false, + }; + screen.handle_key_event(key.into()); + assert!(!persist_selected_trust(&mut screen, /*request_handle*/ None).await); + assert!(screen.is_done()); + assert_eq!(screen.should_exit(), key == KeyCode::Esc); + let Step::TrustDirectory(widget) = &screen.steps[0] else { + panic!("trust step") + }; + assert_eq!(widget.error, None); + } + } + #[tokio::test] async fn trust_persistence_failure_keeps_trust_step_in_progress() { let mut onboarding_screen = OnboardingScreen { request_frame: FrameRequester::test_dummy(), steps: vec![Step::TrustDirectory(TrustDirectoryWidget { + restricted: false, cwd: PathBuf::from("/workspace/project"), trust_target: PathBuf::from("/workspace/project"), show_windows_create_sandbox_hint: false, diff --git a/codex-rs/tui/src/onboarding/snapshots/codex_tui__onboarding__trust_directory__tests__renders_restricted_folder.snap b/codex-rs/tui/src/onboarding/snapshots/codex_tui__onboarding__trust_directory__tests__renders_restricted_folder.snap new file mode 100644 index 0000000000..23b7e16b77 --- /dev/null +++ b/codex-rs/tui/src/onboarding/snapshots/codex_tui__onboarding__trust_directory__tests__renders_restricted_folder.snap @@ -0,0 +1,16 @@ +--- +source: tui/src/onboarding/trust_directory.rs +assertion_line: 335 +expression: terminal.backend() +--- +> You are in /workspace/project + + This folder is marked untrusted. Project-local config, hooks, and + exec policies stay disabled. Skills still load, and tool execution + follows your permission settings. Opening it will not change its + trust setting. + +› 1. Open restricted + 2. Quit + + Press enter to continue; esc to quit diff --git a/codex-rs/tui/src/onboarding/snapshots/codex_tui__onboarding__trust_directory__tests__renders_snapshot_for_git_repo.snap b/codex-rs/tui/src/onboarding/snapshots/codex_tui__onboarding__trust_directory__tests__renders_snapshot_for_git_repo.snap index 0ffd8d35ca..85ee8bdbfa 100644 --- a/codex-rs/tui/src/onboarding/snapshots/codex_tui__onboarding__trust_directory__tests__renders_snapshot_for_git_repo.snap +++ b/codex-rs/tui/src/onboarding/snapshots/codex_tui__onboarding__trust_directory__tests__renders_snapshot_for_git_repo.snap @@ -1,15 +1,16 @@ --- source: tui/src/onboarding/trust_directory.rs +assertion_line: 295 expression: terminal.backend() --- > You are in /workspace/project - Do you trust the contents of this directory? Working with untrusted - contents comes with higher risk of prompt injection. Trusting the - directory allows project-local config, hooks, and exec policies to - load. + Trust this folder? Codex can read, edit, and run files here, subject + to your permission settings. Folder settings can run code + automatically, even without a model request. Continue only if you + trust these files. Your trust decision will be saved. -› 1. Yes, continue - 2. No, quit +› 1. Trust and continue + 2. Quit - Press enter to continue + Press enter to continue; esc to quit diff --git a/codex-rs/tui/src/onboarding/snapshots/codex_tui__onboarding__trust_directory__tests__renders_snapshot_for_remote_git_subdirectory.snap b/codex-rs/tui/src/onboarding/snapshots/codex_tui__onboarding__trust_directory__tests__renders_snapshot_for_remote_git_subdirectory.snap index 92e68dfb12..1b33cd9e91 100644 --- a/codex-rs/tui/src/onboarding/snapshots/codex_tui__onboarding__trust_directory__tests__renders_snapshot_for_remote_git_subdirectory.snap +++ b/codex-rs/tui/src/onboarding/snapshots/codex_tui__onboarding__trust_directory__tests__renders_snapshot_for_remote_git_subdirectory.snap @@ -1,5 +1,6 @@ --- source: tui/src/onboarding/trust_directory.rs +assertion_line: 314 expression: "terminal.backend().to_string().lines().map(str::trim_end).collect::>().join(\"\\n\")" --- > You are in /srv/remote/project/nested @@ -7,12 +8,12 @@ expression: "terminal.backend().to_string().lines().map(str::trim_end).collect:: Note: You’re in a subdirectory of a Git project. Trusting will apply to the repository root: /srv/remote/project - Do you trust the contents of this directory? Working with untrusted - contents comes with higher risk of prompt injection. Trusting the - directory allows project-local config, hooks, and exec policies to - load. + Trust this folder? Codex can read, edit, and run files here, subject + to your permission settings. Folder settings can run code + automatically, even without a model request. Continue only if you + trust these files. Your trust decision will be saved. -› 1. Yes, continue - 2. No, quit +› 1. Trust and continue + 2. Quit - Press enter to continue + Press enter to continue; esc to quit diff --git a/codex-rs/tui/src/onboarding/snapshots/codex_tui__onboarding__trust_directory__tests__renders_snapshot_for_trust_error.snap b/codex-rs/tui/src/onboarding/snapshots/codex_tui__onboarding__trust_directory__tests__renders_snapshot_for_trust_error.snap index 6f7a495d1a..777fc4b82b 100644 --- a/codex-rs/tui/src/onboarding/snapshots/codex_tui__onboarding__trust_directory__tests__renders_snapshot_for_trust_error.snap +++ b/codex-rs/tui/src/onboarding/snapshots/codex_tui__onboarding__trust_directory__tests__renders_snapshot_for_trust_error.snap @@ -1,19 +1,20 @@ --- source: tui/src/onboarding/trust_directory.rs +assertion_line: 364 expression: terminal.backend() --- > You are in /workspace/project - Do you trust the contents of this directory? Working with untrusted - contents comes with higher risk of prompt injection. Trusting the - directory allows project-local config, hooks, and exec policies to - load. + Trust this folder? Codex can read, edit, and run files here, subject + to your permission settings. Folder settings can run code + automatically, even without a model request. Continue only if you + trust these files. Your trust decision will be saved. -› 1. Yes, continue - 2. No, quit +› 1. Trust and continue + 2. Quit Failed to set trust for /workspace/project: config/batchWrite failed in TUI: Invalid configuration: features.fast_mode=true is not supported; allowed set [fast_mode=false] - Press enter to continue + Press enter to continue; esc to quit diff --git a/codex-rs/tui/src/onboarding/trust_directory.rs b/codex-rs/tui/src/onboarding/trust_directory.rs index 9f9301a005..7a55e6985f 100644 --- a/codex-rs/tui/src/onboarding/trust_directory.rs +++ b/codex-rs/tui/src/onboarding/trust_directory.rs @@ -1,3 +1,5 @@ +//! Folder trust disclosure and protected keyboard selection. + use std::path::PathBuf; use crossterm::event::KeyEvent; @@ -22,6 +24,7 @@ use crate::selection_list::selection_option_row; use super::onboarding_screen::StepState; pub(crate) struct TrustDirectoryWidget { + pub restricted: bool, pub cwd: PathBuf, pub trust_target: PathBuf, pub show_windows_create_sandbox_hint: bool, @@ -48,7 +51,7 @@ impl WidgetRef for &TrustDirectoryWidget { ])); column.push(""); - if self.cwd != self.trust_target { + if !self.restricted && self.cwd != self.trust_target { #[allow(clippy::disallowed_methods)] let git_root_warning = Paragraph::new(format!( "Note: You’re in a subdirectory of a Git project. Trusting will apply to the repository root: {}", @@ -66,12 +69,16 @@ impl WidgetRef for &TrustDirectoryWidget { } column.push( - Paragraph::new( - "Do you trust the contents of this directory? Working with untrusted \ - contents comes with higher risk of prompt injection. Trusting the \ - directory allows project-local config, hooks, and exec policies to load." - .to_string(), - ) + Paragraph::new(if self.restricted { + "This folder is marked untrusted. Project-local config, hooks, and exec \ + policies stay disabled. Skills still load, and tool execution follows \ + your permission settings. Opening it will not change its trust setting." + } else { + "Trust this folder? Codex can read, edit, and run files here, subject to \ + your permission settings. Folder settings can run code automatically, \ + even without a model request. Continue only if you trust these files. \ + Your trust decision will be saved." + }) .wrap(Wrap { trim: true }) .inset(Insets::tlbr( /*top*/ 0, /*left*/ 2, /*bottom*/ 0, /*right*/ 0, @@ -80,8 +87,15 @@ impl WidgetRef for &TrustDirectoryWidget { column.push(""); let options: Vec<(&str, TrustDirectorySelection)> = vec![ - ("Yes, continue", TrustDirectorySelection::Trust), - ("No, quit", TrustDirectorySelection::Quit), + ( + if self.restricted { + "Open restricted" + } else { + "Trust and continue" + }, + TrustDirectorySelection::Trust, + ), + ("Quit", TrustDirectorySelection::Quit), ]; for (idx, (text, selection)) in options.iter().enumerate() { @@ -110,10 +124,10 @@ impl WidgetRef for &TrustDirectoryWidget { Line::from(vec![ "Press ".dim(), keys::CONFIRM[0].into(), - if self.show_windows_create_sandbox_hint { + if self.show_windows_create_sandbox_hint && !self.restricted { " to continue and create a sandbox...".dim() } else { - " to continue".dim() + " to continue; esc to quit".dim() }, ]) .inset(Insets::tlbr( @@ -195,6 +209,7 @@ mod tests { fn widget(error: Option) -> TrustDirectoryWidget { TrustDirectoryWidget { + restricted: false, cwd: PathBuf::from("/workspace/project"), trust_target: PathBuf::from("/workspace/project"), show_windows_create_sandbox_hint: false, @@ -208,6 +223,7 @@ mod tests { #[test] fn release_event_does_not_change_selection() { let mut widget = TrustDirectoryWidget { + restricted: false, cwd: PathBuf::from("."), trust_target: PathBuf::from("."), show_windows_create_sandbox_hint: false, @@ -268,6 +284,7 @@ mod tests { #[test] fn renders_snapshot_for_remote_git_subdirectory() { let widget = TrustDirectoryWidget { + restricted: false, cwd: PathBuf::from("/srv/remote/project/nested"), trust_target: PathBuf::from("/srv/remote/project"), ..widget(/*error*/ None) @@ -290,6 +307,20 @@ mod tests { ); } + #[test] + fn renders_restricted_folder() { + let widget = TrustDirectoryWidget { + restricted: true, + ..widget(/*error*/ None) + }; + let mut terminal = + Terminal::new(VT100Backend::new(/*width*/ 70, /*height*/ 18)).expect("terminal"); + terminal + .draw(|f| (&widget).render_ref(f.area(), f.buffer_mut())) + .expect("draw"); + insta::assert_snapshot!(terminal.backend()); + } + #[test] fn renders_snapshot_for_trust_error() { let widget = widget(Some( @@ -298,7 +329,7 @@ mod tests { )); let mut terminal = - Terminal::new(VT100Backend::new(/*width*/ 70, /*height*/ 18)).expect("terminal"); + Terminal::new(VT100Backend::new(/*width*/ 70, /*height*/ 22)).expect("terminal"); terminal .draw(|f| (&widget).render_ref(f.area(), f.buffer_mut())) .expect("draw");