mirror of
https://github.com/openai/codex.git
synced 2026-11-10 21:00:47 +00:00
windows: skip WindowsApps read ACL grants
This commit is contained in:
@@ -58,6 +58,7 @@ const WINDOWS_PLATFORM_DEFAULT_READ_ROOTS: &[&str] = &[
|
||||
r"C:\Program Files (x86)",
|
||||
r"C:\ProgramData",
|
||||
];
|
||||
const WINDOWS_APPS_READ_ROOT: &str = "c:/program files/windowsapps";
|
||||
|
||||
pub fn sandbox_dir(codex_home: &Path) -> PathBuf {
|
||||
codex_home.join(".sandbox")
|
||||
@@ -334,6 +335,7 @@ fn gather_helper_read_roots(codex_home: &Path) -> Vec<PathBuf> {
|
||||
let mut roots = Vec::new();
|
||||
if let Ok(exe) = std::env::current_exe()
|
||||
&& let Some(dir) = exe.parent()
|
||||
&& !is_windows_apps_path(dir)
|
||||
{
|
||||
roots.push(dir.to_path_buf());
|
||||
}
|
||||
@@ -343,6 +345,11 @@ fn gather_helper_read_roots(codex_home: &Path) -> Vec<PathBuf> {
|
||||
roots
|
||||
}
|
||||
|
||||
fn is_windows_apps_path(path: &Path) -> bool {
|
||||
let key = canonical_path_key(path);
|
||||
key == WINDOWS_APPS_READ_ROOT || key.starts_with(&format!("{WINDOWS_APPS_READ_ROOT}/"))
|
||||
}
|
||||
|
||||
fn gather_legacy_full_read_roots(
|
||||
command_cwd: &Path,
|
||||
policy: &SandboxPolicy,
|
||||
@@ -804,6 +811,7 @@ mod tests {
|
||||
use super::WINDOWS_PLATFORM_DEFAULT_READ_ROOTS;
|
||||
use super::gather_legacy_full_read_roots;
|
||||
use super::gather_read_roots;
|
||||
use super::is_windows_apps_path;
|
||||
use super::loopback_proxy_port_from_url;
|
||||
use super::offline_proxy_settings_from_env;
|
||||
use super::profile_read_roots;
|
||||
@@ -816,6 +824,7 @@ mod tests {
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use tempfile::TempDir;
|
||||
|
||||
@@ -1009,6 +1018,19 @@ mod tests {
|
||||
assert!(roots.contains(&expected));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn windows_apps_path_detection_matches_store_install_roots() {
|
||||
assert!(is_windows_apps_path(Path::new(
|
||||
r"C:\Program Files\WindowsApps\OpenAI.Codex_26.417.5275.0_x64__2p2nqsd0c76g0\app\resources"
|
||||
)));
|
||||
assert!(is_windows_apps_path(Path::new(
|
||||
"c:/program files/windowsapps/OpenAI.Codex/app/resources"
|
||||
)));
|
||||
assert!(!is_windows_apps_path(Path::new(
|
||||
r"C:\Program Files\OpenAI.Codex\app\resources"
|
||||
)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn restricted_read_roots_skip_platform_defaults_when_disabled() {
|
||||
let tmp = TempDir::new().expect("tempdir");
|
||||
|
||||
Reference in New Issue
Block a user