From 3ef3ed568a0d97ee6e3c3d0f31fe3c43659baa26 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 13 Nov 2026 10:55:29 -0800 Subject: [PATCH] Scripts: script.grants.revoke does not look up a path outside the automation read roots --- crates/engine/src/cmd/scripts.rs | 13 +++++++++---- crates/engine/src/tests/script_io.rs | 19 +++++++++++++++++-- docs/mcp.md | 3 ++- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/crates/engine/src/cmd/scripts.rs b/crates/engine/src/cmd/scripts.rs index a620d398c8..3af4f351f1 100644 --- a/crates/engine/src/cmd/scripts.rs +++ b/crates/engine/src/cmd/scripts.rs @@ -104,7 +104,7 @@ pub fn specs() -> Vec { "Revoke Script File Permissions", [], None, - "{script?: a script file's path, path?: an allowed file or folder's path, all?: true (exactly one of all and the other two)} remove the kept file access of that script, of that path, of both together, or every one; a path is matched as script.grants lists it, after its links are followed; refused with the busy error while a script runs, as the run keeps the grants it started with → {removed: how many}", + "{script?: a script file's path, path?: an allowed file or folder's path, all?: true (exactly one of all and the other two)} remove the kept file access of that script, of that path, of both together, or every one; a path is matched as script.grants lists it, after its links are followed (a path outside the automation read roots is matched as given); refused with the busy error while a script runs, as the run keeps the grants it started with → {removed: how many}", always, grants_revoke ), @@ -358,9 +358,14 @@ fn grants_revoke(s: &mut Session, p: &Value) -> Result { const C: &str = "script.grants.revoke"; let path_of = |key: &str| match p.get(key) { None => Ok(None), - Some(Value::String(t)) if !t.is_empty() => { - Ok(Some(std::fs::canonicalize(t).map_or_else(|_| t.clone(), |real| crate::cmd::findfiles::plain(real).to_string_lossy().into_owned()))) - } + // A path the request may not read (outside the automation read roots, a network path among + // them) is compared as written, without looking it up. + Some(Value::String(t)) if !t.is_empty() => Ok(Some( + crate::file_access::check_read(t) + .ok() + .and_then(|()| std::fs::canonicalize(t).ok()) + .map_or_else(|| t.clone(), |real| crate::cmd::findfiles::plain(real).to_string_lossy().into_owned()), + )), Some(_) => Err(bad(C, format!("`{key}` must be a path"))), }; let (script_path, path) = (path_of("script")?, path_of("path")?); diff --git a/crates/engine/src/tests/script_io.rs b/crates/engine/src/tests/script_io.rs index 4fae8d33b8..39276d737f 100644 --- a/crates/engine/src/tests/script_io.rs +++ b/crates/engine/src/tests/script_io.rs @@ -1492,8 +1492,23 @@ fn script_file_dialog_grants_are_kept_for_the_same_script_text() { assert!(s.script_pick(crate::script::files::PickAnswer::Deny)); assert!(pump_to_picker(&mut s).is_some(), "the run ends"); - let removed = s.execute("script.grants.revoke", &json!({"path": out.to_string_lossy()})).unwrap(); - assert_eq!(removed["removed"], 1); + // Under automation read roots, a path outside them is not looked up: a link there to the + // granted file does not name it. + #[cfg(unix)] + { + let link = base.join("link.txt"); + std::os::unix::fs::symlink(&out, &link).unwrap(); + let roots = AutomationRoots::new(&[&base.join("main")], &[]).unwrap(); + let r = confine(roots.as_ref(), || s.execute("script.grants.revoke", &json!({"path": link.to_string_lossy()}))).unwrap(); + assert_eq!(r["removed"], 0, "{r}"); + let r = s.execute("script.grants.revoke", &json!({"path": link.to_string_lossy()})).unwrap(); + assert_eq!(r["removed"], 1, "without roots the link is followed: {r}"); + } + #[cfg(not(unix))] + { + let removed = s.execute("script.grants.revoke", &json!({"path": out.to_string_lossy()})).unwrap(); + assert_eq!(removed["removed"], 1); + } assert_eq!(s.execute("script.grants", &json!({})).unwrap()["grants"], json!([])); assert!(s.execute("script.grants.revoke", &json!({})).is_err()); assert!(!base.join("settings/Script Grants.json.part").exists()); diff --git a/docs/mcp.md b/docs/mcp.md index 1b642340cb..2e8843ce07 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -2348,7 +2348,8 @@ grant, which covers everything in the folder (a file's grant covers its own path takes its place), and `file` the grants file's path, or `null` without a settings folder. Under automation read roots, a `script`, `path` or `file` outside them is given as its file name alone. `script.grants.revoke {script?, path?, all?}` removes the grants of -a script file, of a path, of both together, or with `all: true` every grant, and returns `{removed}`. While a script +a script file, of a path, of both together, or with `all: true` every grant, and returns `{removed}`. A path is +matched after its links are followed; under automation read roots, a path outside them is matched as given. While a script runs it is refused with the busy error, as the run keeps the grants it started with. A grants file that is there but cannot be read is left as it is: `script.grants.revoke` fails, and a grant picked with Always is not kept. A script cannot run either command.