Skip missing paths in filesystem sandbox entries (#34598)

## Why

Default read-only protections for project metadata should apply when paths such
as `.git`, `.agents`, and `.codex` exist, without causing sandbox setup to
materialize missing paths as ACL targets.

## What changed

- Add an optional `missing_path_behavior` to filesystem sandbox entries and
  mark default project-metadata protections with `skip`.
- Preserve the behavior through permission transforms and exec/MCP protocol
  serialization while keeping existing path wire variants stable.
- Ignore skip-missing entries when projecting configuration or Windows sandbox
  overrides, while retaining explicit metadata carveouts.

## Testing

- Cover protocol round trips for path and special-path entries.
- Verify default metadata protections and Windows explicit carveout handling.

GitOrigin-RevId: 6df13dadacdd131c44aab9f15a967c81051355c1
This commit is contained in:
iceweasel-oai authored and copyberry committed 2026-07-21 19:17:18 +00:00
1 parent ee71c4a90f
commit 87f71e35b8
63 files changed
+825 -132

No files matched your search

@@ -31,6 +31,7 @@ fn full_access_restricted_policy_skips_platform_sandbox_when_network_is_enabled(
value: FileSystemSpecialPath::Root,
},
access: FileSystemAccessMode::Write,
missing_path_behavior: None,
}]);
assert_eq!(
@@ -55,10 +56,12 @@ fn root_write_policy_with_carveouts_still_uses_platform_sandbox() {
value: FileSystemSpecialPath::Root,
},
access: FileSystemAccessMode::Write,
missing_path_behavior: None,
},
FileSystemSandboxEntry {
path: FileSystemPath::Path { path: blocked },
access: FileSystemAccessMode::Deny,
missing_path_behavior: None,
},
]);
@@ -79,6 +82,7 @@ fn full_access_restricted_policy_still_uses_platform_sandbox_for_restricted_netw
value: FileSystemSpecialPath::Root,
},
access: FileSystemAccessMode::Write,
missing_path_behavior: None,
}]);
assert_eq!(
@@ -166,6 +170,7 @@ fn normalize_additional_permissions_rejects_glob_read_grants() {
pattern: "**/*.env".to_string(),
},
access: FileSystemAccessMode::Read,
missing_path_behavior: None,
}],
glob_scan_max_depth: None,
}),
@@ -188,6 +193,7 @@ fn normalize_additional_permissions_preserves_deny_globs() {
pattern: "**/*.env".to_string(),
},
access: FileSystemAccessMode::Deny,
missing_path_behavior: None,
}],
glob_scan_max_depth: std::num::NonZeroUsize::new(2),
}),
@@ -204,6 +210,7 @@ fn normalize_additional_permissions_preserves_deny_globs() {
pattern: "**/*.env".to_string(),
},
access: FileSystemAccessMode::Deny,
missing_path_behavior: None,
}],
glob_scan_max_depth: std::num::NonZeroUsize::new(2),
}),
@@ -302,6 +309,7 @@ fn intersect_permission_profiles_accepts_child_path_granted_for_requested_cwd()
value: FileSystemSpecialPath::project_roots(/*subpath*/ None),
},
access: FileSystemAccessMode::Write,
missing_path_behavior: None,
}],
glob_scan_max_depth: None,
}),
@@ -335,6 +343,7 @@ fn intersect_permission_profiles_materializes_cwd_grant_for_reuse() {
value: FileSystemSpecialPath::project_roots(/*subpath*/ None),
},
access: FileSystemAccessMode::Write,
missing_path_behavior: None,
}],
glob_scan_max_depth: None,
}),
@@ -386,10 +395,12 @@ fn intersect_permission_profiles_deduplicates_materialized_grants() {
value: FileSystemSpecialPath::project_roots(/*subpath*/ None),
},
access: FileSystemAccessMode::Write,
missing_path_behavior: None,
},
FileSystemSandboxEntry {
path: FileSystemPath::Path { path: cwd.clone() },
access: FileSystemAccessMode::Write,
missing_path_behavior: None,
},
],
glob_scan_max_depth: None,
@@ -422,12 +433,14 @@ fn intersect_permission_profiles_materializes_cwd_deny_entries() {
value: FileSystemSpecialPath::Root,
},
access: FileSystemAccessMode::Write,
missing_path_behavior: None,
},
FileSystemSandboxEntry {
path: FileSystemPath::Special {
value: FileSystemSpecialPath::project_roots(/*subpath*/ None),
},
access: FileSystemAccessMode::Deny,
missing_path_behavior: None,
},
],
glob_scan_max_depth: None,
@@ -445,10 +458,12 @@ fn intersect_permission_profiles_materializes_cwd_deny_entries() {
value: FileSystemSpecialPath::Root,
},
access: FileSystemAccessMode::Write,
missing_path_behavior: None,
},
FileSystemSandboxEntry {
path: FileSystemPath::Path { path: request_cwd },
access: FileSystemAccessMode::Deny,
missing_path_behavior: None,
},
],
glob_scan_max_depth: None,
@@ -477,10 +492,12 @@ fn intersect_permission_profiles_drops_deny_entries_without_filesystem_grants()
value: FileSystemSpecialPath::project_roots(/*subpath*/ None),
},
access: FileSystemAccessMode::Write,
missing_path_behavior: None,
},
FileSystemSandboxEntry {
path: FileSystemPath::Path { path: secret },
access: FileSystemAccessMode::Deny,
missing_path_behavior: None,
},
],
glob_scan_max_depth: None,
@@ -515,12 +532,14 @@ fn intersect_permission_profiles_rejects_concrete_grants_matched_by_requested_de
value: FileSystemSpecialPath::project_roots(/*subpath*/ None),
},
access: FileSystemAccessMode::Write,
missing_path_behavior: None,
},
FileSystemSandboxEntry {
path: FileSystemPath::GlobPattern {
pattern: "**/*.env".to_string(),
},
access: FileSystemAccessMode::Deny,
missing_path_behavior: None,
},
],
glob_scan_max_depth: std::num::NonZeroUsize::new(2),
@@ -553,12 +572,14 @@ fn intersect_permission_profiles_materializes_relative_deny_globs_for_reuse() {
value: FileSystemSpecialPath::project_roots(/*subpath*/ None),
},
access: FileSystemAccessMode::Write,
missing_path_behavior: None,
};
let deny_env_files = FileSystemSandboxEntry {
path: FileSystemPath::GlobPattern {
pattern: "**/*.env".to_string(),
},
access: FileSystemAccessMode::Deny,
missing_path_behavior: None,
};
let permissions = PermissionProfile {
file_system: Some(FileSystemPermissions {
@@ -581,12 +602,14 @@ fn intersect_permission_profiles_materializes_relative_deny_globs_for_reuse() {
path: request_cwd.clone(),
},
access: FileSystemAccessMode::Write,
missing_path_behavior: None,
},
FileSystemSandboxEntry {
path: FileSystemPath::GlobPattern {
pattern: request_cwd.join("**/*.env").to_string_lossy().into_owned(),
},
access: FileSystemAccessMode::Deny,
missing_path_behavior: None,
},
],
glob_scan_max_depth: std::num::NonZeroUsize::new(2),
@@ -632,6 +655,7 @@ fn intersect_permission_profiles_drops_broader_cwd_grant_for_requested_child_pat
value: FileSystemSpecialPath::project_roots(/*subpath*/ None),
},
access: FileSystemAccessMode::Write,
missing_path_behavior: None,
}],
glob_scan_max_depth: None,
}),
@@ -652,12 +676,14 @@ fn intersect_permission_profiles_uses_granted_bounded_glob_scan_depth() {
value: FileSystemSpecialPath::Root,
},
access: FileSystemAccessMode::Write,
missing_path_behavior: None,
};
let deny_env_files = FileSystemSandboxEntry {
path: FileSystemPath::GlobPattern {
pattern: "**/*.env".to_string(),
},
access: FileSystemAccessMode::Deny,
missing_path_behavior: None,
};
let requested = PermissionProfile {
file_system: Some(FileSystemPermissions {
@@ -690,6 +716,7 @@ fn intersect_permission_profiles_uses_granted_bounded_glob_scan_depth() {
.into_owned(),
},
access: FileSystemAccessMode::Deny,
missing_path_behavior: None,
},
],
glob_scan_max_depth: std::num::NonZeroUsize::new(4),
@@ -707,12 +734,14 @@ fn intersect_permission_profiles_uses_granted_unbounded_glob_scan_depth() {
value: FileSystemSpecialPath::Root,
},
access: FileSystemAccessMode::Write,
missing_path_behavior: None,
};
let deny_env_files = FileSystemSandboxEntry {
path: FileSystemPath::GlobPattern {
pattern: "**/*.env".to_string(),
},
access: FileSystemAccessMode::Deny,
missing_path_behavior: None,
};
let requested = PermissionProfile {
file_system: Some(FileSystemPermissions {
@@ -745,6 +774,7 @@ fn intersect_permission_profiles_uses_granted_unbounded_glob_scan_depth() {
.into_owned(),
},
access: FileSystemAccessMode::Deny,
missing_path_behavior: None,
},
],
glob_scan_max_depth: None,
@@ -770,12 +800,14 @@ fn merge_file_system_policy_with_additional_permissions_preserves_unreadable_roo
value: FileSystemSpecialPath::Root,
},
access: FileSystemAccessMode::Read,
missing_path_behavior: None,
},
FileSystemSandboxEntry {
path: FileSystemPath::Path {
path: denied_path.clone(),
},
access: FileSystemAccessMode::Deny,
missing_path_behavior: None,
},
]),
&FileSystemPermissions::from_read_write_roots(
@@ -788,6 +820,7 @@ fn merge_file_system_policy_with_additional_permissions_preserves_unreadable_roo
merged_policy.entries.contains(&FileSystemSandboxEntry {
path: FileSystemPath::Path { path: denied_path },
access: FileSystemAccessMode::Deny,
missing_path_behavior: None,
}),
true
);
@@ -795,6 +828,7 @@ fn merge_file_system_policy_with_additional_permissions_preserves_unreadable_roo
merged_policy.entries.contains(&FileSystemSandboxEntry {
path: FileSystemPath::Path { path: allowed_path },
access: FileSystemAccessMode::Read,
missing_path_behavior: None,
}),
true
);
@@ -807,6 +841,7 @@ fn merge_file_system_policy_with_additional_permissions_carries_bounded_glob_sca
pattern: "**/*.env".to_string(),
},
access: FileSystemAccessMode::Deny,
missing_path_behavior: None,
};
let merged_policy = merge_file_system_policy_with_additional_permissions(
&FileSystemSandboxPolicy::restricted(vec![FileSystemSandboxEntry {
@@ -814,6 +849,7 @@ fn merge_file_system_policy_with_additional_permissions_carries_bounded_glob_sca
value: FileSystemSpecialPath::Root,
},
access: FileSystemAccessMode::Write,
missing_path_behavior: None,
}]),
&FileSystemPermissions {
entries: vec![deny_env_files.clone()],
@@ -828,6 +864,7 @@ fn merge_file_system_policy_with_additional_permissions_carries_bounded_glob_sca
value: FileSystemSpecialPath::Root,
},
access: FileSystemAccessMode::Write,
missing_path_behavior: None,
},
deny_env_files,
]);
@@ -850,10 +887,12 @@ fn effective_file_system_sandbox_policy_returns_base_policy_without_additional_p
value: FileSystemSpecialPath::Root,
},
access: FileSystemAccessMode::Read,
missing_path_behavior: None,
},
FileSystemSandboxEntry {
path: FileSystemPath::Path { path: denied_path },
access: FileSystemAccessMode::Deny,
missing_path_behavior: None,
},
]);
@@ -878,12 +917,14 @@ fn effective_file_system_sandbox_policy_merges_additional_write_roots() {
value: FileSystemSpecialPath::Root,
},
access: FileSystemAccessMode::Read,
missing_path_behavior: None,
},
FileSystemSandboxEntry {
path: FileSystemPath::Path {
path: denied_path.clone(),
},
access: FileSystemAccessMode::Deny,
missing_path_behavior: None,
},
]);
let additional_permissions = PermissionProfile {
@@ -901,6 +942,7 @@ fn effective_file_system_sandbox_policy_merges_additional_write_roots() {
effective_policy.entries.contains(&FileSystemSandboxEntry {
path: FileSystemPath::Path { path: denied_path },
access: FileSystemAccessMode::Deny,
missing_path_behavior: None,
}),
true
);
@@ -908,6 +950,7 @@ fn effective_file_system_sandbox_policy_merges_additional_write_roots() {
effective_policy.entries.contains(&FileSystemSandboxEntry {
path: FileSystemPath::Path { path: allowed_path },
access: FileSystemAccessMode::Write,
missing_path_behavior: None,
}),
true
);