mirror of
https://github.com/openai/codex.git
synced 2026-12-02 00:31:03 +00:00
fix(core): preserve managed network during escalation
Co-authored-by: Codex noreply@openai.com
This commit is contained in:
co-authored by
Codex noreply@openai.com
parent
3f40c70cc2
commit
ca9b26ecae
@@ -227,8 +227,11 @@ impl ToolOrchestrator {
|
||||
&file_system_sandbox_policy,
|
||||
);
|
||||
let managed_network_active = turn_ctx.network.is_some();
|
||||
let escalation_profile =
|
||||
escalation_profile_preserving_deny_read(sandbox_override, &turn_ctx.permission_profile);
|
||||
let escalation_profile = escalation_profile_preserving_deny_read(
|
||||
sandbox_override,
|
||||
managed_network_active,
|
||||
&turn_ctx.permission_profile,
|
||||
);
|
||||
let attempt_permissions = escalation_profile
|
||||
.as_ref()
|
||||
.unwrap_or(&turn_ctx.permission_profile);
|
||||
|
||||
@@ -285,6 +285,7 @@ pub(crate) fn sandbox_override_for_first_attempt(
|
||||
/// administrator-defined deny-read restrictions.
|
||||
pub(crate) fn escalation_profile_preserving_deny_read(
|
||||
sandbox_override: SandboxOverride,
|
||||
managed_network_active: bool,
|
||||
permission_profile: &PermissionProfile,
|
||||
) -> Option<PermissionProfile> {
|
||||
if !matches!(
|
||||
@@ -297,11 +298,16 @@ pub(crate) fn escalation_profile_preserving_deny_read(
|
||||
let mut file_system_policy = FileSystemSandboxPolicy::unrestricted();
|
||||
file_system_policy
|
||||
.preserve_deny_read_restrictions_from(&permission_profile.file_system_sandbox_policy());
|
||||
let network_sandbox_policy = if managed_network_active {
|
||||
permission_profile.network_sandbox_policy()
|
||||
} else {
|
||||
NetworkSandboxPolicy::Enabled
|
||||
};
|
||||
Some(
|
||||
PermissionProfile::from_runtime_permissions_with_enforcement(
|
||||
permission_profile.enforcement(),
|
||||
&file_system_policy,
|
||||
NetworkSandboxPolicy::Enabled,
|
||||
network_sandbox_policy,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -208,6 +208,7 @@ fn deny_read_is_preserved_during_explicit_escalation_and_policy_bypass() {
|
||||
);
|
||||
let escalated = escalation_profile_preserving_deny_read(
|
||||
SandboxOverride::EscalatedSandboxWithDenyRead,
|
||||
/*managed_network_active*/ false,
|
||||
&permission_profile,
|
||||
)
|
||||
.expect("escalation profile");
|
||||
@@ -243,10 +244,25 @@ fn deny_read_is_preserved_during_explicit_escalation_and_policy_bypass() {
|
||||
/*has_managed_network_requirements*/ false,
|
||||
));
|
||||
assert_eq!(
|
||||
escalation_profile_preserving_deny_read(SandboxOverride::NoOverride, &permission_profile,),
|
||||
escalation_profile_preserving_deny_read(
|
||||
SandboxOverride::NoOverride,
|
||||
/*managed_network_active*/ false,
|
||||
&permission_profile,
|
||||
),
|
||||
None,
|
||||
"ordinary sandboxed attempts keep their original profile",
|
||||
);
|
||||
let managed_network_escalation = escalation_profile_preserving_deny_read(
|
||||
SandboxOverride::EscalatedSandboxWithDenyRead,
|
||||
/*managed_network_active*/ true,
|
||||
&permission_profile,
|
||||
)
|
||||
.expect("managed network escalation profile");
|
||||
assert_eq!(
|
||||
managed_network_escalation.network_sandbox_policy(),
|
||||
NetworkSandboxPolicy::Restricted,
|
||||
"managed network restrictions must survive escalation",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user