mirror of
https://github.com/openai/codex.git
synced 2026-09-13 11:47:17 +00:00
Skip WindowsApps package dirs in sandbox read roots
This commit is contained in:
@@ -287,11 +287,26 @@ fn profile_read_roots(user_profile: &Path) -> Vec<PathBuf> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn is_windowsapps_package_path(path: &Path) -> bool {
|
||||
path.to_string_lossy()
|
||||
.to_ascii_lowercase()
|
||||
.contains(r"\program files\windowsapps\")
|
||||
}
|
||||
|
||||
fn helper_source_read_root(current_exe: Option<&Path>) -> Option<PathBuf> {
|
||||
let dir = current_exe?.parent()?;
|
||||
if is_windowsapps_package_path(dir) {
|
||||
None
|
||||
} else {
|
||||
Some(dir.to_path_buf())
|
||||
}
|
||||
}
|
||||
|
||||
fn gather_helper_read_roots(codex_home: &Path) -> Vec<PathBuf> {
|
||||
let mut roots = Vec::new();
|
||||
if let Ok(exe) = std::env::current_exe() {
|
||||
if let Some(dir) = exe.parent() {
|
||||
roots.push(dir.to_path_buf());
|
||||
if let Some(dir) = helper_source_read_root(Some(exe.as_path())) {
|
||||
roots.push(dir);
|
||||
}
|
||||
}
|
||||
let helper_dir = helper_bin_dir(codex_home);
|
||||
@@ -673,6 +688,7 @@ fn filter_sensitive_write_roots(mut roots: Vec<PathBuf>, codex_home: &Path) -> V
|
||||
mod tests {
|
||||
use super::gather_legacy_full_read_roots;
|
||||
use super::gather_read_roots;
|
||||
use super::helper_source_read_root;
|
||||
use super::profile_read_roots;
|
||||
use super::WINDOWS_PLATFORM_DEFAULT_READ_ROOTS;
|
||||
use crate::helper_materialization::helper_bin_dir;
|
||||
@@ -738,6 +754,31 @@ mod tests {
|
||||
assert!(roots.contains(&expected));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn helper_source_read_root_skips_windowsapps_package_dir() {
|
||||
let current_exe = PathBuf::from(
|
||||
r"C:\Program Files\WindowsApps\OpenAI.Codex_26.313.5234.0_x64__2p2nqsd0c76g0\app\codex.exe",
|
||||
);
|
||||
|
||||
let root = helper_source_read_root(Some(current_exe.as_path()));
|
||||
|
||||
assert_eq!(None, root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn helper_source_read_root_keeps_non_windowsapps_dir() {
|
||||
let current_exe = PathBuf::from(r"C:\Users\alice\AppData\Local\Programs\Codex\codex.exe");
|
||||
|
||||
let root = helper_source_read_root(Some(current_exe.as_path()));
|
||||
|
||||
assert_eq!(
|
||||
Some(PathBuf::from(
|
||||
r"C:\Users\alice\AppData\Local\Programs\Codex"
|
||||
)),
|
||||
root
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn restricted_read_roots_skip_platform_defaults_when_disabled() {
|
||||
let tmp = TempDir::new().expect("tempdir");
|
||||
|
||||
Reference in New Issue
Block a user