From 26bfeafd46866185328523856f0b123cf3efd86f Mon Sep 17 00:00:00 2001 From: mavrick Date: Sat, 7 Nov 2026 14:55:30 -0600 Subject: [PATCH 1/9] fix(plugins): a malformed blocklist refresh keeps the last good list parse_blocklist read JSON of the wrong shape ({}, {"blocked": {}}, entries without an id) as an empty list, so a refresh cleared every withdrawal and overwrote the cached blocklist.json. It is now an error, which leaves the list in force and the cache unchanged, as a failed fetch does; only [] or {"blocked": []} clears it. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/plugins.rs | 4 ++-- crates/plugins/src/registry.rs | 21 +++++++++++++++------ crates/plugins/src/tests.rs | 8 ++++++++ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/crates/engine/src/cmd/plugins.rs b/crates/engine/src/cmd/plugins.rs index 745ad28b12..f35e890b4c 100644 --- a/crates/engine/src/cmd/plugins.rs +++ b/crates/engine/src/cmd/plugins.rs @@ -154,8 +154,8 @@ fn fetch_registry(url: &str) -> Result, St use rustgis_plugins::registry; let text = registry::fetch(url, registry::MAX_REGISTRY_BYTES)?; let entries = registry::parse(&String::from_utf8_lossy(&text), url)?; - // A registry without a blocklist blocks nothing; one that can't be fetched leaves the - // cached list in place. + // A registry without a blocklist blocks nothing; one that can't be fetched or read leaves + // the cached list in place. if let Ok(b) = registry::fetch(®istry::blocklist_url(url), 4 * 1024 * 1024) { let _ = rustgis_plugins::store::save_blocklist(url, &String::from_utf8_lossy(&b)); } diff --git a/crates/plugins/src/registry.rs b/crates/plugins/src/registry.rs index 8a6e6dd068..4e9e0c0311 100644 --- a/crates/plugins/src/registry.rs +++ b/crates/plugins/src/registry.rs @@ -192,15 +192,24 @@ pub fn blocklist_url(registry: &str) -> String { resolve(registry, "blocklist.json") } -/// Reads a blocklist (an object with a `blocked` array, or a bare array). +/// Reads a blocklist (an object with a `blocked` array, or a bare array). Any other shape, or an +/// entry without an `id`, is an error rather than an empty list, so a malformed refresh leaves +/// the last good list in place: only `[]` or `{"blocked": []}` clears it. pub fn parse_blocklist(text: &str) -> Result, String> { let root: Value = serde_json::from_str(text).map_err(|e| format!("the blocklist isn't valid JSON: {e}"))?; - let list = match &root { - Value::Array(a) => a.clone(), - Value::Object(o) => o.get("blocked").and_then(Value::as_array).cloned().unwrap_or_default(), - _ => Vec::new(), + let list = match root { + Value::Array(a) => a, + Value::Object(mut o) => match o.remove("blocked") { + Some(Value::Array(a)) => a, + _ => return Err("the blocklist has no `blocked` list".into()), + }, + _ => return Err("the blocklist isn't a list or an object with a `blocked` list".into()), }; - Ok(list.into_iter().take(MAX_ENTRIES).filter_map(|v| serde_json::from_value::(v).ok()).collect()) + list.into_iter() + .take(MAX_ENTRIES) + .enumerate() + .map(|(i, v)| serde_json::from_value::(v).map_err(|e| format!("blocklist entry {}: {e}", i + 1))) + .collect() } /// Why a package is blocked, if it is. diff --git a/crates/plugins/src/tests.rs b/crates/plugins/src/tests.rs index be87984cde..3e35e0bba7 100644 --- a/crates/plugins/src/tests.rs +++ b/crates/plugins/src/tests.rs @@ -403,6 +403,14 @@ fn blocked_plugins_are_unloaded_and_refused() { assert!(crate::get("unit-blocked").is_none()); let pkg = Package::from_zip(&testing::package("unit-blocked", &[])).unwrap(); assert!(crate::load(pkg, "t").unwrap_err().contains("malware")); + // A refresh of the wrong shape is refused and leaves the withdrawal in place. + for text in ["{}", r#"{"blocked": {}}"#, r#"{"blocked": null}"#, "1", r#"[{"reason": "no id"}]"#, "[1]"] { + assert!(crate::store::save_blocklist(registry::DEFAULT_URL, text).is_err(), "{text}"); + assert!(crate::blocked("unit-blocked", "any").is_some(), "{text} cleared the blocklist"); + } + // Only an explicitly empty list clears it. + assert_eq!(registry::parse_blocklist(r#"{"blocked": []}"#).unwrap(), Vec::new()); + assert_eq!(registry::parse_blocklist("[]").unwrap(), Vec::new()); crate::set_blocklist(Vec::new()); // Another registry's blocklist only adds: it can't bring back what the hosted one withdrew. load("unit-blocked", &[]); From 437bfbf1c8ce9a61590ea6d5180e0ade101306f1 Mon Sep 17 00:00:00 2001 From: mavrick Date: Sat, 7 Nov 2026 16:54:51 -0600 Subject: [PATCH 2/9] fix(plugins): warn when a blocklist can't be read; refuse one too long to read whole Review follow-up. The engine's plugin.registry/installFromRegistry and the Plugin Manager now warn that the plugins withdrawn before stay blocked when a registry's blocklist is refused, instead of dropping the error. A list of more than 100,000 entries is refused rather than cut short, so withdrawals past the cap aren't lost and a bad entry past it isn't skipped. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/plugins.rs | 29 ++++++++++++++++++----------- crates/engine/src/tests.rs | 16 ++++++++++++++++ crates/plugins/src/registry.rs | 15 +++++++++------ crates/plugins/src/tests.rs | 16 +++++++++++++++- crates/ui-egui/src/pluginsui.rs | 12 ++++++++++-- 5 files changed, 68 insertions(+), 20 deletions(-) diff --git a/crates/engine/src/cmd/plugins.rs b/crates/engine/src/cmd/plugins.rs index f35e890b4c..0d09da90f4 100644 --- a/crates/engine/src/cmd/plugins.rs +++ b/crates/engine/src/cmd/plugins.rs @@ -150,14 +150,17 @@ fn enable(_: &mut Session, p: &Value) -> CmdResult { /// The registry at `url` with each plugin's installed version. Applies its blocklist. #[cfg(not(target_arch = "wasm32"))] -fn fetch_registry(url: &str) -> Result, String> { +fn fetch_registry(s: &mut Session, url: &str) -> Result, String> { use rustgis_plugins::registry; let text = registry::fetch(url, registry::MAX_REGISTRY_BYTES)?; let entries = registry::parse(&String::from_utf8_lossy(&text), url)?; - // A registry without a blocklist blocks nothing; one that can't be fetched or read leaves - // the cached list in place. - if let Ok(b) = registry::fetch(®istry::blocklist_url(url), 4 * 1024 * 1024) { - let _ = rustgis_plugins::store::save_blocklist(url, &String::from_utf8_lossy(&b)); + // A registry without a blocklist blocks nothing; one that can't be fetched leaves the cached + // list in place, and so does one that can't be read, with a warning. + let blocklist = registry::blocklist_url(url); + if let Ok(b) = registry::fetch(&blocklist, 4 * 1024 * 1024) + && let Err(e) = rustgis_plugins::store::save_blocklist(url, &String::from_utf8_lossy(&b)) + { + s.warn(format!("{blocklist}: {e}; the plugins withdrawn before stay blocked")); } Ok(entries) } @@ -178,15 +181,17 @@ pub fn entry_status(e: &rustgis_plugins::registry::Entry) -> Value { v } -fn browse(_: &mut Session, p: &Value) -> CmdResult { +/// `plugin.registry`: the registry's plugins, each with its installed version (see +/// [`fetch_registry`]). +fn browse(s: &mut Session, p: &Value) -> CmdResult { let url = ps(p, "url").map(str::trim).filter(|s| !s.is_empty()).unwrap_or(rustgis_plugins::registry::DEFAULT_URL); #[cfg(not(target_arch = "wasm32"))] { - Ok(Value::Array(fetch_registry(url)?.iter().map(entry_status).collect())) + Ok(Value::Array(fetch_registry(s, url)?.iter().map(entry_status).collect())) } #[cfg(target_arch = "wasm32")] { - let _ = url; + let _ = (s, url); Err("in the browser, browse plugins in the Plugin Manager".into()) } } @@ -220,19 +225,21 @@ pub fn install_checked(e: &rustgis_plugins::registry::Entry, bytes: &[u8]) -> Re install_bytes(bytes) } -fn install_from_registry(_: &mut Session, p: &Value) -> CmdResult { +/// Installs the plugin `id` from the registry, checked against its entry (see [`install_checked`]), +/// after applying the registry's blocklist. +fn install_from_registry(s: &mut Session, p: &Value) -> CmdResult { let id = ps(p, "id").ok_or("id is required")?; let url = ps(p, "url").map(str::trim).filter(|s| !s.is_empty()).unwrap_or(rustgis_plugins::registry::DEFAULT_URL); #[cfg(not(target_arch = "wasm32"))] { - let entries = fetch_registry(url)?; + let entries = fetch_registry(s, url)?; let e = entries.iter().find(|e| e.id == id).ok_or_else(|| format!("the registry has no plugin '{id}'"))?; let bytes = rustgis_plugins::registry::fetch(&e.package, rustgis_plugins::package::MAX_PACKAGE)?; Ok(install_checked(e, &bytes)?.info()) } #[cfg(target_arch = "wasm32")] { - let _ = (id, url); + let _ = (s, id, url); Err("in the browser, install plugins from the Plugin Manager".into()) } } diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 48a513010d..f64a1b1989 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -12680,6 +12680,22 @@ fn serve_files(files: Vec<(String, Vec)>) -> (String, std::sync::Arc String { } /// Reads a blocklist (an object with a `blocked` array, or a bare array). Any other shape, or an -/// entry without an `id`, is an error rather than an empty list, so a malformed refresh leaves -/// the last good list in place: only `[]` or `{"blocked": []}` clears it. +/// entry without an `id`, or more than [`MAX_ENTRIES`] entries, is an error rather than a shorter +/// list, so a malformed refresh leaves the last good list in place: only `[]` or +/// `{"blocked": []}` clears it. pub fn parse_blocklist(text: &str) -> Result, String> { let root: Value = serde_json::from_str(text).map_err(|e| format!("the blocklist isn't valid JSON: {e}"))?; let list = match root { Value::Array(a) => a, Value::Object(mut o) => match o.remove("blocked") { Some(Value::Array(a)) => a, - _ => return Err("the blocklist has no `blocked` list".into()), + _ => return Err("the blocklist has no 'blocked' list".into()), }, - _ => return Err("the blocklist isn't a list or an object with a `blocked` list".into()), + _ => return Err("the blocklist isn't a list or an object with a 'blocked' list".into()), }; + if list.len() > MAX_ENTRIES { + return Err(format!("the blocklist has {} entries; at most {MAX_ENTRIES} can be read", list.len())); + } list.into_iter() - .take(MAX_ENTRIES) .enumerate() .map(|(i, v)| serde_json::from_value::(v).map_err(|e| format!("blocklist entry {}: {e}", i + 1))) .collect() diff --git a/crates/plugins/src/tests.rs b/crates/plugins/src/tests.rs index 3e35e0bba7..9e2fef13d6 100644 --- a/crates/plugins/src/tests.rs +++ b/crates/plugins/src/tests.rs @@ -392,6 +392,12 @@ fn registries_and_blocklists_are_read_defensively() { assert!(registry::blocked(&list, "x", "anything").is_some()); assert!(registry::blocked(&list, "y", &sha).is_some()); assert!(registry::blocked(&list, "y", &"b".repeat(64)).is_none()); + // A list too long to read whole is refused, not cut short. + let entry = json!({"id": "x"}); + let full = Value::Array(vec![entry.clone(); registry::MAX_ENTRIES]); + assert_eq!(registry::parse_blocklist(&full.to_string()).unwrap().len(), registry::MAX_ENTRIES); + let over = Value::Array(vec![entry; registry::MAX_ENTRIES + 1]); + assert!(registry::parse_blocklist(&over.to_string()).unwrap_err().contains("at most")); } /// Blocklisting unloads affected plugins and prevents them from being loaded again. @@ -404,7 +410,15 @@ fn blocked_plugins_are_unloaded_and_refused() { let pkg = Package::from_zip(&testing::package("unit-blocked", &[])).unwrap(); assert!(crate::load(pkg, "t").unwrap_err().contains("malware")); // A refresh of the wrong shape is refused and leaves the withdrawal in place. - for text in ["{}", r#"{"blocked": {}}"#, r#"{"blocked": null}"#, "1", r#"[{"reason": "no id"}]"#, "[1]"] { + for text in [ + "{}", + r#"{"blocked": {}}"#, + r#"{"blocked": null}"#, + "1", + r#"[{"reason": "no id"}]"#, + "[1]", + r#"[{"id": "ok"}, {"reason": "no id"}]"#, + ] { assert!(crate::store::save_blocklist(registry::DEFAULT_URL, text).is_err(), "{text}"); assert!(crate::blocked("unit-blocked", "any").is_some(), "{text} cleared the blocklist"); } diff --git a/crates/ui-egui/src/pluginsui.rs b/crates/ui-egui/src/pluginsui.rs index 469f2c10d8..df18034597 100644 --- a/crates/ui-egui/src/pluginsui.rs +++ b/crates/ui-egui/src/pluginsui.rs @@ -615,9 +615,17 @@ pub fn poll(app: &mut RustGisApp, ctx: &egui::Context) { Some(Ok(b)) => { let text = String::from_utf8_lossy(&b).to_string(); #[cfg(not(target_arch = "wasm32"))] - let pulled = rp::store::save_blocklist(®istry, &text).unwrap_or_default(); + let pulled = rp::store::save_blocklist(®istry, &text); #[cfg(target_arch = "wasm32")] - let pulled = rp::registry::parse_blocklist(&text).map(|l| rp::apply_blocklist(®istry, l)).unwrap_or_default(); + let pulled = rp::registry::parse_blocklist(&text).map(|l| rp::apply_blocklist(®istry, l)); + // One that can't be read leaves the list in force as it was. + let pulled = pulled.unwrap_or_else(|e| { + app.session.warn(crate::i18n::fmt( + "The plugin blocklist couldn't be read ({error}); the plugins withdrawn before stay blocked.", + &[("error", &e)], + )); + Vec::new() + }); for name in pulled { app.session.notify( crate::i18n::fmt("{name} was withdrawn from the plugin registry and has been turned off.", &[("name", &name)]), From 9387e93641a732f0275b05c17d4e8ea3c68a662f Mon Sep 17 00:00:00 2001 From: mavrick Date: Sat, 7 Nov 2026 19:05:33 -0600 Subject: [PATCH 3/9] fix(plugins): warn when the hosted registry's blocklist can't be downloaded Review follow-up. The hosted registry always publishes a blocklist, so failing to download it means the list in force may be out of date: plugin.registry, plugin.installFromRegistry and the Plugin Manager now warn. Another registry may have no blocklist, so its failed download stays quiet. The engine test also checks the notice is a warning. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/plugins.rs | 12 +++++++----- crates/engine/src/tests.rs | 4 +++- crates/ui-egui/src/pluginsui.rs | 12 ++++++++++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/crates/engine/src/cmd/plugins.rs b/crates/engine/src/cmd/plugins.rs index 0d09da90f4..992f13e1e7 100644 --- a/crates/engine/src/cmd/plugins.rs +++ b/crates/engine/src/cmd/plugins.rs @@ -154,12 +154,14 @@ fn fetch_registry(s: &mut Session, url: &str) -> Result rustgis_plugins::store::save_blocklist(url, &String::from_utf8_lossy(&b)).err(), + Err(e) => registry::is_default(url).then_some(e), + }; + if let Some(e) = refused { s.warn(format!("{blocklist}: {e}; the plugins withdrawn before stay blocked")); } Ok(entries) diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index f64a1b1989..43972a668f 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -12690,7 +12690,9 @@ fn unreadable_plugin_blocklist_warns() { let mut s = Session::new(Project::default()); let mark = s.notices_given(); s.run("plugin.registry", &json!({"url": format!("{base}/registry.json")})).unwrap(); - s.notices_since(mark).iter().filter(|n| n.text.contains("withdrawn before stay blocked")).count() + let said: Vec<_> = s.notices_since(mark).iter().filter(|n| n.text.contains("withdrawn before stay blocked")).collect(); + assert!(said.iter().all(|n| n.severity == rustgis_data::diagnostics::Severity::Warning), "{said:?}"); + said.len() }; assert_eq!(warned(br#"{"blocked": {}}"#), 1); assert_eq!(warned(br#"{"blocked": []}"#), 0); diff --git a/crates/ui-egui/src/pluginsui.rs b/crates/ui-egui/src/pluginsui.rs index df18034597..081879cf40 100644 --- a/crates/ui-egui/src/pluginsui.rs +++ b/crates/ui-egui/src/pluginsui.rs @@ -633,8 +633,16 @@ pub fn poll(app: &mut RustGisApp, ctx: &egui::Context) { ); } } - // No blocklist: nothing is blocked. - Some(Err(_)) => {} + // Another registry may have no blocklist (it blocks nothing); the hosted one always + // has one, so the list in force may be out of date. + Some(Err(e)) => { + if rp::registry::is_default(®istry) { + app.session.warn(crate::i18n::fmt( + "The plugin blocklist couldn't be downloaded ({error}); the plugins withdrawn before stay blocked.", + &[("error", &e)], + )); + } + } }, Job::Download { entry, slot } => match take(&slot) { None => waiting.push(Job::Download { entry, slot }), From 7a442ad8bed97a2fb9c7dbb3c37406d4fe8d1ca6 Mon Sep 17 00:00:00 2001 From: mavrick Date: Sat, 7 Nov 2026 20:10:48 -0600 Subject: [PATCH 4/9] fix(plugins): report a cached blocklist that can't be read at start Review follow-up. A blocklist.json cached by an older version that the stricter parser refuses is now reported in load_installed's errors (shown at start by the app and the command line) instead of being ignored. A test checks that refused refreshes leave the cache byte for byte. The warnings no longer promise that earlier withdrawals stay blocked, which isn't true on a first run or a fresh browser session: the last blocklist read, if any, stays in force. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/plugins.rs | 2 +- crates/engine/src/tests.rs | 4 ++-- crates/plugins/src/store.rs | 13 +++++++++++-- crates/plugins/src/tests.rs | 21 +++++++++++++++++++++ crates/ui-egui/src/pluginsui.rs | 4 ++-- 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/crates/engine/src/cmd/plugins.rs b/crates/engine/src/cmd/plugins.rs index 992f13e1e7..b0320545e1 100644 --- a/crates/engine/src/cmd/plugins.rs +++ b/crates/engine/src/cmd/plugins.rs @@ -162,7 +162,7 @@ fn fetch_registry(s: &mut Session, url: &str) -> Result registry::is_default(url).then_some(e), }; if let Some(e) = refused { - s.warn(format!("{blocklist}: {e}; the plugins withdrawn before stay blocked")); + s.warn(format!("{blocklist}: {e}; the last blocklist read, if any, stays in force")); } Ok(entries) } diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 43972a668f..ba80b4828e 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -12680,7 +12680,7 @@ fn serve_files(files: Vec<(String, Vec)>) -> (String, std::sync::Arc = s.notices_since(mark).iter().filter(|n| n.text.contains("withdrawn before stay blocked")).collect(); + let said: Vec<_> = s.notices_since(mark).iter().filter(|n| n.text.contains("stays in force")).collect(); assert!(said.iter().all(|n| n.severity == rustgis_data::diagnostics::Severity::Warning), "{said:?}"); said.len() }; diff --git a/crates/plugins/src/store.rs b/crates/plugins/src/store.rs index 08bf38d3da..cea0a08117 100644 --- a/crates/plugins/src/store.rs +++ b/crates/plugins/src/store.rs @@ -75,8 +75,17 @@ fn write_state(st: &State) -> Result<(), String> { pub fn load_installed() -> Vec { let mut errors = Vec::new(); let Some(dir) = dir() else { return errors }; - if let Some(list) = std::fs::read_to_string(dir.join("blocklist.json")).ok().and_then(|t| registry::parse_blocklist(&t).ok()) { - crate::set_blocklist(list); + // A cache this version can't read (one an older version saved) is reported, not trusted. + let cached = dir.join("blocklist.json"); + if let Ok(text) = std::fs::read_to_string(&cached) { + match registry::parse_blocklist(&text) { + Ok(list) => { + crate::set_blocklist(list); + } + Err(e) => { + errors.push(format!("{}: {e}; withdrawn plugins aren't blocked until the blocklist is fetched again", cached.display())) + } + } } let st = read_state(); let mut paths: Vec = std::fs::read_dir(&dir) diff --git a/crates/plugins/src/tests.rs b/crates/plugins/src/tests.rs index 9e2fef13d6..1eb5bf648a 100644 --- a/crates/plugins/src/tests.rs +++ b/crates/plugins/src/tests.rs @@ -1212,6 +1212,27 @@ fn process_manifests_are_checked() { assert!(crate::prepare(pkg, "test").unwrap_err().contains("doesn't run on this platform")); } +/// A refused refresh leaves the cached hosted blocklist byte for byte, and a cache that can't be +/// read at start is reported rather than ignored. +#[test] +fn cached_blocklist_survives_refused_refreshes() { + let plugins = std::env::temp_dir().join(format!("rustgis-test-blocklist-cache-{}", std::process::id())); + let _store = store_lock(); + crate::store::set_dir(Some(plugins.clone())); + std::fs::create_dir_all(&plugins).unwrap(); + let cache = plugins.join("blocklist.json"); + let good = r#"{"blocked": [{"id": "cached-withdrawal"}]}"#; + std::fs::write(&cache, good).unwrap(); + for text in ["{}", r#"{"blocked": {}}"#, r#"[{"id": "ok"}, {"reason": "no id"}]"#] { + assert!(crate::store::save_blocklist(registry::DEFAULT_URL, text).is_err(), "{text}"); + assert_eq!(std::fs::read_to_string(&cache).unwrap(), good, "{text} overwrote the cache"); + } + std::fs::write(&cache, r#"[{"id": "a"}, {"reason": "no id"}]"#).unwrap(); + let errors = crate::store::load_installed(); + assert!(errors.iter().any(|e| e.contains("blocklist.json") && e.contains("entry 2")), "{errors:?}"); + let _ = std::fs::remove_dir_all(&plugins); +} + #[test] fn process_packages_unpack_safely() { use std::io::Write; diff --git a/crates/ui-egui/src/pluginsui.rs b/crates/ui-egui/src/pluginsui.rs index 081879cf40..1caffc0183 100644 --- a/crates/ui-egui/src/pluginsui.rs +++ b/crates/ui-egui/src/pluginsui.rs @@ -621,7 +621,7 @@ pub fn poll(app: &mut RustGisApp, ctx: &egui::Context) { // One that can't be read leaves the list in force as it was. let pulled = pulled.unwrap_or_else(|e| { app.session.warn(crate::i18n::fmt( - "The plugin blocklist couldn't be read ({error}); the plugins withdrawn before stay blocked.", + "The plugin blocklist couldn't be read ({error}); the last one read, if any, stays in force.", &[("error", &e)], )); Vec::new() @@ -638,7 +638,7 @@ pub fn poll(app: &mut RustGisApp, ctx: &egui::Context) { Some(Err(e)) => { if rp::registry::is_default(®istry) { app.session.warn(crate::i18n::fmt( - "The plugin blocklist couldn't be downloaded ({error}); the plugins withdrawn before stay blocked.", + "The plugin blocklist couldn't be downloaded ({error}); the last one read, if any, stays in force.", &[("error", &e)], )); } From a469228bd84767a7e761a7a19194d4691b33b1d2 Mon Sep 17 00:00:00 2001 From: mavrick Date: Sat, 7 Nov 2026 21:36:06 -0600 Subject: [PATCH 5/9] fix(plugins): report a cached blocklist that can't be read at all Review follow-up. Startup also reports a blocklist.json it can't read (not text, or a read error), not only one it can't parse; a missing one is fine. The report no longer claims withdrawn plugins aren't blocked, which isn't true when a list is already in force. The engine test checks the warning names the blocklist and the reason. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/tests.rs | 5 +++++ crates/plugins/src/store.rs | 24 +++++++++++++++--------- crates/plugins/src/tests.rs | 5 +++++ 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index ba80b4828e..55d4068b2b 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -12692,6 +12692,11 @@ fn unreadable_plugin_blocklist_warns() { s.run("plugin.registry", &json!({"url": format!("{base}/registry.json")})).unwrap(); let said: Vec<_> = s.notices_since(mark).iter().filter(|n| n.text.contains("stays in force")).collect(); assert!(said.iter().all(|n| n.severity == rustgis_data::diagnostics::Severity::Warning), "{said:?}"); + // It names the blocklist and why it was refused. + assert!( + said.iter().all(|n| n.text.contains(&format!("{base}/blocklist.json")) && n.text.contains("no 'blocked' list")), + "{said:?}" + ); said.len() }; assert_eq!(warned(br#"{"blocked": {}}"#), 1); diff --git a/crates/plugins/src/store.rs b/crates/plugins/src/store.rs index cea0a08117..7f69e3b70a 100644 --- a/crates/plugins/src/store.rs +++ b/crates/plugins/src/store.rs @@ -75,17 +75,23 @@ fn write_state(st: &State) -> Result<(), String> { pub fn load_installed() -> Vec { let mut errors = Vec::new(); let Some(dir) = dir() else { return errors }; - // A cache this version can't read (one an older version saved) is reported, not trusted. + // A cache that can't be read (or one an older version saved that this one refuses) is + // reported, not trusted; there being none is fine. let cached = dir.join("blocklist.json"); - if let Ok(text) = std::fs::read_to_string(&cached) { - match registry::parse_blocklist(&text) { - Ok(list) => { - crate::set_blocklist(list); - } - Err(e) => { - errors.push(format!("{}: {e}; withdrawn plugins aren't blocked until the blocklist is fetched again", cached.display())) - } + let list = match std::fs::read_to_string(&cached) { + Ok(text) => registry::parse_blocklist(&text).map(Some), + Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(None), + Err(e) => Err(e.to_string()), + }; + match list { + Ok(Some(list)) => { + crate::set_blocklist(list); } + Ok(None) => {} + Err(e) => errors.push(format!( + "{}: {e}; it was ignored, so withdrawn plugins may not be blocked until the blocklist is fetched again", + cached.display() + )), } let st = read_state(); let mut paths: Vec = std::fs::read_dir(&dir) diff --git a/crates/plugins/src/tests.rs b/crates/plugins/src/tests.rs index 1eb5bf648a..74022ab055 100644 --- a/crates/plugins/src/tests.rs +++ b/crates/plugins/src/tests.rs @@ -1230,6 +1230,11 @@ fn cached_blocklist_survives_refused_refreshes() { std::fs::write(&cache, r#"[{"id": "a"}, {"reason": "no id"}]"#).unwrap(); let errors = crate::store::load_installed(); assert!(errors.iter().any(|e| e.contains("blocklist.json") && e.contains("entry 2")), "{errors:?}"); + // So is one that isn't text; none at all is fine. + std::fs::write(&cache, [0xff, 0xfe]).unwrap(); + assert!(crate::store::load_installed().iter().any(|e| e.contains("blocklist.json"))); + std::fs::remove_file(&cache).unwrap(); + assert!(crate::store::load_installed().is_empty()); let _ = std::fs::remove_dir_all(&plugins); } From 08efb83d553ea5d0010f51c0e45a3a2a242b1214 Mon Sep 17 00:00:00 2001 From: mavrick Date: Sun, 8 Nov 2026 12:29:03 -0600 Subject: [PATCH 6/9] fix(plugins): refuse a blocklist that isn't text; say which plugins one turned off Review follow-up. A refreshed blocklist that isn't UTF-8 was read with its bad bytes replaced, so an id holding one matched nothing; the engine and the Plugin Manager now refuse it with the usual warning, as the startup reader does. plugin.registry and plugin.installFromRegistry now say which plugins a newly withdrawn list turned off, as the Plugin Manager already did. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/plugins.rs | 23 ++++++++++++++++------- crates/engine/src/tests.rs | 20 ++++++++++++++++++++ crates/ui-egui/src/pluginsui.rs | 7 ++++--- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/crates/engine/src/cmd/plugins.rs b/crates/engine/src/cmd/plugins.rs index b0320545e1..0aeac258dc 100644 --- a/crates/engine/src/cmd/plugins.rs +++ b/crates/engine/src/cmd/plugins.rs @@ -154,15 +154,24 @@ fn fetch_registry(s: &mut Session, url: &str) -> Result rustgis_plugins::store::save_blocklist(url, &String::from_utf8_lossy(&b)).err(), - Err(e) => registry::is_default(url).then_some(e), + let applied = match registry::fetch(&blocklist, 4 * 1024 * 1024) { + Ok(b) => { + std::str::from_utf8(&b).map_err(|e| format!("it isn't text: {e}")).and_then(|t| rustgis_plugins::store::save_blocklist(url, t)) + } + Err(e) if registry::is_default(url) => Err(e), + Err(_) => Ok(Vec::new()), }; - if let Some(e) = refused { - s.warn(format!("{blocklist}: {e}; the last blocklist read, if any, stays in force")); + match applied { + Ok(pulled) if !pulled.is_empty() => s.notify( + format!("{} plugin(s) were withdrawn from the plugin registry and turned off: {}", pulled.len(), pulled.join(", ")), + true, + ), + Ok(_) => {} + Err(e) => s.warn(format!("{blocklist}: {e}; the last blocklist read, if any, stays in force")), } Ok(entries) } diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 55d4068b2b..1a969030a2 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -12703,6 +12703,26 @@ fn unreadable_plugin_blocklist_warns() { assert_eq!(warned(br#"{"blocked": []}"#), 0); } +/// A registry's blocklist that isn't text is refused with a warning, and one that withdraws a +/// loaded plugin says it was turned off. +#[test] +fn registry_blocklists_say_what_they_refuse_and_turn_off() { + let run = |blocklist: &[u8]| { + let (base, _) = + serve_files(vec![("/registry.json".into(), br#"{"plugins": []}"#.to_vec()), ("/blocklist.json".into(), blocklist.to_vec())]); + let mut s = Session::new(Project::default()); + let mark = s.notices_given(); + s.run("plugin.registry", &json!({"url": format!("{base}/registry.json")})).unwrap(); + s.notices_since(mark).iter().map(|n| n.text.clone()).collect::>() + }; + let said = run(b"[{\"id\": \"eng-\xff\"}]"); + assert!(said.iter().any(|t| t.contains("isn't text") && t.contains("stays in force")), "{said:?}"); + plugin("eng-withdrawn", &[]); + let said = run(br#"[{"id": "eng-withdrawn"}]"#); + assert!(said.iter().any(|t| t.contains("1 plugin(s) were withdrawn") && t.contains("Test eng-withdrawn")), "{said:?}"); + assert!(rustgis_plugins::get("eng-withdrawn").is_none()); +} + /// A Shapefile published as loose files is added by its `.shp` address (#1238): its `.dbf`, /// `.shx`, `.prj` and `.cpg` are fetched beside it with the address's query, and its `.prj` places /// it; the parts that aren't there are done without, said, but not its `.dbf`, nor a part a diff --git a/crates/ui-egui/src/pluginsui.rs b/crates/ui-egui/src/pluginsui.rs index 1caffc0183..3dbf6f7154 100644 --- a/crates/ui-egui/src/pluginsui.rs +++ b/crates/ui-egui/src/pluginsui.rs @@ -613,11 +613,12 @@ pub fn poll(app: &mut RustGisApp, ctx: &egui::Context) { Job::Blocklist { registry, slot } => match take(&slot) { None => waiting.push(Job::Blocklist { registry, slot }), Some(Ok(b)) => { - let text = String::from_utf8_lossy(&b).to_string(); + // Not text is refused too: a replaced byte in an id would match nothing. + let text = std::str::from_utf8(&b).map_err(|e| format!("it isn't text: {e}")); #[cfg(not(target_arch = "wasm32"))] - let pulled = rp::store::save_blocklist(®istry, &text); + let pulled = text.and_then(|t| rp::store::save_blocklist(®istry, t)); #[cfg(target_arch = "wasm32")] - let pulled = rp::registry::parse_blocklist(&text).map(|l| rp::apply_blocklist(®istry, l)); + let pulled = text.and_then(rp::registry::parse_blocklist).map(|l| rp::apply_blocklist(®istry, l)); // One that can't be read leaves the list in force as it was. let pulled = pulled.unwrap_or_else(|e| { app.session.warn(crate::i18n::fmt( From a89e8e36aa2bfb60646af9512652644622d631cc Mon Sep 17 00:00:00 2001 From: mavrick Date: Sun, 8 Nov 2026 13:12:13 -0600 Subject: [PATCH 7/9] fix(plugins): refuse a blocklist entry whose sha256 can't match Review follow-up. An entry with a sha256 that isn't a SHA-256 hash (a prefix, a cut-short hash) withdrew nothing without a word; it now refuses the refresh like an entry without an id. The engine's two blocklist tests are one test, so their process-wide blocklists don't race. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/tests.rs | 10 +++------- crates/plugins/src/registry.rs | 17 ++++++++++++----- crates/plugins/src/tests.rs | 1 + 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 1a969030a2..188a987686 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -12681,7 +12681,7 @@ fn serve_files(files: Vec<(String, Vec)>) -> (String, std::sync::Arc String { resolve(registry, "blocklist.json") } -/// Reads a blocklist (an object with a `blocked` array, or a bare array). Any other shape, or an -/// entry without an `id`, or more than [`MAX_ENTRIES`] entries, is an error rather than a shorter -/// list, so a malformed refresh leaves the last good list in place: only `[]` or -/// `{"blocked": []}` clears it. +/// Reads a blocklist (an object with a `blocked` array, or a bare array). Any other shape, an +/// entry without an `id` or with a `sha256` that isn't a SHA-256 hash (it would match nothing), or +/// more than [`MAX_ENTRIES`] entries, is an error rather than a shorter list, so a malformed +/// refresh leaves the last good list in place: only `[]` or `{"blocked": []}` clears it. pub fn parse_blocklist(text: &str) -> Result, String> { let root: Value = serde_json::from_str(text).map_err(|e| format!("the blocklist isn't valid JSON: {e}"))?; let list = match root { @@ -211,7 +211,14 @@ pub fn parse_blocklist(text: &str) -> Result, String> { } list.into_iter() .enumerate() - .map(|(i, v)| serde_json::from_value::(v).map_err(|e| format!("blocklist entry {}: {e}", i + 1))) + .map(|(i, v)| { + let b = serde_json::from_value::(v).map_err(|e| format!("blocklist entry {}: {e}", i + 1))?; + // Either case: `blocked` compares hashes ignoring it. + match &b.sha256 { + Some(h) if !is_sha256(&h.to_ascii_lowercase()) => Err(format!("blocklist entry {}: sha256 isn't a SHA-256 hash", i + 1)), + _ => Ok(b), + } + }) .collect() } diff --git a/crates/plugins/src/tests.rs b/crates/plugins/src/tests.rs index 74022ab055..3ca6080965 100644 --- a/crates/plugins/src/tests.rs +++ b/crates/plugins/src/tests.rs @@ -418,6 +418,7 @@ fn blocked_plugins_are_unloaded_and_refused() { r#"[{"reason": "no id"}]"#, "[1]", r#"[{"id": "ok"}, {"reason": "no id"}]"#, + r#"[{"id": "unit-blocked", "sha256": "sha256:abc"}]"#, ] { assert!(crate::store::save_blocklist(registry::DEFAULT_URL, text).is_err(), "{text}"); assert!(crate::blocked("unit-blocked", "any").is_some(), "{text} cleared the blocklist"); From d761e57e82af1ba4c87061d2e2607c414797af6c Mon Sep 17 00:00:00 2001 From: mavrick Date: Sun, 8 Nov 2026 13:51:32 -0600 Subject: [PATCH 8/9] fix(plugins): refuse a blocklist entry whose id isn't a plugin id Review follow-up. An entry whose id no plugin can have (empty, capitals, spaces) matched nothing without a word; it now refuses the refresh, as an entry whose sha256 isn't a hash does. Co-Authored-By: Claude Opus 5.5 --- crates/plugins/src/registry.rs | 7 +++++-- crates/plugins/src/tests.rs | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/plugins/src/registry.rs b/crates/plugins/src/registry.rs index b271c285bf..dd2ee8206d 100644 --- a/crates/plugins/src/registry.rs +++ b/crates/plugins/src/registry.rs @@ -193,8 +193,8 @@ pub fn blocklist_url(registry: &str) -> String { } /// Reads a blocklist (an object with a `blocked` array, or a bare array). Any other shape, an -/// entry without an `id` or with a `sha256` that isn't a SHA-256 hash (it would match nothing), or -/// more than [`MAX_ENTRIES`] entries, is an error rather than a shorter list, so a malformed +/// entry whose `id` isn't a plugin id or whose `sha256` isn't a SHA-256 hash (either would match +/// nothing), or more than [`MAX_ENTRIES`] entries, is an error rather than a shorter list, so a malformed /// refresh leaves the last good list in place: only `[]` or `{"blocked": []}` clears it. pub fn parse_blocklist(text: &str) -> Result, String> { let root: Value = serde_json::from_str(text).map_err(|e| format!("the blocklist isn't valid JSON: {e}"))?; @@ -213,6 +213,9 @@ pub fn parse_blocklist(text: &str) -> Result, String> { .enumerate() .map(|(i, v)| { let b = serde_json::from_value::(v).map_err(|e| format!("blocklist entry {}: {e}", i + 1))?; + if !valid_id(&b.id, false) { + return Err(format!("blocklist entry {}: '{}' isn't a plugin id", i + 1, b.id)); + } // Either case: `blocked` compares hashes ignoring it. match &b.sha256 { Some(h) if !is_sha256(&h.to_ascii_lowercase()) => Err(format!("blocklist entry {}: sha256 isn't a SHA-256 hash", i + 1)), diff --git a/crates/plugins/src/tests.rs b/crates/plugins/src/tests.rs index 3ca6080965..954fa054ee 100644 --- a/crates/plugins/src/tests.rs +++ b/crates/plugins/src/tests.rs @@ -419,6 +419,7 @@ fn blocked_plugins_are_unloaded_and_refused() { "[1]", r#"[{"id": "ok"}, {"reason": "no id"}]"#, r#"[{"id": "unit-blocked", "sha256": "sha256:abc"}]"#, + r#"[{"id": "Unit Blocked"}]"#, ] { assert!(crate::store::save_blocklist(registry::DEFAULT_URL, text).is_err(), "{text}"); assert!(crate::blocked("unit-blocked", "any").is_some(), "{text} cleared the blocklist"); From 9bf272edded9c09d1add12c91447614464c93f80 Mon Sep 17 00:00:00 2001 From: mavrick Date: Sun, 8 Nov 2026 14:29:58 -0600 Subject: [PATCH 9/9] fix(plugins): a refused blocklist entry isn't quoted at length Review follow-up. The refusal for an entry whose id isn't a plugin id no longer echoes the id, and an entry's other refusal reasons are cut to 200 characters: both can quote what the network sent, which the command line prints in full. The docs say a null sha256 withdraws every version, and the tests add an id with a bad character inside. Co-Authored-By: Claude Opus 5.5 --- crates/plugins/src/registry.rs | 13 ++++++++----- crates/plugins/src/tests.rs | 7 +++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/crates/plugins/src/registry.rs b/crates/plugins/src/registry.rs index dd2ee8206d..50f188e778 100644 --- a/crates/plugins/src/registry.rs +++ b/crates/plugins/src/registry.rs @@ -193,9 +193,10 @@ pub fn blocklist_url(registry: &str) -> String { } /// Reads a blocklist (an object with a `blocked` array, or a bare array). Any other shape, an -/// entry whose `id` isn't a plugin id or whose `sha256` isn't a SHA-256 hash (either would match -/// nothing), or more than [`MAX_ENTRIES`] entries, is an error rather than a shorter list, so a malformed -/// refresh leaves the last good list in place: only `[]` or `{"blocked": []}` clears it. +/// entry whose `id` isn't a plugin id or whose `sha256`, when given, isn't a SHA-256 hash (either +/// would match nothing; no `sha256`, or `null`, withdraws every version), or more than 100,000 +/// entries, is an error rather than a shorter list, so a malformed refresh leaves the last good +/// list in place: only `[]` or `{"blocked": []}` clears it. pub fn parse_blocklist(text: &str) -> Result, String> { let root: Value = serde_json::from_str(text).map_err(|e| format!("the blocklist isn't valid JSON: {e}"))?; let list = match root { @@ -212,9 +213,11 @@ pub fn parse_blocklist(text: &str) -> Result, String> { list.into_iter() .enumerate() .map(|(i, v)| { - let b = serde_json::from_value::(v).map_err(|e| format!("blocklist entry {}: {e}", i + 1))?; + // The reason is cut short: it can quote the entry, which comes from the network. + let b = serde_json::from_value::(v) + .map_err(|e| format!("blocklist entry {}: {}", i + 1, e.to_string().chars().take(200).collect::()))?; if !valid_id(&b.id, false) { - return Err(format!("blocklist entry {}: '{}' isn't a plugin id", i + 1, b.id)); + return Err(format!("blocklist entry {}: id isn't a plugin id", i + 1)); } // Either case: `blocked` compares hashes ignoring it. match &b.sha256 { diff --git a/crates/plugins/src/tests.rs b/crates/plugins/src/tests.rs index 954fa054ee..a5f8d215b7 100644 --- a/crates/plugins/src/tests.rs +++ b/crates/plugins/src/tests.rs @@ -398,6 +398,12 @@ fn registries_and_blocklists_are_read_defensively() { assert_eq!(registry::parse_blocklist(&full.to_string()).unwrap().len(), registry::MAX_ENTRIES); let over = Value::Array(vec![entry; registry::MAX_ENTRIES + 1]); assert!(registry::parse_blocklist(&over.to_string()).unwrap_err().contains("at most")); + // A refused entry isn't quoted at length. + let long = json!([{"id": "x".repeat(100_000)}, "y".repeat(100_000)]); + for list in [json!([long[0].clone()]), json!([long[1].clone()])] { + let e = registry::parse_blocklist(&list.to_string()).unwrap_err(); + assert!(e.starts_with("blocklist entry 1") && e.len() < 400, "{}", e.len()); + } } /// Blocklisting unloads affected plugins and prevents them from being loaded again. @@ -420,6 +426,7 @@ fn blocked_plugins_are_unloaded_and_refused() { r#"[{"id": "ok"}, {"reason": "no id"}]"#, r#"[{"id": "unit-blocked", "sha256": "sha256:abc"}]"#, r#"[{"id": "Unit Blocked"}]"#, + r#"[{"id": "unit blocked"}]"#, ] { assert!(crate::store::save_blocklist(registry::DEFAULT_URL, text).is_err(), "{text}"); assert!(crate::blocked("unit-blocked", "any").is_some(), "{text} cleared the blocklist");