Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

[codex] Reject read-only fallback with approvals disabled (#23774)

viyatb-oaia27d3847b5c3
diff --git a/codex-rs/app-server/tests/suite/v2/turn_start.rs b/codex-rs/app-server/tests/suite/v2/turn_start.rs
index 66f704f83d..236d57a0ee 100644
--- a/codex-rs/app-server/tests/suite/v2/turn_start.rs
+++ b/codex-rs/app-server/tests/suite/v2/turn_start.rs
@@ -1004,10 +1004,14 @@ async fn turn_start_rejects_invalid_permission_selection_before_starting_turn()
assert!(
err.error
.message
- .contains("invalid thread settings override")
+ .contains("`approval_policy = \"never\"` cannot be used"),
+ "unexpected error message: {}",
+ err.error.message
);
assert!(
- err.error.message.contains("allowed set [ReadOnly]"),
+ err.error
+ .message
+ .contains("requirements do not allow `sandbox_mode = \"danger-full-access\"`"),
"unexpected error message: {}",
err.error.message
);
diff --git a/codex-rs/core/src/config/config_tests.rs b/codex-rs/core/src/config/config_tests.rs
index 5fa284ad30..ccde74afe3 100644
--- a/codex-rs/core/src/config/config_tests.rs
+++ b/codex-rs/core/src/config/config_tests.rs
@@ -9906,6 +9906,73 @@ async fn explicit_sandbox_mode_falls_back_when_disallowed_by_requirements() -> s
Ok(())
}
+#[tokio::test]
+async fn danger_full_access_with_never_is_rejected_when_requirements_force_read_only()
+-> std::io::Result<()> {
+ let codex_home = TempDir::new()?;
+ std::fs::write(
+ codex_home.path().join(CONFIG_TOML_FILE),
+ r#"approval_policy = "never"
+sandbox_mode = "danger-full-access"
+"#,
+ )?;
+
+ let err = ConfigBuilder::without_managed_config_for_tests()
+ .codex_home(codex_home.path().to_path_buf())
+ .fallback_cwd(Some(codex_home.path().to_path_buf()))
+ .cloud_requirements(CloudRequirementsLoader::new(async {
+ Ok(Some(codex_config::ConfigRequirementsToml {
+ allowed_sandbox_modes: Some(vec![codex_config::SandboxModeRequirement::ReadOnly]),
+ ..Default::default()
+ }))
+ }))
+ .build()
+ .await
+ .expect_err("requirements-constrained yolo should require sandbox approval");
+
+ assert_eq!(err.kind(), std::io::ErrorKind::InvalidInput);
+ assert_eq!(
+ err.to_string(),
+ "`approval_policy = \"never\"` cannot be used because requirements do not allow `sandbox_mode = \"danger-full-access\"`; Codex would fall back to read-only permissions with approvals disabled. Choose an `approval_policy` based on what you need, such as `on-request`, or choose an allowed sandbox mode."
+ );
+ Ok(())
+}
+
+#[tokio::test]
+async fn named_full_access_profile_with_never_is_rejected_when_requirements_force_read_only()
+-> std::io::Result<()> {
+ let codex_home = TempDir::new()?;
+ std::fs::write(
+ codex_home.path().join(CONFIG_TOML_FILE),
+ r#"approval_policy = "never"
+default_permissions = "dev"
+
+[permissions.dev.filesystem]
+":root" = "write"
+"#,
+ )?;
+
+ let err = ConfigBuilder::without_managed_config_for_tests()
+ .codex_home(codex_home.path().to_path_buf())
+ .fallback_cwd(Some(codex_home.path().to_path_buf()))
+ .cloud_requirements(CloudRequirementsLoader::new(async {
+ Ok(Some(codex_config::ConfigRequirementsToml {
+ allowed_sandbox_modes: Some(vec![codex_config::SandboxModeRequirement::ReadOnly]),
+ ..Default::default()
+ }))
+ }))
+ .build()
+ .await
+ .expect_err("requirements-constrained full-access profile should require sandbox approval");
+
+ assert_eq!(err.kind(), std::io::ErrorKind::InvalidInput);
+ assert_eq!(
+ err.to_string(),
+ "`approval_policy = \"never\"` cannot be used because requirements do not allow `sandbox_mode = \"danger-full-access\"`; Codex would fall back to read-only permissions with approvals disabled. Choose an `approval_policy` based on what you need, such as `on-request`, or choose an allowed sandbox mode."
+ );
+ Ok(())
+}
+
#[tokio::test]
async fn permission_profile_override_falls_back_when_disallowed_by_requirements()
-> std::io::Result<()> {
diff --git a/codex-rs/core/src/config/mod.rs b/codex-rs/core/src/config/mod.rs
index 305ae3b75c..9ff9434fbf 100644
--- a/codex-rs/core/src/config/mod.rs
+++ b/codex-rs/core/src/config/mod.rs
@@ -3334,6 +3334,17 @@ impl Config {
&mut constrained_permission_profile,
&mut startup_warnings,
)?;
+ if permission_profile_was_constrained
+ && sandbox_mode_requirement_for_permission_profile(&original_permission_profile)
+ == SandboxModeRequirement::DangerFullAccess
+ && constrained_permission_profile.get() == &PermissionProfile::read_only()
+ && constrained_approval_policy.value() == AskForApproval::Never
+ {
+ return Err(std::io::Error::new(
+ std::io::ErrorKind::InvalidInput,
+ "`approval_policy = \"never\"` cannot be used because requirements do not allow `sandbox_mode = \"danger-full-access\"`; Codex would fall back to read-only permissions with approvals disabled. Choose an `approval_policy` based on what you need, such as `on-request`, or choose an allowed sandbox mode.",
+ ));
+ }
if permission_profile_was_constrained {
// The selected profile no longer describes the effective
// permissions after requirements forced a fallback.