Require fresh approval beneath denied permission paths (#39266)

## Why

A stored permission grant may allow access to a parent while explicitly denying
a child path. A later request for that child must not be treated as already
approved by the broader parent grant.

## What changed

- Compare materialized permission profiles without intersecting away denied or
  reopened paths before deciding that a request is preapproved.
- Execute preapproved commands with the stored grant itself so its denied paths
  remain enforced.
- Fail closed when permission profiles cannot be materialized.

## Testing

Added unit and integration coverage for turn and session grants across
`exec_command`, `shell_command`, and `apply_patch`, including approval-disabled
and `Never` approval modes.

GitOrigin-RevId: 5455880328a89c7958f859c7ce87805dff9704fb
This commit is contained in:
Dylan Hurd authored and copyberry committed 2026-08-18 19:17:09 +00:00
1 parent 846a16852f
commit d68b85a097
5 files changed
+469 -22

No files matched your search

@@ -1,5 +1,6 @@
use super::effective_file_system_sandbox_policy;
use super::intersect_permission_profiles;
use super::materialize_additional_permissions;
use super::merge_file_system_policy_with_additional_permissions;
use super::normalize_additional_permissions;
use super::should_require_platform_sandbox;
@@ -230,6 +231,54 @@ fn normalize_additional_permissions_drops_empty_nested_profiles() {
assert_eq!(permissions, PermissionProfile::default());
}
#[test]
fn materialize_additional_permissions_preserves_authority_and_constraints() {
use FileSystemAccessMode::Deny;
use FileSystemAccessMode::Read;
use FileSystemAccessMode::Write;
let temp_dir = TempDir::new().expect("create temp dir");
let cwd = AbsolutePathBuf::from_absolute_path(
canonicalize(temp_dir.path()).expect("canonicalize temp dir"),
)
.expect("absolute temp dir");
let project_path = |subpath: &str| FileSystemPath::Special {
value: FileSystemSpecialPath::project_roots(Some(subpath.to_owned())),
};
let deny_glob = |pattern: String| {
FileSystemSandboxEntry::new(FileSystemPath::GlobPattern { pattern }, Deny)
};
let profile = |entries| PermissionProfile {
file_system: Some(FileSystemPermissions {
entries,
glob_scan_max_depth: std::num::NonZeroUsize::new(/*n*/ 3),
}),
..Default::default()
};
let reopened = FileSystemSandboxEntry::new(cwd.join("private/reopened").into(), Write);
let requested = profile(vec![
FileSystemSandboxEntry::new(project_path("."), Write),
FileSystemSandboxEntry::new(project_path("private"), Deny),
FileSystemSandboxEntry::skip_missing_path(project_path("readonly"), Read),
FileSystemSandboxEntry::new(project_path("private/reopened"), Write),
reopened.clone(),
deny_glob("**/*.env".to_owned()),
]);
let expected = profile(vec![
FileSystemSandboxEntry::new(cwd.clone().into(), Write),
FileSystemSandboxEntry::new(cwd.join("private").into(), Deny),
FileSystemSandboxEntry::skip_missing_path(cwd.join("readonly").into(), Read),
reopened,
deny_glob(cwd.join("**/*.env").to_string_lossy().into_owned()),
]);
assert_eq!(
materialize_additional_permissions(requested, cwd.as_path())
.expect("materialized permissions"),
expected
);
}
#[test]
fn intersect_permission_profiles_preserves_explicit_empty_requested_reads() {
let temp_dir = TempDir::new().expect("create temp dir");