Protect workspace .agents directory in Windows sandbox (#11970)

The Mac and Linux implementations of the sandbox recently added write
protections for `.codex` and `.agents` subdirectories in all writable
roots. When adding documentation for this, I noticed that this change
was never made for the Windows sandbox.

Summary
- make compute_allow_paths treat .codex/.agents as protected alongside
.git, and cover their behavior in new tests
- wire protect_workspace_agents_dir through the sandbox lib and setup
path to apply deny ACEs when `.agents` exists
- factor shared ACL logic for workspace subdirectories
This commit is contained in:
Eric Traut
2026-02-17 09:40:46 -08:00
committed by GitHub
parent 31906cdb4d
commit 5296e06b61
4 changed files with 85 additions and 11 deletions

View File

@@ -11,9 +11,19 @@ pub fn is_command_cwd_root(root: &Path, canonical_command_cwd: &Path) -> bool {
/// # Safety
/// Caller must ensure `psid` is a valid SID pointer.
pub unsafe fn protect_workspace_codex_dir(cwd: &Path, psid: *mut c_void) -> Result<bool> {
let cwd_codex = cwd.join(".codex");
if cwd_codex.is_dir() {
add_deny_write_ace(&cwd_codex, psid)
protect_workspace_subdir(cwd, psid, ".codex")
}
/// # Safety
/// Caller must ensure `psid` is a valid SID pointer.
pub unsafe fn protect_workspace_agents_dir(cwd: &Path, psid: *mut c_void) -> Result<bool> {
protect_workspace_subdir(cwd, psid, ".agents")
}
unsafe fn protect_workspace_subdir(cwd: &Path, psid: *mut c_void, subdir: &str) -> Result<bool> {
let path = cwd.join(subdir);
if path.is_dir() {
add_deny_write_ace(&path, psid)
} else {
Ok(false)
}