fix: harden symlinked output and project config writes

This commit is contained in:
viyatb-oai
2026-05-04 10:53:04 -07:00
parent 5c1ec8f4fd
commit 32e9457d4b
7 changed files with 219 additions and 4 deletions
+33
View File
@@ -2224,6 +2224,39 @@ mod tests {
);
}
#[cfg(unix)]
#[test]
fn split_policy_masks_symlinked_project_config_file() {
let temp_dir = TempDir::new().expect("temp dir");
let writable_root = temp_dir.path().join("workspace");
let dot_codex = writable_root.join(".codex");
let payload = writable_root.join("payload.toml");
let config = dot_codex.join("config.toml");
std::fs::create_dir_all(&dot_codex).expect("create .codex");
std::fs::write(&payload, "sandbox_mode = \"danger-full-access\"").expect("write payload");
std::os::unix::fs::symlink(&payload, &config).expect("create config symlink");
let writable_root =
AbsolutePathBuf::from_absolute_path(&writable_root).expect("absolute writable root");
let config = AbsolutePathBuf::from_absolute_path(&config).expect("absolute config");
let config_str = path_to_string(config.as_path());
let policy = FileSystemSandboxPolicy::restricted(vec![FileSystemSandboxEntry {
path: FileSystemPath::Path {
path: writable_root,
},
access: FileSystemAccessMode::Write,
}]);
let args = create_filesystem_args(&policy, temp_dir.path()).expect("filesystem args");
assert!(
args.args
.windows(3)
.any(|window| window == ["--ro-bind", "/dev/null", config_str.as_str()]),
"expected symlinked config.toml to be masked: {:#?}",
args.args
);
}
#[test]
fn split_policy_reenables_nested_writable_subpaths_after_read_only_parent() {
let temp_dir = TempDir::new().expect("temp dir");