fix(windows): clear stale protected ACLs in full access

This commit is contained in:
David Wiesen
2026-04-23 15:07:17 -07:00
parent 95845cf6ce
commit 89616178a6
4 changed files with 93 additions and 0 deletions
+31
View File
@@ -350,6 +350,13 @@ pub(crate) async fn execute_exec_request(
arg0,
};
#[cfg(target_os = "windows")]
maybe_cleanup_stale_windows_sandbox_denies(
sandbox_policy,
params.windows_sandbox_level,
&params.cwd,
)?;
let start = Instant::now();
let raw_output_result = exec(
params,
@@ -379,6 +386,30 @@ fn extract_create_process_as_user_error_code(err: &str) -> Option<String> {
}
}
#[cfg(target_os = "windows")]
fn maybe_cleanup_stale_windows_sandbox_denies(
sandbox_policy: &SandboxPolicy,
windows_sandbox_level: WindowsSandboxLevel,
cwd: &Path,
) -> Result<()> {
if !matches!(windows_sandbox_level, WindowsSandboxLevel::Elevated)
|| !matches!(
sandbox_policy,
SandboxPolicy::DangerFullAccess | SandboxPolicy::ExternalSandbox { .. }
)
{
return Ok(());
}
let codex_home = crate::config::find_codex_home().map_err(|err| {
CodexErr::Io(io::Error::other(format!(
"windows sandbox: failed to resolve codex_home for ACL cleanup: {err}"
)))
})?;
crate::windows_sandbox::cleanup_stale_protected_write_denies(cwd, codex_home.as_ref())
.map_err(|err| CodexErr::Io(io::Error::other(format!("windows sandbox: {err}"))))
}
#[cfg(target_os = "windows")]
fn windowsapps_path_kind(path: &str) -> &'static str {
let lower = path.to_ascii_lowercase();
+16
View File
@@ -192,6 +192,22 @@ pub fn run_elevated_setup(
)
}
#[cfg(target_os = "windows")]
pub fn cleanup_stale_protected_write_denies(
command_cwd: &Path,
codex_home: &Path,
) -> anyhow::Result<()> {
codex_windows_sandbox::cleanup_stale_protected_write_denies(command_cwd, codex_home)
}
#[cfg(not(target_os = "windows"))]
pub fn cleanup_stale_protected_write_denies(
_command_cwd: &Path,
_codex_home: &Path,
) -> anyhow::Result<()> {
anyhow::bail!("Windows sandbox ACL cleanup is only supported on Windows")
}
#[cfg(not(target_os = "windows"))]
pub fn run_elevated_setup(
_policy: &SandboxPolicy,