mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 13:02:50 -05:00
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:
1 parent
dc7d5ccfd7
commit
bbc85020e0
2 files changed
+17
-3
No files matched your search
@@ -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");
|
||||
|
||||
Reference in new issue
Block a user