mirror of
https://github.com/openai/codex.git
synced 2026-05-02 12:21:26 +03:00
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
31 lines
943 B
Rust
31 lines
943 B
Rust
use crate::acl::add_deny_write_ace;
|
|
use crate::path_normalization::canonicalize_path;
|
|
use anyhow::Result;
|
|
use std::ffi::c_void;
|
|
use std::path::Path;
|
|
|
|
pub fn is_command_cwd_root(root: &Path, canonical_command_cwd: &Path) -> bool {
|
|
canonicalize_path(root) == canonical_command_cwd
|
|
}
|
|
|
|
/// # 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> {
|
|
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)
|
|
}
|
|
}
|