From db598e087521570e82edee6eb86edb8af690e94c Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Tue, 7 Jul 2026 08:31:56 -0400 Subject: [PATCH] Protect apply_patch rollout env on remote exec --- .../core/src/unified_exec/process_manager.rs | 21 +++++++++++++---- .../src/unified_exec/process_manager_tests.rs | 23 +++++++++++++++++-- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/codex-rs/core/src/unified_exec/process_manager.rs b/codex-rs/core/src/unified_exec/process_manager.rs index d8c12229e6..db89ccd5de 100644 --- a/codex-rs/core/src/unified_exec/process_manager.rs +++ b/codex-rs/core/src/unified_exec/process_manager.rs @@ -117,9 +117,19 @@ fn exec_env_policy_from_shell_policy( .iter() .map(std::string::ToString::to_string) .collect::>(); - exclude.push(CODEX_PERMISSION_PROFILE_ENV_VAR.to_string()); + exclude.extend([ + CODEX_PERMISSION_PROFILE_ENV_VAR.to_string(), + codex_apply_patch::CODEX_APPLY_PATCH_PRESERVE_LINE_ENDINGS_ENV_VAR.to_string(), + ]); let mut r#set = policy.r#set.clone(); - r#set.retain(|key, _| !key.eq_ignore_ascii_case(CODEX_PERMISSION_PROFILE_ENV_VAR)); + r#set.retain(|key, _| { + ![ + CODEX_PERMISSION_PROFILE_ENV_VAR, + codex_apply_patch::CODEX_APPLY_PATCH_PRESERVE_LINE_ENDINGS_ENV_VAR, + ] + .iter() + .any(|runtime_key| key.eq_ignore_ascii_case(runtime_key)) + }); codex_exec_server::ExecEnvPolicy { inherit: policy.inherit.clone(), ignore_default_excludes: policy.ignore_default_excludes, @@ -140,8 +150,11 @@ fn env_overlay_for_exec_server( request_env .iter() .filter(|(key, value)| { - key.as_str() == CODEX_PERMISSION_PROFILE_ENV_VAR - || local_policy_env.get(*key) != Some(*value) + matches!( + key.as_str(), + CODEX_PERMISSION_PROFILE_ENV_VAR + | codex_apply_patch::CODEX_APPLY_PATCH_PRESERVE_LINE_ENDINGS_ENV_VAR + ) || local_policy_env.get(*key) != Some(*value) }) .map(|(key, value)| (key.clone(), value.clone())) .collect() diff --git a/codex-rs/core/src/unified_exec/process_manager_tests.rs b/codex-rs/core/src/unified_exec/process_manager_tests.rs index 20a930b552..3f3a6b8b4f 100644 --- a/codex-rs/core/src/unified_exec/process_manager_tests.rs +++ b/codex-rs/core/src/unified_exec/process_manager_tests.rs @@ -46,6 +46,10 @@ fn env_overlay_for_exec_server_keeps_runtime_changes_only() { CODEX_PERMISSION_PROFILE_ENV_VAR.to_string(), "current-profile".to_string(), ), + ( + codex_apply_patch::CODEX_APPLY_PATCH_PRESERVE_LINE_ENDINGS_ENV_VAR.to_string(), + "1".to_string(), + ), ]); let request_env = HashMap::from([ ("HOME".to_string(), "/client-home".to_string()), @@ -56,6 +60,10 @@ fn env_overlay_for_exec_server_keeps_runtime_changes_only() { CODEX_PERMISSION_PROFILE_ENV_VAR.to_string(), "current-profile".to_string(), ), + ( + codex_apply_patch::CODEX_APPLY_PATCH_PRESERVE_LINE_ENDINGS_ENV_VAR.to_string(), + "1".to_string(), + ), ( "CODEX_SANDBOX_NETWORK_DISABLED".to_string(), "1".to_string(), @@ -71,6 +79,10 @@ fn env_overlay_for_exec_server_keeps_runtime_changes_only() { CODEX_PERMISSION_PROFILE_ENV_VAR.to_string(), "current-profile".to_string(), ), + ( + codex_apply_patch::CODEX_APPLY_PATCH_PRESERVE_LINE_ENDINGS_ENV_VAR.to_string(), + "1".to_string(), + ), ( "CODEX_SANDBOX_NETWORK_DISABLED".to_string(), "1".to_string() @@ -80,13 +92,17 @@ fn env_overlay_for_exec_server_keeps_runtime_changes_only() { } #[test] -fn exec_env_policy_excludes_runtime_permission_profile() { +fn exec_env_policy_excludes_runtime_apply_patch_and_permission_profile_vars() { let policy = ShellEnvironmentPolicy { r#set: HashMap::from([ ( "codex_permission_profile".to_string(), "stale-profile".to_string(), ), + ( + "codex_apply_patch_preserve_line_endings".to_string(), + "1".to_string(), + ), ("KEEP".to_string(), "value".to_string()), ]), ..Default::default() @@ -97,7 +113,10 @@ fn exec_env_policy_excludes_runtime_permission_profile() { codex_exec_server::ExecEnvPolicy { inherit: policy.inherit, ignore_default_excludes: policy.ignore_default_excludes, - exclude: vec![CODEX_PERMISSION_PROFILE_ENV_VAR.to_string()], + exclude: vec![ + CODEX_PERMISSION_PROFILE_ENV_VAR.to_string(), + codex_apply_patch::CODEX_APPLY_PATCH_PRESERVE_LINE_ENDINGS_ENV_VAR.to_string(), + ], r#set: HashMap::from([("KEEP".to_string(), "value".to_string())]), include_only: Vec::new(), }