mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Make filesystem policy matching URI-native (#41001)
## Why Filesystem policies can describe paths using a convention that differs from the host running Codex. Native path comparisons can therefore mis-handle cases such as case-variant Windows paths or ambiguous encoded components. ## What changed - Resolve policy entries and special roots as `PathUri` values using the executor's path convention. - Use validated URI components for containment, overlap, and precedence, and fail closed when component boundaries are ambiguous. - Restrict relative joins to descendants and apply the same matching rules to protected metadata paths and permission-profile intersections. ## Testing Added coverage for Windows case variants, encoded and opaque paths, repeated separators, descendant joins, special roots, metadata protection, and preserved deny entries. GitOrigin-RevId: fb09d44d11df25faaac806fe00457e6f6b0d8596
This commit is contained in:
1 parent
f3741880f6
commit
2926014075
5 files changed
+640
-113
No files matched your search
@@ -343,6 +343,46 @@ fn intersect_permission_profiles_drops_explicit_empty_reads_without_grant() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn intersect_permission_profiles_preserves_parent_relative_project_root_restriction() {
|
||||
let temp_dir = TempDir::new().expect("create temp dir");
|
||||
let root = AbsolutePathBuf::from_absolute_path(temp_dir.path()).expect("absolute temp dir");
|
||||
let cwd = root.join("project");
|
||||
let outside_child = root.join("outside/child");
|
||||
let requested = PermissionProfile {
|
||||
file_system: Some(FileSystemPermissions {
|
||||
entries: vec![
|
||||
FileSystemSandboxEntry::new(
|
||||
FileSystemPath::Special {
|
||||
value: FileSystemSpecialPath::Root,
|
||||
},
|
||||
FileSystemAccessMode::Write,
|
||||
),
|
||||
FileSystemSandboxEntry::new(
|
||||
FileSystemPath::Special {
|
||||
value: FileSystemSpecialPath::project_roots(Some("../outside".to_string())),
|
||||
},
|
||||
FileSystemAccessMode::Read,
|
||||
),
|
||||
],
|
||||
glob_scan_max_depth: None,
|
||||
}),
|
||||
..Default::default()
|
||||
};
|
||||
let granted = PermissionProfile {
|
||||
file_system: Some(FileSystemPermissions::from_read_write_roots(
|
||||
/*read*/ None,
|
||||
Some(vec![outside_child]),
|
||||
)),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
intersect_permission_profiles(requested, granted, cwd.as_path()),
|
||||
PermissionProfile::default()
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
#[test]
|
||||
fn intersect_permission_profiles_rejects_symbolic_slash_tmp_grants() {
|
||||
@@ -378,6 +418,89 @@ fn intersect_permission_profiles_rejects_symbolic_slash_tmp_grants() {
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
#[test]
|
||||
fn intersect_permission_profiles_preserves_deny_across_case_variant_grant() {
|
||||
use FileSystemAccessMode::Deny;
|
||||
use FileSystemAccessMode::Write;
|
||||
|
||||
let requested_root =
|
||||
AbsolutePathBuf::from_absolute_path(r"C:\workspace").expect("absolute requested root");
|
||||
let granted_root =
|
||||
AbsolutePathBuf::from_absolute_path(r"C:\WORKSPACE").expect("absolute granted root");
|
||||
let requested_write = FileSystemSandboxEntry::new(requested_root.clone().into(), Write);
|
||||
let requested_deny = FileSystemSandboxEntry::new(requested_root.join("secret").into(), Deny);
|
||||
let granted_write = FileSystemSandboxEntry::new(granted_root.into(), Write);
|
||||
let profile = |entries| PermissionProfile {
|
||||
file_system: Some(FileSystemPermissions {
|
||||
entries,
|
||||
glob_scan_max_depth: None,
|
||||
}),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
intersect_permission_profiles(
|
||||
profile(vec![requested_write, requested_deny.clone()]),
|
||||
profile(vec![granted_write.clone()]),
|
||||
requested_root.as_path(),
|
||||
),
|
||||
profile(vec![granted_write, requested_deny])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn intersect_permission_profiles_preserves_opaque_child_deny() {
|
||||
use std::ffi::OsString;
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::ffi::OsStringExt;
|
||||
#[cfg(windows)]
|
||||
use std::os::windows::ffi::OsStringExt;
|
||||
|
||||
use FileSystemAccessMode::Deny;
|
||||
use FileSystemAccessMode::Write;
|
||||
|
||||
let temp_dir = TempDir::new().expect("create temp dir");
|
||||
let root = AbsolutePathBuf::from_absolute_path(
|
||||
canonicalize(temp_dir.path()).expect("canonicalize temp dir"),
|
||||
)
|
||||
.expect("absolute temp dir");
|
||||
#[cfg(unix)]
|
||||
let opaque_name = OsString::from_vec(b"private-\xff".to_vec());
|
||||
#[cfg(windows)]
|
||||
let opaque_name = OsString::from_wide(&[
|
||||
u16::from(b'p'),
|
||||
u16::from(b'r'),
|
||||
u16::from(b'i'),
|
||||
u16::from(b'v'),
|
||||
u16::from(b'a'),
|
||||
u16::from(b't'),
|
||||
u16::from(b'e'),
|
||||
u16::from(b'-'),
|
||||
0xD800,
|
||||
]);
|
||||
let deny_path = root.join(opaque_name);
|
||||
let requested_write = FileSystemSandboxEntry::new(root.clone().into(), Write);
|
||||
let requested_deny = FileSystemSandboxEntry::new(deny_path.into(), Deny);
|
||||
let granted_write = FileSystemSandboxEntry::new(root.clone().into(), Write);
|
||||
let profile = |entries| PermissionProfile {
|
||||
file_system: Some(FileSystemPermissions {
|
||||
entries,
|
||||
glob_scan_max_depth: None,
|
||||
}),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
intersect_permission_profiles(
|
||||
profile(vec![requested_write, requested_deny.clone()]),
|
||||
profile(vec![granted_write.clone()]),
|
||||
root.as_path(),
|
||||
),
|
||||
profile(vec![granted_write, requested_deny])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn intersect_permission_profiles_accepts_child_path_granted_for_requested_cwd() {
|
||||
let temp_dir = TempDir::new().expect("create temp dir");
|
||||
|
||||
Reference in new issue
Block a user