mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Isolate external editor buffers from sandbox-writable paths (#38830)
## Why External editor buffers can contain the current composer text and should not be placed in directories exposed as writable by a restricted filesystem policy. ## What changed - Create editor buffer files under a protected `editor` directory, trying the configured Codex home, the default Codex home, and a workspace fallback. - Reject candidates that overlap writable roots or resolve through symbolic links, while preserving external editor support for full-disk-write policies. - Surface an editor error when no protected directory is available. ## Testing Add coverage for writable roots, aliases, symbolic links, fallback selection, temporary-directory grants, full-disk-write policies, and editor invocation. GitOrigin-RevId: df1029d81b327678991ab84ffd1077f0e5855631
This commit is contained in:
1 parent
c7a95f84b3
commit
73abda8bfe
5 files changed
+572
-4
No files matched your search
@@ -107,8 +107,19 @@ impl App {
|
||||
};
|
||||
|
||||
let seed = self.chat_widget.composer_text_with_pending();
|
||||
let config = self.chat_widget.config_ref();
|
||||
let file_system_policy = config.permissions.file_system_sandbox_policy();
|
||||
let editor_result = tui
|
||||
.with_restored(|| async { external_editor::run_editor(&seed, &editor_cmd).await })
|
||||
.with_restored(|| async {
|
||||
external_editor::run_editor(
|
||||
&seed,
|
||||
&editor_cmd,
|
||||
config.codex_home.as_path(),
|
||||
&file_system_policy,
|
||||
config.cwd.as_path(),
|
||||
)
|
||||
.await
|
||||
})
|
||||
.await;
|
||||
self.reset_external_editor_state(tui);
|
||||
|
||||
|
||||
@@ -318,6 +318,53 @@ async fn cyber_model_auto_review_notice_snapshot() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial_test::serial]
|
||||
async fn external_editor_writable_directory_rejected_snapshot() -> Result<()> {
|
||||
struct RestoreVisual(Option<std::ffi::OsString>);
|
||||
|
||||
impl Drop for RestoreVisual {
|
||||
fn drop(&mut self) {
|
||||
match self.0.take() {
|
||||
Some(value) => unsafe { std::env::set_var("VISUAL", value) },
|
||||
None => unsafe { std::env::remove_var("VISUAL") },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let (mut app, mut app_event_rx, _op_rx) = make_test_app_with_channels().await;
|
||||
let codex_home = app.chat_widget.config_ref().codex_home.clone();
|
||||
let fallback_home = dirs::home_dir()
|
||||
.expect("home directory")
|
||||
.join(".codex")
|
||||
.abs();
|
||||
let workspace_codex_home = app.chat_widget.config_ref().cwd.join(".codex");
|
||||
let permission_profile = PermissionProfile::workspace_write_with(
|
||||
&[codex_home, fallback_home, workspace_codex_home],
|
||||
codex_protocol::permissions::NetworkSandboxPolicy::Restricted,
|
||||
/*exclude_tmpdir_env_var*/ true,
|
||||
/*exclude_slash_tmp*/ true,
|
||||
);
|
||||
app.chat_widget
|
||||
.set_permission_profile_from_session_snapshot(PermissionProfileSnapshot::legacy(
|
||||
permission_profile,
|
||||
))?;
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
let restore_visual = RestoreVisual(std::env::var_os("VISUAL"));
|
||||
unsafe { std::env::set_var("VISUAL", "editor") };
|
||||
|
||||
app.launch_external_editor(&mut tui).await;
|
||||
drop(restore_visual);
|
||||
|
||||
let cell = match app_event_rx.try_recv() {
|
||||
Ok(AppEvent::InsertHistoryCell(cell)) => cell,
|
||||
other => panic!("expected InsertHistoryCell event, got {other:?}"),
|
||||
};
|
||||
let rendered = lines_to_single_string(&cell.display_lines(/*width*/ 80));
|
||||
assert_app_snapshot!("external_editor_writable_directory_rejected", rendered);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn enqueue_primary_thread_session_replays_buffered_approval_after_attach() -> Result<()> {
|
||||
let (mut app, mut app_event_rx, _op_rx) = make_test_app_with_channels().await;
|
||||
|
||||
Reference in new issue
Block a user