mirror of
https://github.com/openai/codex.git
synced 2026-10-28 16:06:15 +00:00
Avoid creating metadata paths in the Windows sandbox (#33430)
## Why Elevated Windows sandbox setup could turn the built-in read-only protections for workspace metadata into deny-write paths, creating metadata directories that did not already exist. ## What changed - Track whether filesystem permission entries come from a built-in profile or were explicitly configured. - Exclude generated metadata defaults from direct Windows deny-write overrides while continuing to enforce explicit read-only carveouts for the same paths. - Preserve the distinction while materializing and normalizing permission paths, without exposing generated defaults as user configuration. ## Testing Added Windows coverage confirming that elevated sandbox setup leaves missing workspace metadata absent and still produces overrides for explicit metadata carveouts. GitOrigin-RevId: 701bcb229f631b18ab5ced22f3edf6f303d932f3
This commit is contained in:
@@ -4263,7 +4263,7 @@ exclude_slash_tmp = true
|
||||
file_system_policy
|
||||
.entries
|
||||
.contains(&FileSystemSandboxEntry {
|
||||
path: FileSystemPath::Path {
|
||||
path: FileSystemPath::GeneratedDefaultPath {
|
||||
path: AbsolutePathBuf::resolve_path_against_base(
|
||||
subpath,
|
||||
cwd.path()
|
||||
|
||||
@@ -249,6 +249,8 @@ fn insert_filesystem_permission_toml(
|
||||
FileSystemPath::Special { value } => {
|
||||
insert_special_filesystem_permission_toml(entries, value, entry.access);
|
||||
}
|
||||
FileSystemPath::GeneratedDefaultPath { .. }
|
||||
| FileSystemPath::GeneratedDefaultSpecial { .. } => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -153,13 +153,13 @@ fn render_file_system_entry(rendered: &mut String, entry: &FileSystemSandboxEntr
|
||||
}
|
||||
rendered.push_str("\">");
|
||||
match &entry.path {
|
||||
FileSystemPath::Path { path } => {
|
||||
FileSystemPath::Path { path } | FileSystemPath::GeneratedDefaultPath { path } => {
|
||||
push_text_element(rendered, "path", path.to_string_lossy().as_ref());
|
||||
}
|
||||
FileSystemPath::GlobPattern { pattern } => {
|
||||
push_text_element(rendered, "glob", pattern);
|
||||
}
|
||||
FileSystemPath::Special { value } => {
|
||||
FileSystemPath::Special { value } | FileSystemPath::GeneratedDefaultSpecial { value } => {
|
||||
let value = render_special_path(value);
|
||||
push_text_element(rendered, "special", &value);
|
||||
}
|
||||
|
||||
@@ -797,6 +797,51 @@ fn windows_elevated_supports_split_write_read_carveouts() {
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
#[test]
|
||||
fn windows_workspace_defaults_do_not_hide_explicit_metadata_carveouts() {
|
||||
let temp_dir = tempfile::TempDir::new().expect("tempdir");
|
||||
let cwd = temp_dir.path().canonicalize().expect("canonical cwd").abs();
|
||||
|
||||
let default_profile = PermissionProfile::workspace_write();
|
||||
let default_overrides = resolve_windows_elevated_filesystem_overrides(
|
||||
SandboxType::WindowsRestrictedToken,
|
||||
&default_profile,
|
||||
&cwd,
|
||||
/*use_windows_elevated_backend*/ true,
|
||||
)
|
||||
.expect("resolve workspace defaults");
|
||||
assert!(
|
||||
default_overrides.is_none_or(|overrides| overrides.additional_deny_write_paths.is_empty())
|
||||
);
|
||||
|
||||
for name in codex_protocol::permissions::PROTECTED_METADATA_PATH_NAMES {
|
||||
let (mut explicit_policy, network_policy) = default_profile.to_runtime_permissions();
|
||||
explicit_policy
|
||||
.entries
|
||||
.push(codex_protocol::permissions::FileSystemSandboxEntry {
|
||||
path: codex_protocol::permissions::FileSystemPath::Special {
|
||||
value: codex_protocol::permissions::FileSystemSpecialPath::project_roots(Some(
|
||||
(*name).into(),
|
||||
)),
|
||||
},
|
||||
access: codex_protocol::permissions::FileSystemAccessMode::Read,
|
||||
});
|
||||
let explicit_profile =
|
||||
PermissionProfile::from_runtime_permissions(&explicit_policy, network_policy);
|
||||
|
||||
let overrides = resolve_windows_elevated_filesystem_overrides(
|
||||
SandboxType::WindowsRestrictedToken,
|
||||
&explicit_profile,
|
||||
&cwd,
|
||||
/*use_windows_elevated_backend*/ true,
|
||||
)
|
||||
.expect("resolve explicit metadata carveout")
|
||||
.expect("explicit metadata carveout needs an override");
|
||||
assert_eq!(overrides.additional_deny_write_paths, vec![cwd.join(name)]);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn windows_elevated_supports_unreadable_split_carveouts() {
|
||||
let temp_dir = tempfile::TempDir::new().expect("tempdir");
|
||||
|
||||
Reference in New Issue
Block a user