diff --git a/crates/openhuman-core/src/modules/browser_egress_host.rs b/crates/openhuman-core/src/modules/browser_egress_host.rs index 6e56402777a..d280a2c11d1 100644 --- a/crates/openhuman-core/src/modules/browser_egress_host.rs +++ b/crates/openhuman-core/src/modules/browser_egress_host.rs @@ -61,11 +61,56 @@ pub(crate) fn browser_dial_alias(config: &crate::config::Config) -> Value { alias } +/// The `browser.egress` section TinyComputer's callback-bound load admitted. +/// TinyBus refuses that module any later config with different bytes +/// ("scoped callback configuration is immutable"), so an edited or rotated +/// `[browser] upstream_proxies` must not reach a refresh: it would fail every +/// browser call until restart. Refreshes reuse what was admitted instead, and +/// the edit takes effect at the next load. +fn admitted_alias() -> &'static parking_lot::Mutex> { + static ADMITTED: std::sync::OnceLock>> = + std::sync::OnceLock::new(); + ADMITTED.get_or_init(|| parking_lot::Mutex::new(None)) +} + +/// Build the alias for a callback-bound load and record it as admitted. +pub(crate) fn admit_browser_dial_alias(config: &crate::config::Config) -> Value { + admit_in(admitted_alias(), config) +} + +fn admit_in(slot: &parking_lot::Mutex>, config: &crate::config::Config) -> Value { + let alias = browser_dial_alias(config); + *slot.lock() = Some(alias.clone()); + alias +} + +/// The alias a refresh pushes: the admitted one when a load recorded it, so a +/// changed proxy list never makes TinyBus refuse the refresh. +fn refresh_alias_in( + slot: &parking_lot::Mutex>, + config: &crate::config::Config, +) -> Value { + let current = browser_dial_alias(config); + match slot.lock().as_ref() { + Some(admitted) => { + if *admitted != current { + // Never the URLs: they carry credentials. + tracing::warn!( + "[computer] [browser] upstream_proxies changed since TinyComputer loaded; \ + the change takes effect at the next core start" + ); + } + admitted.clone() + } + None => current, + } +} + /// Make sure the browser's destination-only policy is registered for this /// host context, then return the stable alias for TinyComputer config. pub(crate) async fn browser_dial_config(config: &crate::config::Config) -> Result { current_browser_policy(config).await?; - Ok(browser_dial_alias(config)) + Ok(refresh_alias_in(admitted_alias(), config)) } /// The id and generation of the current browser policy, registering a new one diff --git a/crates/openhuman-core/src/modules/browser_egress_host_tests.rs b/crates/openhuman-core/src/modules/browser_egress_host_tests.rs index edae5c8ec3f..5a3e8f3fe74 100644 --- a/crates/openhuman-core/src/modules/browser_egress_host_tests.rs +++ b/crates/openhuman-core/src/modules/browser_egress_host_tests.rs @@ -180,6 +180,40 @@ fn the_config_names_a_stable_alias_not_the_rotating_policy() { assert_eq!(alias.as_object().unwrap().len(), 2); } +#[test] +fn a_refresh_keeps_the_upstream_proxies_admitted_at_load() { + // TinyBus refuses a callback-bound refresh whose bytes differ from the + // load's, so an edited or rotated proxy list must wait for the next load. + let slot = parking_lot::Mutex::new(None); + let mut loaded = crate::config::Config::default(); + loaded.browser.upstream_proxies = vec![crate::config::schema::BrowserUpstreamProxy { + domains: vec!["reddit.com".into()], + url: "http://resi:old@gate.example:7000".into(), + }]; + let admitted = admit_in(&slot, &loaded); + + let mut edited = loaded.clone(); + edited.browser.upstream_proxies[0].url = "http://resi:rotated@gate.example:7000".into(); + assert_eq!(refresh_alias_in(&slot, &edited), admitted); + let mut removed = loaded.clone(); + removed.browser.upstream_proxies.clear(); + assert_eq!(refresh_alias_in(&slot, &removed), admitted); + assert_eq!(refresh_alias_in(&slot, &loaded), admitted); + + // Before any load, a refresh builds from the current config. + let empty = parking_lot::Mutex::new(None); + assert_eq!( + refresh_alias_in(&empty, &edited), + browser_dial_alias(&edited) + ); + // The next load admits the edit. + assert_eq!(admit_in(&slot, &edited), browser_dial_alias(&edited)); + assert_eq!( + refresh_alias_in(&slot, &edited), + browser_dial_alias(&edited) + ); +} + #[test] fn configured_upstream_proxies_ride_in_the_private_egress_section() { let mut config = crate::config::Config::default(); diff --git a/crates/openhuman-core/src/modules/ops.rs b/crates/openhuman-core/src/modules/ops.rs index 0e00c1beb3d..4acc81e40ef 100644 --- a/crates/openhuman-core/src/modules/ops.rs +++ b/crates/openhuman-core/src/modules/ops.rs @@ -391,7 +391,7 @@ pub(super) async fn computer_callback_config( let mut module_config = module_config(config, id).await; super::desktop::inject_security_browser_config( &mut module_config, - super::browser_egress_host::browser_dial_alias(config), + super::browser_egress_host::admit_browser_dial_alias(config), callback_destination, ); module_config diff --git a/crates/openhuman-core/src/platform/about_app/catalog_tests.rs b/crates/openhuman-core/src/platform/about_app/catalog_tests.rs index 4f4d9609c1c..992cd528978 100644 --- a/crates/openhuman-core/src/platform/about_app/catalog_tests.rs +++ b/crates/openhuman-core/src/platform/about_app/catalog_tests.rs @@ -573,3 +573,19 @@ fn computer_capabilities_disclose_the_components_ceiling() { ); } } + +#[test] +fn browser_automation_discloses_the_optional_upstream_proxy() { + let capability = + lookup("workflows.computer_browser_automation").expect("browser automation is listed"); + assert!(capability + .description + .contains("[browser] upstream_proxies")); + let privacy = capability.privacy.expect("browser automation has privacy"); + assert!(privacy + .destinations + .iter() + .any(|destination| destination.contains("upstream HTTP proxy") + && destination.contains("[browser] upstream_proxies") + && destination.contains("next core start"))); +} diff --git a/crates/openhuman-core/src/platform/about_app/catalog_workflows_automation.rs b/crates/openhuman-core/src/platform/about_app/catalog_workflows_automation.rs index f660118594d..3d5c3442b0c 100644 --- a/crates/openhuman-core/src/platform/about_app/catalog_workflows_automation.rs +++ b/crates/openhuman-core/src/platform/about_app/catalog_workflows_automation.rs @@ -96,13 +96,13 @@ Capability { name: "Browser Automation", domain: "workflows", category: CapabilityCategory::Workflows, - description: "Inspect pages and run bounded browser tasks in Chrome through TinyComputer, with a rescue model for failed steps. A finished task's plan and the page elements it found are kept per site in the core's workspace, so the next task there starts sooner. Switched off by [components] computer = false, which unregisters the browser tools and answers the browser RPCs with COMPONENT_DISABLED:computer.", + description: "Inspect pages and run bounded browser tasks in Chrome through TinyComputer, with a rescue model for failed steps. A finished task's plan and the page elements it found are kept per site in the core's workspace, so the next task there starts sooner. An operator can route chosen domains through an upstream HTTP proxy ([browser] upstream_proxies) for sites that block this machine’s own address; TinySecurity still authorizes every routed page and the proxy itself. Switched off by [components] computer = false, which unregisters the browser tools and answers the browser RPCs with COMPONENT_DISABLED:computer.", how_to: "Connections > Computer > Browser, then ask the assistant to use the browser; What tasks learn turns learning off or forgets learned sites", status: CapabilityStatus::Beta, privacy: Some(CapabilityPrivacy { leaves_device: true, data_kind: PrivacyDataKind::Raw, - destinations: &["Visited websites", "OpenRouter, OpenHuman backend, OpenJev or Sage for task decisions", "TypeSafe or Surplus Intelligence for captcha images, only when the captcha solver is on (captcha_provider)"], + destinations: &["Visited websites", "OpenRouter, OpenHuman backend, OpenJev or Sage for task decisions", "TypeSafe or Surplus Intelligence for captcha images, only when the captcha solver is on (captcha_provider)", "The operator’s upstream HTTP proxy, for the domains in [browser] upstream_proxies, only when set; adding, changing or removing it takes effect at the next core start"], }), }, Capability { diff --git a/scripts/ci/process-statics.json b/scripts/ci/process-statics.json index 8bccf108dbf..1f9620ceade 100644 --- a/scripts/ci/process-statics.json +++ b/scripts/ci/process-statics.json @@ -958,5 +958,15 @@ "category": "B", "reason": "Prepared program quotes are partitioned by QuoteBinding (workspace path, a hash of the encrypted phrase, account index and Solana endpoint). A take is refused, and the quote stays in the map, unless all four match the context that takes it.", "verification": "web3/wallet/program/ops_tests.rs: a_quote_is_taken_only_in_the_context_it_was_prepared_in" + }, + { + "file": "crates/openhuman-core/src/modules/browser_egress_host.rs", + "scope": "", + "name": "ADMITTED", + "type": "std::sync::OnceLock>>", + "count": 1, + "category": "A", + "reason": "The browser.egress section TinyComputer's callback-bound load admitted. TinyComputer is one module per process with one host config, and TinyBus refuses a refresh that differs from what was loaded, so this mirrors the module's own process-wide config. It holds the operator's [browser] upstream_proxies (process configuration), never tenant data.", + "verification": "modules/browser_egress_host_tests.rs: a_refresh_keeps_the_upstream_proxies_admitted_at_load" } ]