Scripts: PlacedItem.file checks the script's own read scope, not open documents

Reading file of a placed image linked to a file outside the script's read
scope throws Script file access denied even when that file is also open as
a document, whose file the script's commands may read.
This commit is contained in:
dotCooCoo
2026-11-21 18:51:00 -08:00
parent dc7d5ccfd7
commit bbc85020e0
2 changed files with 17 additions and 3 deletions
+3 -3
View File
@@ -289,10 +289,10 @@ fn doc_raster(h: &Host, a: &[Data]) -> Answer {
// ---- files ----
/// Whether the script's commands may read `path` now ([`crate::file_access::ScriptGate`]).
/// Whether the script may read `path` now by its own read scope and the read roots
/// ([`crate::file_access::ScriptGate`]), without the open documents' files a command may also read.
fn may_read(h: &Host, path: &str) -> bool {
let documents = h.session.borrow().documents().iter().filter_map(|d| d.path.clone()).collect();
let gate = h.disk.borrow().gate(documents);
let gate = h.disk.borrow().gate(Vec::new());
crate::file_access::with_script_gate(gate, || crate::file_access::check_read(path)).is_ok()
}
@@ -411,6 +411,20 @@ fn image_file_getter_hides_out_of_scope_link() {
let _ = std::fs::remove_dir_all(base);
}
#[test]
fn image_file_getter_hides_a_link_to_an_open_document_out_of_scope() {
let base = folder("hidedoc");
let b = base.join("outside/secret.png");
std::fs::write(&b, gray_png(4, 4)).unwrap();
let mut s = session();
place(&mut s, &b, true);
// The linked file is also the file of an open document, which the script's commands may read.
s.doc_mut().unwrap().path = Some(b.to_string_lossy().into_owned());
let e = failure(&mut s, &base, "vc.log(app.activeDocument.placedItems[0].file.fsName);");
assert!(e.contains("Script file access denied") && !e.contains("secret"), "{e}");
let _ = std::fs::remove_dir_all(base);
}
#[test]
fn stale_and_foreign_placed_items_are_refused() {
let base = folder("stale");