From e1125904be672e41958f551f26dbcc2e2be45d7e Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Wed, 11 Nov 2026 11:40:49 +0000 Subject: [PATCH] address review: packaging applies the source-read gate to the linked path --- crates/engine/src/cmd/print_cmds.rs | 7 +++++-- crates/engine/src/cmd/print_cmds/tests.rs | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/print_cmds.rs b/crates/engine/src/cmd/print_cmds.rs index f07b8173fc..fb8ab5cdf1 100644 --- a/crates/engine/src/cmd/print_cmds.rs +++ b/crates/engine/src/cmd/print_cmds.rs @@ -1498,8 +1498,11 @@ fn package(s: &mut Session, p: &Value) -> Result { }; // The path lives in the document, not in the params: a file the session's policy // refuses is packaged as missing, as smart-object renders refuse to read it. Both - // spellings are gated, the stored link path as well as the resolved one. - let refused = |p: &str| s.authorize.is_some_and(|gate| gate(cmd, &json!({"path": p})).is_err()); + // spellings are gated, the stored link path as well as the resolved one, and by the + // command the renderer reads the file with too. + let refused = |p: &str| { + s.authorize.is_some_and(|gate| [cmd, "layer.smartObjects.updateModifiedContent"].iter().any(|c| gate(c, &json!({"path": p})).is_err())) + }; if refused(path.as_str()) || refused(&file.to_string_lossy()) { missing.push(path.clone()); continue; diff --git a/crates/engine/src/cmd/print_cmds/tests.rs b/crates/engine/src/cmd/print_cmds/tests.rs index d2d2ce5075..f30d2f0419 100644 --- a/crates/engine/src/cmd/print_cmds/tests.rs +++ b/crates/engine/src/cmd/print_cmds/tests.rs @@ -1585,3 +1585,25 @@ fn package_skips_links_the_session_refuses() { assert_eq!(r["missing"], json!([link])); assert!(!std::path::Path::new(&format!("{dir}/pkg/Print Me/Links/art.png")).exists()); } + +/// A gate that allows `file.package` but refuses the command the renderer reads linked files with +/// still keeps the file out of the package. +#[test] +fn package_applies_the_source_read_gate() { + fn deny_source_reads(id: &str, _: &Value) -> Result<()> { + if id == "layer.smartObjects.updateModifiedContent" { Err(other("source reads are refused")) } else { Ok(()) } + } + let dir = tmp("package_read_gate"); + let link = format!("{dir}/art.png"); + let mut src = Session::new(); + src.execute("file.new", json!({"width": 20, "height": 20, "background": "#ff0000"})).unwrap(); + crate::file_cmds::save_doc(&src.active().unwrap().doc, &link, None).unwrap(); + let mut s = session("rgb", 8); + s.execute("file.placeLinked", json!({"path": link})).unwrap(); + s.authorize = Some(deny_source_reads); + let r = s.execute("file.package", json!({"dir": format!("{dir}/pkg")})).unwrap(); + assert_eq!(r["missing"], json!([link])); + s.authorize = None; + let r = s.execute("file.package", json!({"dir": format!("{dir}/pkg2")})).unwrap(); + assert_eq!(r["links"].as_array().map(Vec::len), Some(1), "an ungated package still copies the link"); +}