Repository navigation
fix(plugins): service discovery a plugin starts reaches only the internet #2841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -262,6 +262,10 @@ fn read_documents_with( | |
| fetch: FetchDocument<'_>, | ||
| ) -> Result<Discovery, String> { | ||
| let original = url_of(p)?; | ||
| // The service's own address is the caller's choice, unless a document read from the internet | ||
| // named it (a catalogue's record: [`cache::ceiling_for`] holds it there) or a plugin did | ||
| // (plugins reach only the internet: [`Session::named_reach`]). | ||
| let named = s.named_reach(original)?; | ||
| let mut address = | ||
| crate::render::rustgis_tiles::logins::inherit(original, &rustgis_data::ogc::capabilities_url(original, ps(p, "type"))); | ||
| let supplied = ps(p, "text"); | ||
|
|
@@ -289,22 +293,20 @@ fn read_documents_with( | |
| loop { | ||
| rustgis_data::progress::check().map_err(|e| e.to_string())?; | ||
| let crossed_origin = histories.get(&parent).copied().unwrap_or(false) || crosses_origin(&parent, &address); | ||
| // The service's own address is the user's choice, unless a document read from the | ||
| // internet named it (a catalogue's record: [`cache::ceiling_for`] holds it there); a linked | ||
| // one inherits its document's reach (a document not recorded, which can't happen, reaches | ||
| // only the internet). Either is judged by that reach, never by how the document's address | ||
| // is spelled: a public-looking name may connect on the local network, and its local links | ||
| // are then the service's own. | ||
| // The service's own address is read within `named`; a linked one inherits its document's | ||
| // reach (a document not recorded, which can't happen, reaches only the internet). Either is | ||
| // judged by that reach, never by how the document's address is spelled: a public-looking | ||
| // name may connect on the local network, and its local links are then the service's own. | ||
| let inherited = if seen.is_empty() { | ||
| cache::ceiling_for(original) | ||
| named | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the root of a possible side effect that is new with this change. Under a plugin, I have not confirmed this is reachable in practice, and the restriction may be the intended outcome for plugin-named internet hosts. Worth checking: either scope the restriction to what the plugin's own fetches need, or add a test that a plugin's discovery leaves a later, unrelated user read unchanged. Category: bug
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't add a new kind of entry. Every discovery read that connects on the internet already records its address, for any caller, plugins included: What this change adds is the same entry for a plugin's supplied-text and off-frame ( No change for this one. |
||
| } else { | ||
| reaches.get(crate::render::rustgis_tiles::logins::inner(&parent)).copied().unwrap_or(Reach::Public) | ||
| }; | ||
| let ceiling = inherited.min(cache::ceiling_for(&address)); | ||
| // A document the app supplies was recorded by its fetch if it came from the internet; one | ||
| // supplied by anything else (the Assistant, MCP, a plugin) says nothing trustworthy about | ||
| // where it was read, so what it names is taken as named on the internet. Its address | ||
| // itself stays the caller's own choice. | ||
| // itself is the caller's choice, as `named` holds it. | ||
| let read_within = if seen.is_empty() && supplied.is_some() && !s.policy_user() { ceiling.min(Reach::Public) } else { ceiling }; | ||
| let rejected = match crate::render::rustgis_tiles::address::check_reach(&address, ceiling) { | ||
| Ok(()) => false, | ||
|
|
@@ -1893,9 +1895,10 @@ pub(super) fn catalog_search_read(s: &mut Session, p: &Value, read: Option<Reach | |
| let url = url_of(p)?; | ||
| let request = records_request(s, p)?; | ||
| // Where the answer was read: natively, where the fetch connected; otherwise what the app's | ||
| // fetch recorded of it ([`cache::ceiling_for`]). The catalogue's own address is the user's | ||
| // choice, unless a document read from the internet named it. | ||
| let within = cache::ceiling_for(url).min(cache::ceiling_for(&request)); | ||
| // fetch recorded of it ([`cache::ceiling_for`]). The catalogue's own address is the caller's | ||
| // choice, unless a document read from the internet or a plugin named it | ||
| // ([`Session::named_reach`]). | ||
| let within = s.named_reach(url)?.min(cache::ceiling_for(&request)); | ||
| // An answer supplied by anything but the app says nothing trustworthy about where it was read. | ||
| let within = match read { | ||
| Some(read) => within.min(read), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20377,6 +20377,84 @@ fn plugins_fetch_documents_with_network() { | |
| rustgis_plugins::unload("eng-fetch"); | ||
| } | ||
|
|
||
| /// A service's collections at `local`, on this computer, whose one layer is there too (nothing | ||
| /// listens on port 9, so a read that is tried fails at once), and a catalogue's answer for a | ||
| /// catalogue on the local network linking to a service there: `(listing, search)`, each with its | ||
| /// document given as `text`. | ||
| fn local_service_and_catalogue(local: &str, catalogue: &str) -> (Value, Value) { | ||
| let items = format!("{local}/parcels/items"); | ||
| let collections = | ||
| json!({"collections":[{"id":"parcels","title":"Parcels","links":[{"rel":"items","type":"application/geo+json","href":items}]}]}); | ||
| let record = format!( | ||
| r#"<csw:GetRecordsResponse xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" xmlns:dc="http://purl.org/dc/elements/1.1/"><csw:SearchResults numberOfRecordsMatched="1"><csw:Record><dc:identifier>a</dc:identifier><dc:title>A</dc:title><dc:URI protocol="OGC:WMS">{catalogue}/wms</dc:URI></csw:Record></csw:SearchResults></csw:GetRecordsResponse>"# | ||
| ); | ||
| (json!({"url": local, "type": "ogcapi", "text": collections.to_string()}), json!({"url": catalogue, "text": record})) | ||
| } | ||
|
|
||
| /// Plugins reach only the internet, and so does the service discovery one starts: a service or | ||
| /// catalogue address on this computer or the local network is refused for a plugin, naming it and | ||
| /// why, by every command that discovers a service or searches a catalogue, and nothing is added. | ||
| #[test] | ||
| fn a_plugin_cannot_discover_a_service_off_the_internet() { | ||
| let mut s = world(); | ||
| let id = "eng-service-local"; | ||
| plugin(id, &["network", "edit"]); | ||
| let (local, catalogue) = ("http://127.0.0.1:9/ogc/collections", "http://192.168.21.4/csw"); | ||
| let (listing, search) = local_service_and_catalogue(local, catalogue); | ||
| let with = |extra: Value| { | ||
| let mut p = listing.clone(); | ||
| if let (Some(p), Some(extra)) = (p.as_object_mut(), extra.as_object()) { | ||
| p.extend(extra.clone()); | ||
| } | ||
| p | ||
| }; | ||
| for (op, p, url) in [ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The list covers Category: quality
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Left for the release quality pass. |
||
| ("service.add", with(json!({"layer": "parcels"})), local), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The case list covers Category: quality
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Left for the release quality pass. |
||
| ("service.add", json!({"url": "http://127.0.0.1:9/wms", "type": "wms", "layer": "roads"}), "http://127.0.0.1:9/wms"), | ||
| ("service.layers", listing.clone(), local), | ||
| ("service.coverage", with(json!({"layer": "parcels"})), local), | ||
| ("service.groupPlan", listing.clone(), local), | ||
| ("service.import", with(json!({"name": "Parcels"})), local), | ||
| ("catalog.search", search.clone(), catalogue), | ||
| ] { | ||
| let e = forward(&mut s, id, op, p).unwrap_err(); | ||
| assert!(e.contains(url) && e.contains("plugins fetch only from the internet, not this computer or the local network"), "{op}: {e}"); | ||
| } | ||
| assert!(s.map().layers.iter().all(|l| l.name != "Parcels" && l.name != "roads"), "nothing was added"); | ||
| rustgis_plugins::unload(id); | ||
| } | ||
|
|
||
| /// The user's own service and catalogue on this computer and the local network are read as ever: | ||
| /// only a plugin's discovery is held to the internet. | ||
| #[test] | ||
| fn the_users_own_local_service_is_still_discovered() { | ||
| let mut s = world(); | ||
| let (listing, search) = local_service_and_catalogue("http://127.0.0.1:9/ogc/collections", "http://192.168.21.4/csw"); | ||
| let own = s.run("service.layers", &listing).unwrap(); | ||
| assert_eq!(own["layers"].as_array().map_or(0, Vec::len), 1, "{own}"); | ||
| let own = s.run("catalog.search", &search).unwrap(); | ||
| assert_eq!(own["records"][0]["links"].as_array().map_or(0, Vec::len), 1, "{own}"); | ||
| } | ||
|
|
||
| /// A document a plugin supplies for a service on the internet has what it names held there: its | ||
| /// link into the local network is refused, naming it, as is a catalogue answer's. | ||
| #[test] | ||
| fn a_document_a_plugin_supplies_names_only_the_internet() { | ||
| let mut s = world(); | ||
| let id = "eng-service-text"; | ||
| plugin(id, &["network"]); | ||
| let linked = "http://10.0.21.5/collections"; | ||
| let landing = json!({"links":[{"rel":"data","type":"application/json","href":linked}]}).to_string(); | ||
| let p = json!({"url": "https://gis-21.corp-looks-public.example/ogc", "type": "ogcapi", "text": landing}); | ||
| let e = forward(&mut s, id, "service.layers", p).unwrap_err(); | ||
| assert!(e.contains(linked) && e.contains("local network"), "{e}"); | ||
| let (_, search) = local_service_and_catalogue("http://127.0.0.1:9/ogc/collections", "http://192.168.21.4/csw"); | ||
| let search = json!({"url": "https://csw-21.corp-looks-public.example/csw", "text": search["text"]}); | ||
| let out = forward(&mut s, id, "catalog.search", search).unwrap(); | ||
| assert_eq!(out["records"][0]["links"].as_array().map_or(0, Vec::len), 0, "{out}"); | ||
| rustgis_plugins::unload(id); | ||
| } | ||
|
|
||
| /// Where nothing may wait (the browser), `host.fetch` answers pending: the command is undone, | ||
| /// quietly, and runs again once the answer is in, when the cache answers. | ||
| #[test] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The doc says "the widest reach", but for a plugin this returns
Reach::Public, which is the narrowest value inReach's ordering (Public < Local < Forbidden, and callers use.min()). The meaning is right, but the wording reads backwards for anyone who knows the ordering. Suggest saying "the most a caller may reach" or "held to the internet".The
catalog_search_readcomment inservice.rs(~line 1898) has a similar issue: it says the catalogue address is "unless a document read from the internet or a plugin named it". For a plugin,named_reachdoesn't consult any naming. It refuses local addresses and holds internet ones to Public.Category: quality
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left for the release quality pass: "the widest reach" becomes "how far discovery may reach from", and the catalogue comment says a plugin's address is held to the internet rather than "named".