From 239d7ff61f5aa3892df57b7e6d7d216128cd0b5b Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 26 Nov 2026 11:27:37 -0800 Subject: [PATCH] Block mutating queries during held plugin runs --- crates/engine/src/session/execute.rs | 10 ++++----- crates/engine/src/tests/plugins.rs | 31 ++++++++++++++++++++++++++++ packaging/web/README.md | 7 ++++--- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/crates/engine/src/session/execute.rs b/crates/engine/src/session/execute.rs index 75b89ff239..47ad94233d 100644 --- a/crates/engine/src/session/execute.rs +++ b/crates/engine/src/session/execute.rs @@ -95,10 +95,11 @@ impl Session { if self.depth == 0 && self.script_key.is_some() && (waits_for_tool_edit(id) || id.starts_with("clipboard.import")) { return Err(EngineError::Busy); } - // While a plug-in run that calls commands holds the documents, only queries run, and the - // command that applies its output. A clipboard import is refused too: the run's end would put - // back the clipboard it started with. - let changes = (spec.journal && !JOURNALED_READS.contains(&id)) || id.starts_with("clipboard.import"); + // A command-calling plug-in run blocks external document, selection and preference changes. + // Its completion command can still apply the output. + let find_selects = id == "document.find" && params.get("select").and_then(Value::as_bool) == Some(true); + let changes = (waits_for_tool_edit(id) && !JOURNALED_READS.contains(&id) && (id != "document.find" || find_selects)) + || id.starts_with("clipboard.import"); if self.depth == 0 && self.plugin_calls_open() && !self.plugin_calls_end_with(id) && changes { return Err(EngineError::PluginBusy); } @@ -116,7 +117,6 @@ impl Session { // A command from outside the tool, while the tool's drag is in progress, is a step of its // own before the drag's ([`Session::outside_interaction`]). Find Objects with `select` is // journaled (`Session::journal_query`), so it is one too. - let find_selects = id == "document.find" && params.get("select").and_then(Value::as_bool) == Some(true); let outside = (spec.journal || find_selects) && !self.previewing && !self.in_tool_actions; // A preview that a top-level command applied first (a drag with Real-time Drawing off, kept // before Undo) reports its warning in the command's result. diff --git a/crates/engine/src/tests/plugins.rs b/crates/engine/src/tests/plugins.rs index f3c0faf572..200ecb0914 100644 --- a/crates/engine/src/tests/plugins.rs +++ b/crates/engine/src/tests/plugins.rs @@ -7922,3 +7922,34 @@ fn a_clipboard_import_is_refused_while_a_run_holds_the_documents() { run(&mut s, "clipboard.importText", json!({"text": "Hello"})); run(&mut s, "plugin.remove", json!({"id": id})); } + +#[test] +fn mutating_queries_are_refused_while_a_run_holds_the_documents() { + use cmd::plugin::FilterRun; + let id = "test.engine.heldqueries"; + let mut s = session(); + install_select_all_then_remove(&mut s, id); + let a = rect(&mut s, 10.0, "#ff0000"); + rect(&mut s, 40.0, "#00ff00"); + run(&mut s, "select.set", json!({"ids": [a.0]})); + let before = s.doc().unwrap().doc.clone(); + let prefs = s.prefs.to_json(); + FilterRun::begin_calls(&mut s, "plugin.run", &json!({"id": id})).unwrap(); + for (command, params) in [ + ("document.find", json!({"intersects": [0, 0, 400, 400], "select": true})), + ("prefs.set", json!({"key": "marqueeSelection", "value": "enclosed"})), + ] { + assert!(matches!(s.execute(command, ¶ms), Err(EngineError::PluginBusy)), "{command}"); + assert_eq!(s.doc().unwrap().selection.objects, [a]); + assert_eq!(s.doc().unwrap().doc, before); + assert_eq!(s.prefs.to_json(), prefs); + } + assert!(s.execute("prefs.get", &json!({})).is_ok()); + assert!(s.execute("document.find", &json!({"intersects": [0, 0, 400, 400]})).is_ok()); + s.end_plugin_calls(); + run(&mut s, "document.find", json!({"intersects": [0, 0, 400, 400], "select": true})); + assert_eq!(s.doc().unwrap().selection.objects.len(), 2); + run(&mut s, "prefs.set", json!({"key": "marqueeSelection", "value": "enclosed"})); + assert_eq!(s.prefs.marquee_selection, "enclosed"); + run(&mut s, "plugin.remove", json!({"id": id})); +} diff --git a/packaging/web/README.md b/packaging/web/README.md index 7f0583ab30..6d4e216902 100644 --- a/packaging/web/README.md +++ b/packaging/web/README.md @@ -39,9 +39,10 @@ files need revalidation. `script-src 'self'` alone blocks it, and the app does not start. A hash of that script in `script-src` allows it, or in `script-src-elem` when the policy sets that directive. The script changes with each build, so the hash must be taken from the build you deploy. - - WebAssembly compilation: the page and plug-in worker policies need `'wasm-unsafe-eval'` in - `script-src`, or in `default-src` when `script-src` is absent. Without it the app does not - start, and plug-ins fail to install and run. + - The page and plug-in worker policies can allow WebAssembly compilation with + `'wasm-unsafe-eval'` in `script-src`, or in `default-src` when `script-src` is absent. + A policy that blocks WebAssembly prevents the app from starting and plug-ins from installing + and running. - The plug-in worker: `worker-src 'self'`. Without `worker-src`, the browser uses `child-src`, then `script-src`, then `default-src`, so a `script-src` that allows the site's own scripts is enough only when the policy sets neither `worker-src` nor