From f5e4a4c79c311c12f51a430fa55ac243f60a6fab Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Fri, 23 Oct 2026 10:14:02 +0000 Subject: [PATCH 1/6] test(browser-egress): cover dns rebinding in live egress tests Add a live test module exercising DNS rebinding against the browser egress path, and extend the fixture host with an optional resolved address so authorization can be checked against the address the browser actually resolved. The observation log now records the resolution alongside the authorize call, and the existing authority denial fixtures pass no resolved address to keep their behaviour unchanged. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../src/linked/linked_tests/live_tests.rs | 2 +- .../authority_denial_tests.rs | 2 + .../dns_rebinding_tests.rs | 111 ++++++++++++++++++ .../browser_egress_live_tests/mod.rs | 81 +++++++++++-- 4 files changed, 186 insertions(+), 10 deletions(-) create mode 100644 crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/dns_rebinding_tests.rs diff --git a/crates/tinycomputer-browser/src/linked/linked_tests/live_tests.rs b/crates/tinycomputer-browser/src/linked/linked_tests/live_tests.rs index f6283f00f..64c80f5f8 100644 --- a/crates/tinycomputer-browser/src/linked/linked_tests/live_tests.rs +++ b/crates/tinycomputer-browser/src/linked/linked_tests/live_tests.rs @@ -367,7 +367,7 @@ async fn live_chromium_dns_rebinding_never_reaches_the_rebound_private_socket() .execute(json!({"id":"close","action":"close"})) .await; assert_eq!(navigation["success"], true, "{navigation}"); - let observed_addresses = observed_addresses.lock().unwrap(); + let observed_addresses = observed_addresses.lock().unwrap().clone(); assert_eq!( observed_addresses.first(), Some(&allowed_address), diff --git a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/authority_denial_tests.rs b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/authority_denial_tests.rs index aff977399..7dbc2ba1d 100644 --- a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/authority_denial_tests.rs +++ b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/authority_denial_tests.rs @@ -115,6 +115,7 @@ async fn live_chromium_denies_stale_egress_generation_before_dialing() -> tinybu Some(EgressHost { allowed: Arc::new(AtomicBool::new(true)), allowed_addresses: vec![allowed_address], + resolved_address: None, grant_generation: Some(40), authorize_delay: Duration::ZERO, observations: observations.clone(), @@ -168,6 +169,7 @@ async fn live_chromium_denies_when_host_authorization_times_out() -> tinybus::Re Some(EgressHost { allowed: Arc::new(AtomicBool::new(true)), allowed_addresses: vec![denied_address.clone()], + resolved_address: None, grant_generation: None, authorize_delay: Duration::from_secs(6), observations: observations.clone(), diff --git a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/dns_rebinding_tests.rs b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/dns_rebinding_tests.rs new file mode 100644 index 000000000..c6910e743 --- /dev/null +++ b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/dns_rebinding_tests.rs @@ -0,0 +1,111 @@ +//! Live Chromium coverage for a fixture host rebound between authorizations. + +use super::*; + +#[tokio::test] +async fn live_chromium_module_never_dials_a_rebound_private_socket() -> tinybus::Result<()> { + // Keep both endpoints on assigned loopback addresses and the same port; + // the resolver fixture changes only the address returned for fixture.test. + let allowed_listener = tokio::net::TcpListener::bind("[::1]:0").await?; + let port = allowed_listener.local_addr()?.port(); + let rebound_listener = tokio::net::TcpListener::bind(("127.0.0.1", port)).await?; + let allowed_address = allowed_listener.local_addr()?.to_string(); + let rebound_address = rebound_listener.local_addr()?.to_string(); + let extra_connections = Arc::new(AtomicUsize::new(0)); + let (served_tx, served_rx) = tokio::sync::oneshot::channel(); + let server = tokio::spawn(serve_fixture( + allowed_listener, + b"allowed fixture".to_vec(), + extra_connections.clone(), + served_tx, + None, + )); + let resolved_address = Arc::new(Mutex::new(allowed_address.clone())); + let browser = start_browser_with_fixture_hosts_and_resolution( + vec![allowed_address.clone()], + port, + "/before-rebind", + served_rx, + Some(resolved_address.clone()), + ) + .await?; + + let before_rebind_authorizations = browser + .observations + .lock() + .unwrap() + .iter() + .filter(|call| call.starts_with("authorize:fixture-policy:41:fixture.test:")) + .count(); + let connections_before_rebind = extra_connections.load(Ordering::SeqCst); + *resolved_address.lock().unwrap() = rebound_address.clone(); + let denied: DesktopResponse = browser + .proxy + .call( + browser_names::methods::NAVIGATE, + (serde_json::json!({ + "session": browser.session, + "url": format!("http://fixture.test:{port}/after-rebind") + }),), + ) + .await?; + + assert!(!denied.ok, "navigation to the rebound address was allowed"); + assert!( + tokio::time::timeout(Duration::from_millis(500), rebound_listener.accept()) + .await + .is_err(), + "the rebound private socket received a connection" + ); + assert!( + tokio::time::timeout(Duration::from_millis(500), async { + while extra_connections.load(Ordering::SeqCst) == connections_before_rebind { + tokio::task::yield_now().await; + } + }) + .await + .is_err(), + "the request reached the previously allowed socket after rebinding" + ); + + let calls = browser.observations.lock().unwrap(); + assert!( + calls + .iter() + .filter(|call| call.starts_with("authorize:fixture-policy:41:fixture.test:")) + .count() + > before_rebind_authorizations, + "the rebound request did not reach host authorization: {calls:?}" + ); + assert!( + calls + .iter() + .any(|call| call == &format!("resolve:fixture.test:{port}:{rebound_address}")), + "the controlled resolver did not return the rebound address: {calls:?}" + ); + assert!( + !calls + .iter() + .any(|call| call == &format!("consume:{rebound_address}")), + "the rebound socket was consumed: {calls:?}" + ); + drop(calls); + + let closed: DesktopResponse = browser + .proxy + .call( + browser_names::methods::CLOSE_SESSION, + (serde_json::json!({"session": browser.session}),), + ) + .await?; + assert!( + closed.ok, + "browser session did not close: {:?}", + closed.error + ); + browser.broker_task.abort(); + let _ = browser.broker_task.await; + server.abort(); + let _ = server.await; + Ok(()) +} diff --git a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/mod.rs b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/mod.rs index 683c8db77..f362aaf01 100644 --- a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/mod.rs +++ b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/mod.rs @@ -2,6 +2,7 @@ #![allow(clippy::expect_used, clippy::panic, clippy::unwrap_used)] mod authority_denial_tests; +mod dns_rebinding_tests; #[cfg(feature = "test-connector")] mod public_connector_tests; mod transport_classes_tests; @@ -28,6 +29,7 @@ use tinycomputer_bus::{ struct EgressHost { allowed: Arc, allowed_addresses: Vec, + resolved_address: Option>>, grant_generation: Option, authorize_delay: Duration, observations: Arc>>, @@ -36,22 +38,35 @@ struct EgressHost { #[tinybus::interface(name = "ai.tinyhumans.tinycomputer.BrowserEgressHost")] impl EgressHost { async fn authorize(&self, request: BrowserEgressTarget) -> tinybus::Result { - self.observations.lock().unwrap().push(format!( - "authorize:{}:{}:{}:{}", - request.policy_id, request.expected_generation, request.hostname, request.port - )); tokio::time::sleep(self.authorize_delay).await; tokio::task::yield_now().await; + let resolved_address = self + .resolved_address + .as_ref() + .map(|resolved| resolved.lock().unwrap().clone()); let allowed_address = self.allowed_addresses.iter().find(|address| { - address - .rsplit(':') - .next() - .and_then(|port| port.parse::().ok()) - == Some(request.port) + resolved_address + .as_ref() + .map_or(true, |resolved| *address == resolved) + && address + .rsplit(':') + .next() + .and_then(|port| port.parse::().ok()) + == Some(request.port) }); let allow = self.allowed.load(Ordering::SeqCst) && request.hostname == "fixture.test" && allowed_address.is_some(); + self.observations.lock().unwrap().push(format!( + "authorize:{}:{}:{}:{}", + request.policy_id, request.expected_generation, request.hostname, request.port + )); + if let Some(resolved_address) = resolved_address { + self.observations.lock().unwrap().push(format!( + "resolve:{}:{}:{}", + request.hostname, request.port, resolved_address + )); + } Ok(BrowserEgressGrant { generation: self.grant_generation.unwrap_or(request.expected_generation), authorization: if allow { @@ -204,6 +219,53 @@ async fn start_browser_with_fixture_hosts_for_policy( generation: u64, shared_observations: Option>>>, test_connector_map: Option<(String, String)>, +) -> tinybus::Result { + start_browser_with_fixture_hosts_for_policy_and_resolution( + allowed_addresses, + page_port, + page_path, + served, + policy_id, + generation, + shared_observations, + test_connector_map, + None, + ) + .await +} + +async fn start_browser_with_fixture_hosts_and_resolution( + allowed_addresses: Vec, + page_port: u16, + page_path: &str, + served: tokio::sync::oneshot::Receiver<()>, + resolved_address: Option>>, +) -> tinybus::Result { + start_browser_with_fixture_hosts_for_policy_and_resolution( + allowed_addresses, + page_port, + page_path, + served, + "fixture-policy", + 41, + None, + None, + resolved_address, + ) + .await +} + +#[allow(clippy::too_many_arguments)] +async fn start_browser_with_fixture_hosts_for_policy_and_resolution( + allowed_addresses: Vec, + page_port: u16, + page_path: &str, + served: tokio::sync::oneshot::Receiver<()>, + policy_id: &str, + generation: u64, + shared_observations: Option>>>, + test_connector_map: Option<(String, String)>, + resolved_address: Option>>, ) -> tinybus::Result { let bus = MemoryBus::new(); let broker = Broker::new(); @@ -217,6 +279,7 @@ async fn start_browser_with_fixture_hosts_for_policy( EgressHost { allowed: allowed.clone(), allowed_addresses, + resolved_address, grant_generation: None, authorize_delay: Duration::ZERO, observations: observations.clone(), From a43cf6878b2bd7256c730fe8664d47ffe1214651 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Fri, 23 Oct 2026 10:15:47 +0000 Subject: [PATCH 2/6] test(browser_egress): record authorize observation before delay Move the authorize observation push ahead of the simulated delay so the recorded order reflects when the request arrived rather than when the handler finished. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../src/tinybus_module/browser_egress_live_tests/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/mod.rs b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/mod.rs index f362aaf01..2ae8b2d59 100644 --- a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/mod.rs +++ b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/mod.rs @@ -38,6 +38,10 @@ struct EgressHost { #[tinybus::interface(name = "ai.tinyhumans.tinycomputer.BrowserEgressHost")] impl EgressHost { async fn authorize(&self, request: BrowserEgressTarget) -> tinybus::Result { + self.observations.lock().unwrap().push(format!( + "authorize:{}:{}:{}:{}", + request.policy_id, request.expected_generation, request.hostname, request.port + )); tokio::time::sleep(self.authorize_delay).await; tokio::task::yield_now().await; let resolved_address = self @@ -57,10 +61,6 @@ impl EgressHost { let allow = self.allowed.load(Ordering::SeqCst) && request.hostname == "fixture.test" && allowed_address.is_some(); - self.observations.lock().unwrap().push(format!( - "authorize:{}:{}:{}:{}", - request.policy_id, request.expected_generation, request.hostname, request.port - )); if let Some(resolved_address) = resolved_address { self.observations.lock().unwrap().push(format!( "resolve:{}:{}:{}", From 3bc95dbc7d35452267e1c2ae197c573a599581f0 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Fri, 23 Oct 2026 10:16:16 +0000 Subject: [PATCH 3/6] test(browser): use to_string for static worker fixture html Replace the unnecessary format! call with a plain string literal converted via to_string, since the html contains no interpolation. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../tinycomputer-browser/src/linked/linked_tests/live_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/tinycomputer-browser/src/linked/linked_tests/live_tests.rs b/crates/tinycomputer-browser/src/linked/linked_tests/live_tests.rs index 64c80f5f8..ad19de006 100644 --- a/crates/tinycomputer-browser/src/linked/linked_tests/live_tests.rs +++ b/crates/tinycomputer-browser/src/linked/linked_tests/live_tests.rs @@ -242,7 +242,7 @@ async fn live_chromium_worker_fetch_never_reaches_a_denied_destination() { let denied_targets = Arc::new(Mutex::new(Vec::new())); let fixture = TcpListener::bind("127.0.0.1:0").await.unwrap(); let address = fixture.local_addr().unwrap(); - let html = format!("

worker fixture

"); + let html = "

worker fixture

".to_string(); let worker = format!( "fetch('http://127.0.0.1:{}/private').catch(() => {{}});", denied_address.port() From e15a3ceaa5e87c0a6da722ba473a21aca6f50a01 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Fri, 23 Oct 2026 10:16:54 +0000 Subject: [PATCH 4/6] test(browser_egress): satisfy clippy lints in live egress tests Clone the observations snapshot instead of holding the mutex guard across the remaining assertions, replace a map_or with is_none_or, and allow the too_many_arguments lint on the fixture host helper. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../browser_egress_live_tests/dns_rebinding_tests.rs | 4 +--- .../src/tinybus_module/browser_egress_live_tests/mod.rs | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/dns_rebinding_tests.rs b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/dns_rebinding_tests.rs index c6910e743..7828bae61 100644 --- a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/dns_rebinding_tests.rs +++ b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/dns_rebinding_tests.rs @@ -68,7 +68,7 @@ async fn live_chromium_module_never_dials_a_rebound_private_socket() -> tinybus: "the request reached the previously allowed socket after rebinding" ); - let calls = browser.observations.lock().unwrap(); + let calls = browser.observations.lock().unwrap().clone(); assert!( calls .iter() @@ -89,8 +89,6 @@ async fn live_chromium_module_never_dials_a_rebound_private_socket() -> tinybus: .any(|call| call == &format!("consume:{rebound_address}")), "the rebound socket was consumed: {calls:?}" ); - drop(calls); - let closed: DesktopResponse = browser .proxy .call( diff --git a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/mod.rs b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/mod.rs index 2ae8b2d59..bb9ea3400 100644 --- a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/mod.rs +++ b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/mod.rs @@ -51,7 +51,7 @@ impl EgressHost { let allowed_address = self.allowed_addresses.iter().find(|address| { resolved_address .as_ref() - .map_or(true, |resolved| *address == resolved) + .is_none_or(|resolved| *address == resolved) && address .rsplit(':') .next() @@ -210,6 +210,7 @@ async fn start_browser_with_fixture_hosts( .await } +#[allow(clippy::too_many_arguments)] async fn start_browser_with_fixture_hosts_for_policy( allowed_addresses: Vec, page_port: u16, From fdbd7186f4dba7faab634f4eddc6e29878dd57aa Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Fri, 23 Oct 2026 10:18:26 +0000 Subject: [PATCH 5/6] test(browser_egress): assert the allowed socket is consumed before rebinding The DNS rebinding test now snapshots the recorded calls before the rebind and asserts that the initially allowed address was consumed, so a failure to dial the permitted socket is caught rather than silently passing the later denial checks. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../browser_egress_live_tests/dns_rebinding_tests.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/dns_rebinding_tests.rs b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/dns_rebinding_tests.rs index 7828bae61..a74fa2c02 100644 --- a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/dns_rebinding_tests.rs +++ b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/dns_rebinding_tests.rs @@ -30,13 +30,17 @@ async fn live_chromium_module_never_dials_a_rebound_private_socket() -> tinybus: ) .await?; - let before_rebind_authorizations = browser - .observations - .lock() - .unwrap() + let calls_before_rebind = browser.observations.lock().unwrap().clone(); + let before_rebind_authorizations = calls_before_rebind .iter() .filter(|call| call.starts_with("authorize:fixture-policy:41:fixture.test:")) .count(); + assert!( + calls_before_rebind + .iter() + .any(|call| call == &format!("consume:{allowed_address}")), + "the initial allowed socket was not consumed: {calls_before_rebind:?}" + ); let connections_before_rebind = extra_connections.load(Ordering::SeqCst); *resolved_address.lock().unwrap() = rebound_address.clone(); let denied: DesktopResponse = browser From 4a4112d472c58f4f8c50ba5703344a48425ac30e Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Fri, 23 Oct 2026 10:18:45 +0000 Subject: [PATCH 6/6] test(browser_egress): allow long dns rebinding test Silence the clippy too_many_lines lint on the live DNS rebinding test, which is long by necessity because it sets up both loopback endpoints and the resolver fixture inline. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../browser_egress_live_tests/dns_rebinding_tests.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/dns_rebinding_tests.rs b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/dns_rebinding_tests.rs index a74fa2c02..762517c63 100644 --- a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/dns_rebinding_tests.rs +++ b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/dns_rebinding_tests.rs @@ -3,6 +3,7 @@ use super::*; #[tokio::test] +#[allow(clippy::too_many_lines)] async fn live_chromium_module_never_dials_a_rebound_private_socket() -> tinybus::Result<()> { // Keep both endpoints on assigned loopback addresses and the same port; // the resolver fixture changes only the address returned for fixture.test.