Skip to content

Commit 381acb1

Browse files
committed
Allow enforceable Windows split writable roots
1 parent 07490c7 commit 381acb1

1 file changed

Lines changed: 11 additions & 24 deletions

File tree

‎codex-rs/sandboxing/src/windows.rs‎

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -141,21 +141,6 @@ pub fn resolve_windows_restricted_token_filesystem_overrides(
141141
let legacy_writable_roots = legacy_projection.get_writable_roots_with_cwd(sandbox_policy_cwd);
142142
let split_writable_roots =
143143
file_system_sandbox_policy.get_writable_roots_with_cwd(sandbox_policy_cwd);
144-
let legacy_root_paths: BTreeSet<PathBuf> = legacy_writable_roots
145-
.iter()
146-
.map(|root| normalize_windows_override_path(root.root.as_path()))
147-
.collect::<std::result::Result<_, _>>()?;
148-
let split_root_paths: BTreeSet<PathBuf> = split_writable_roots
149-
.iter()
150-
.map(|root| normalize_windows_override_path(root.root.as_path()))
151-
.collect::<std::result::Result<_, _>>()?;
152-
153-
if legacy_root_paths != split_root_paths {
154-
return Err(
155-
"windows unelevated restricted-token sandbox cannot enforce split writable root sets directly; refusing to run unsandboxed"
156-
.to_string(),
157-
);
158-
}
159144

160145
for writable_root in &split_writable_roots {
161146
for read_only_subpath in &writable_root.read_only_subpaths {
@@ -177,22 +162,24 @@ pub fn resolve_windows_restricted_token_filesystem_overrides(
177162
let mut additional_deny_write_paths = BTreeSet::new();
178163
for split_root in &split_writable_roots {
179164
let split_root_path = normalize_windows_override_path(split_root.root.as_path())?;
180-
let Some(legacy_root) = legacy_writable_roots.iter().find(|candidate| {
165+
let legacy_root = legacy_writable_roots.iter().find(|candidate| {
181166
normalize_windows_override_path(candidate.root.as_path())
182167
.is_ok_and(|candidate_path| candidate_path == split_root_path)
183-
}) else {
168+
});
169+
if legacy_root.is_none() && split_root_path.parent().is_none() {
184170
return Err(
185-
"windows unelevated restricted-token sandbox cannot enforce split writable root sets directly; refusing to run unsandboxed"
171+
"windows unelevated restricted-token sandbox cannot enforce filesystem-root writes directly; refusing to run unsandboxed"
186172
.to_string(),
187173
);
188-
};
174+
}
189175

190176
for read_only_subpath in &split_root.read_only_subpaths {
191-
if !legacy_root
192-
.read_only_subpaths
193-
.iter()
194-
.any(|candidate| candidate == read_only_subpath)
195-
{
177+
if legacy_root.is_none_or(|legacy_root| {
178+
!legacy_root
179+
.read_only_subpaths
180+
.iter()
181+
.any(|candidate| candidate == read_only_subpath)
182+
}) {
196183
additional_deny_write_paths.insert(normalize_windows_override_path(
197184
read_only_subpath.as_path(),
198185
)?);

0 commit comments

Comments
 (0)