Respect sandbox read restrictions in remote plugin approvals (#64369)

## Why

Remote command approvals could attribute a command to a plugin by reading
a script that the turn's filesystem permissions denied access to.

## What changed

Use the remote environment's sandbox policy and stored permission grants
when resolving script paths, checking file metadata, and reading scripts
for approval attribution. If the lookup is denied, the approval prompt
still appears without plugin attribution.

## Testing

Add a regression test that checks for an approval prompt without a plugin
ID or script path when either the environment policy or a stored turn
grant denies reads of an otherwise matching plugin script.

GitOrigin-RevId: 123fd72c14cd31121d271fa800f005d3fc41a366
This commit is contained in:
jif
2026-11-27 19:09:58 +00:00
committed by copyberry
parent 005a57e890
commit 045a11fe2c
6 changed files with 183 additions and 32 deletions
+17 -15
View File
@@ -18,6 +18,7 @@ use crate::store::PluginStore;
use crate::store::plugin_version_for_source;
use crate::store::validate_plugin_version_segment;
use codex_exec_server::ExecutorFileSystem;
use codex_exec_server::FileSystemSandboxContext;
use codex_exec_server::GetMetadataOptions;
use codex_exec_server::ReadFileOptions;
use codex_plugin::PluginId;
@@ -337,8 +338,9 @@ impl TrustedPluginRoots {
command: &[String],
cwd: &PathUri,
file_system: &dyn ExecutorFileSystem,
sandbox: Option<&FileSystemSandboxContext>,
) -> Option<PluginCommandAttribution> {
self.executor_candidate(command, cwd, file_system, PluginVersionMatch::Any)
self.executor_candidate(command, cwd, file_system, sandbox, PluginVersionMatch::Any)
.await
.map(|candidate| candidate.matched.attribution())
}
@@ -351,10 +353,16 @@ impl TrustedPluginRoots {
cwd: &PathUri,
file_system: &dyn ExecutorFileSystem,
) -> Option<ResolvedPluginMetricsOperation> {
self.executor_candidate(command, cwd, file_system, PluginVersionMatch::Exact)
.await?
.matched
.metrics_operation()
self.executor_candidate(
command,
cwd,
file_system,
/*sandbox*/ None,
PluginVersionMatch::Exact,
)
.await?
.matched
.metrics_operation()
}
async fn executor_candidate(
@@ -362,6 +370,7 @@ impl TrustedPluginRoots {
command: &[String],
cwd: &PathUri,
file_system: &dyn ExecutorFileSystem,
sandbox: Option<&FileSystemSandboxContext>,
version_match: PluginVersionMatch,
) -> Option<ExecutorAttributionCandidate<'_>> {
if self.roots.is_empty() {
@@ -381,20 +390,13 @@ impl TrustedPluginRoots {
}) {
return None;
}
let script = file_system
.canonicalize(&script, /*sandbox*/ None)
.await
.ok()?;
let script = file_system.canonicalize(&script, sandbox).await.ok()?;
let candidates = self.local_candidates_for_executor_script(&script, version_match);
if candidates.is_empty() {
return None;
}
let metadata = file_system
.get_metadata(
&script,
GetMetadataOptions::default(),
/*sandbox*/ None,
)
.get_metadata(&script, GetMetadataOptions::default(), sandbox)
.await
.ok()?;
if !metadata.is_file
@@ -405,7 +407,7 @@ impl TrustedPluginRoots {
return None;
}
let contents = file_system
.read_file(&script, ReadFileOptions::default(), /*sandbox*/ None)
.read_file(&script, ReadFileOptions::default(), sandbox)
.await
.ok()?;
let mut matches = candidates
@@ -217,6 +217,7 @@ async fn resolves_relocated_script_through_executor_filesystem() {
&command(&["python", "scripts/run.py"]),
&cwd,
LOCAL_FS.as_ref(),
/*sandbox*/ None,
)
.await,
Some(PluginCommandAttribution {
@@ -232,6 +233,7 @@ async fn resolves_relocated_script_through_executor_filesystem() {
&command(&["python", "scripts/run.py"]),
&cwd,
LOCAL_FS.as_ref(),
/*sandbox*/ None,
)
.await,
None
@@ -796,7 +798,7 @@ async fn assert_executor_resolution(
) {
assert_eq!(
roots
.resolve_executor_attribution(command, cwd, LOCAL_FS.as_ref())
.resolve_executor_attribution(command, cwd, LOCAL_FS.as_ref(), /*sandbox*/ None)
.await,
Some(PluginCommandAttribution {
plugin_id: plugin_id.clone(),
@@ -1168,7 +1170,7 @@ async fn unrelated_scripts_skip_executor_lookup() -> anyhow::Result<()> {
// An executor lookup waits for provisioning; unrelated scripts must finish immediately.
assert_eq!(
futures::future::join3(
roots.resolve_executor_attribution(&command, &cwd, fs.as_ref()),
roots.resolve_executor_attribution(&command, &cwd, fs.as_ref(), /*sandbox*/ None),
roots.resolve_metrics_operation_in_filesystem(&command, &cwd, fs.as_ref()),
PluginMeasurementTarget::from_command(&command, &cwd, fs.as_ref()),
)