Repository navigation
fix(plugins): every web address a plugin gives a command reaches only the internet #2848
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
4591e14
d86623e
d502a53
78ccd3f
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 |
|---|---|---|
|
|
@@ -116,19 +116,28 @@ fn cache() -> std::sync::MutexGuard<'static, Cache> { | |
| CACHE.lock().unwrap_or_else(|e| e.into_inner()) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| #[cfg(any(test, all(feature = "testing", debug_assertions)))] | ||
| thread_local! { | ||
| /// Tests: let the plugin fetch from this computer (a test server) and, when `wait` is off, | ||
| /// fetch as the browser does (pending, then run again). | ||
| pub(crate) static TEST: std::cell::Cell<(bool, bool)> = const { std::cell::Cell::new((false, true)) }; | ||
| } | ||
|
|
||
| /// Tests in other crates: lets the plugins this thread runs reach this computer (their test | ||
| /// server), with `host.fetch` and the addresses they give commands, as the engine's own tests do. | ||
| /// Only in a test build: the `testing` feature with debug assertions, never a release build. | ||
| #[cfg(all(feature = "testing", debug_assertions))] | ||
| #[doc(hidden)] | ||
| pub fn plugins_reach_this_computer() { | ||
| TEST.with(|t| t.set((true, t.get().1))); | ||
| } | ||
|
|
||
| fn allow_local() -> bool { | ||
| #[cfg(test)] | ||
| #[cfg(any(test, all(feature = "testing", debug_assertions)))] | ||
| { | ||
| TEST.with(|t| t.get().0) | ||
| } | ||
| #[cfg(not(test))] | ||
| #[cfg(not(any(test, all(feature = "testing", debug_assertions))))] | ||
| { | ||
| false | ||
| } | ||
|
|
@@ -188,6 +197,62 @@ impl Session { | |
| Err(e) => Err(e), | ||
| } | ||
| } | ||
|
|
||
| /// Whether what runs now is held to the internet: a plugin's authority is in the scope (as | ||
| /// for [`Self::named_reach`]), unless a test lets it reach its server on this computer. | ||
| pub(crate) fn plugin_held(&self) -> bool { | ||
| self.policy_plugin() && !allow_local() | ||
| } | ||
|
|
||
| /// Holds the web addresses a plugin gives a command that connects as [`Self::named_reach`] | ||
| /// holds the service it names, with its wording: each one among the command's parameters | ||
| /// (not inside the contents of a file it gives, `data` or `text`) on this computer or the local | ||
| /// network is refused, naming it, before anything is read. The rest are recorded as reaching | ||
| /// only the internet ([`cache::restrict_to_public`]), wherever their names resolve, so the | ||
| /// reads made of them later or elsewhere (a download left to the app, a tile layer drawn) | ||
| /// are held there too; while the command runs, all its requests are | ||
| /// ([`cache::held_to_public`]). Any other caller's addresses are its own choice, as before. | ||
| /// | ||
| /// [`cache::restrict_to_public`]: crate::render::rustgis_tiles::cache::restrict_to_public | ||
| /// [`cache::held_to_public`]: crate::render::rustgis_tiles::cache::held_to_public | ||
| pub(crate) fn hold_plugin_addresses(&self, params: &Value) -> Result<(), String> { | ||
| if !self.plugin_held() { | ||
| return Ok(()); | ||
| } | ||
| let named = web_addresses(params); | ||
| for url in &named { | ||
| // An address wrong some other way (spaces in it) is the command's to judge; it is | ||
| // held to the internet below all the same. | ||
| if let Err(e) = address::check_reach(url, address::Reach::Public) | ||
| && address::is_refusal(&e) | ||
| { | ||
| return Err(crate::sources::message_with_address(url, INTERNET_ONLY)); | ||
| } | ||
| } | ||
| for url in named { | ||
| crate::render::rustgis_tiles::cache::restrict_to_public(url); | ||
|
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 public-only restriction doesn't reach the requests these commands derive from the address, so a public-looking name that resolves to a local address is still read.
The case that would be refused is a literal local address (caught up front by Suggested fix: have each of these commands take its ceiling from Category: security
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. Fixed in d86623e. Recording the exact address alone didn't hold what a command derives from it, as you say. While a network command runs under a plugin's authority, every request it makes on that thread is now held to the internet: Tests: the tiles test
coderabbitai[bot] marked this conversation as resolved.
Resolved
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 PR discloses both trade-offs and the new notice covers the second, so this is a design question rather than a defect. Suggest scoping the record to the command's own run, or keeping plugin-recorded addresses out of Category: security
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. Both effects are deliberate, and the PR body states them. The record has to win over the user's earlier allowance. Some reads of the address happen after the command returns, outside its request context: a download left to the app, or a tile layer drawn later. Those reads only see what is recorded. If a plugin-named address kept the user's allowance, they would read the local network for the plugin. Recording it is how a document's links are held today. The user gets the allowance back by naming the address directly ( On filling the table: a plugin's addresses count as a document's do. When the table fills, the new notice says so once, which is the "never silent" half of this PR. Scoping the record to the command's run would leave those later reads unheld. Keeping plugin records in a table of their own would mean a second cap and a second notice; that is left out of this hardening change. |
||
| } | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| /// The web addresses among a command's own parameters, not inside the contents of a file it | ||
| /// gives (`data`, `text`). | ||
| fn web_addresses(params: &Value) -> Vec<&str> { | ||
| let Some(o) = params.as_object() else { return Vec::new() }; | ||
| o.iter() | ||
| .filter(|(key, _)| !matches!(key.as_str(), "data" | "text")) | ||
| .filter_map(|(_, v)| v.as_str().map(str::trim)) | ||
| .filter(|v| is_web_address(v)) | ||
| .collect() | ||
| } | ||
|
|
||
| /// Whether `v` is a web address the app fetches (`http://`, `https://` or `s3://`), as given or | ||
| /// marked with a saved login, an S3 connection or an anonymous read. | ||
| fn is_web_address(v: &str) -> bool { | ||
| let plain = crate::render::rustgis_tiles::s3::split_anonymous(v).0; | ||
| let plain = rustgis_data::login_address::inner(rustgis_data::s3_address::inner(plain)).to_ascii_lowercase(); | ||
| ["http://", "https://", "s3://"].iter().any(|scheme| plain.starts_with(scheme)) | ||
| } | ||
|
|
||
| /// The answer for a fetched document: `{url, text}`, and `json` when the text is a JSON object | ||
|
|
||
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 plugin reach check is now switched off by a Cargo feature, not only by
cfg(test).allow_local()returns true for any build withrustgis-engine'stestingfeature onceplugins_reach_this_computer()has run on that thread, and that function ispuband#[doc(hidden)]. Today only dev-dependencies enabletesting(ui-egui, assistant, engine's own tests), so release builds are safe. A future non-dev dependency that enablestestingwould silently remove the local-network guard for plugins. Suggest keeping the hookcfg(test)-only in this crate, or exposing a narrower test-support function behind a feature whose name says it is for tests and that release crates cannot enable by accident.Category: security
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.
Fixed in 78ccd3f. The hook now needs debug assertions as well as the
testingfeature (all(feature = "testing", debug_assertions), andcfg(test)inside the engine as before). A release build can't carry it even if something enablestestingby accident. The tests that use it build with the dev profile, as CI's do.