diff --git a/crates/engine/src/script/dom/images.rs b/crates/engine/src/script/dom/images.rs index bf79f77013..dc5417c318 100644 --- a/crates/engine/src/script/dom/images.rs +++ b/crates/engine/src/script/dom/images.rs @@ -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() } diff --git a/crates/engine/src/tests/script_dom_images.rs b/crates/engine/src/tests/script_dom_images.rs index 674d098eb5..1c1a78d864 100644 --- a/crates/engine/src/tests/script_dom_images.rs +++ b/crates/engine/src/tests/script_dom_images.rs @@ -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");