From f2157ccbbce201202fc55b73e89f9b1559251159 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Fri, 23 Oct 2026 08:42:05 +0000 Subject: [PATCH 01/15] test: add live browser egress test run to feature script The feature test script now runs the browser egress live tests with the egress environment flag enabled, matching the existing live browser test invocation so that this suite is exercised alongside the others. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- scripts/test-features.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/test-features.sh b/scripts/test-features.sh index a7b75f57b..5debf3af1 100755 --- a/scripts/test-features.sh +++ b/scripts/test-features.sh @@ -14,6 +14,7 @@ esac cargo test --locked --workspace cargo test --locked --workspace --all-features RUST_TEST_THREADS=1 TINYCOMPUTER_LIVE_BROWSER_TESTS=1 cargo test --locked -p tinycomputer-browser --features agent-browser live_ +RUST_TEST_THREADS=1 TINYCOMPUTER_LIVE_BROWSER_EGRESS_TESTS=1 cargo test --locked -p tinycomputer --features static-link tinybus_module::browser_egress_live_tests -- --nocapture cargo test --locked -p tinycomputer --features static-link cargo run --locked -p tinycomputer-examples --bin basic forbidden="$(cargo tree -p tinycomputer-bus -e normal,build --prefix none | grep -Ei 'tinybus|tokio|reqwest|ureq|hyper|rusqlite|git2|agent-desktop' || true)" From c1467dcf37ed36f4157ac74b52e3a9565ad03966 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Fri, 23 Oct 2026 08:53:37 +0000 Subject: [PATCH 02/15] test(browser): clone observed addresses before asserting Clone the locked address list before the assertion so the mutex guard is released prior to the comparison, avoiding a held lock across the assert. 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 1ed161728..d32e5ca78 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), From 7c8001803133d53c95f4b5b87450e9260fba4ec9 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Fri, 23 Oct 2026 08:53:49 +0000 Subject: [PATCH 03/15] test(browser): use to_string for static worker fixture html Replace the unnecessary format! call with a to_string conversion on the static HTML string in the live worker fetch test, since the literal 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 d32e5ca78..f88a3381a 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 c38ef880efa16e438c8e14e502837bc613d1eeca Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Fri, 23 Oct 2026 11:56:10 +0000 Subject: [PATCH 04/15] test(browser): bind denied listeners on distinct ephemeral ports The live egress tests previously bound the denied listener to a second loopback address on the same port as the allowed listener, which is not portable across environments. Each denied listener now binds to its own ephemeral port and the tests assert the ports differ, so the fixtures exercise host-based denial rather than address-based separation. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../src/linked/linked_tests/live_tests.rs | 8 +++++--- .../browser_egress_live_tests/dns_rebinding_tests.rs | 3 ++- .../src/tinybus_module/browser_egress_live_tests/mod.rs | 6 ++++-- .../tinybus_module/browser_egress_live_tests/worker.rs | 7 ++++--- 4 files changed, 15 insertions(+), 9 deletions(-) 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 f88a3381a..21a89cd64 100644 --- a/crates/tinycomputer-browser/src/linked/linked_tests/live_tests.rs +++ b/crates/tinycomputer-browser/src/linked/linked_tests/live_tests.rs @@ -69,10 +69,12 @@ async fn live_chromium_loopback_navigation_uses_the_authenticated_session_proxy( #[tokio::test] #[cfg(live_browser_tests)] async fn live_chromium_dials_only_the_exact_host_authorized_socket() { - let allowed = TcpListener::bind("127.0.0.2:0").await.unwrap(); + let allowed = TcpListener::bind("127.0.0.1:0").await.unwrap(); let allowed_address = allowed.local_addr().unwrap(); - let denied = std::net::TcpListener::bind(("127.0.0.1", allowed_address.port())).unwrap(); + let denied = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); denied.set_nonblocking(true).unwrap(); + let denied_address = denied.local_addr().unwrap(); + assert_ne!(allowed_address.port(), denied_address.port()); let allowed_server = tokio::spawn(async move { let (mut socket, _) = allowed.accept().await.unwrap(); @@ -95,7 +97,7 @@ async fn live_chromium_dials_only_the_exact_host_authorized_socket() { .execute(json!({ "id":"navigate", "action":"navigate", - "url":format!("http://127.0.0.1:{}/", allowed_address.port()) + "url":format!("http://127.0.0.1:{}/", denied_address.port()) })) .await; browser 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 54a608de4..e0d0d4161 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 @@ -6,9 +6,10 @@ use super::*; async fn live_chromium_module_never_dials_a_rebound_private_socket() -> tinybus::Result<()> { let allowed_listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?; let port = allowed_listener.local_addr()?.port(); - let rebound_listener = tokio::net::TcpListener::bind(("127.0.0.2", port)).await?; + let rebound_listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?; let allowed_address = allowed_listener.local_addr()?.to_string(); let rebound_address = rebound_listener.local_addr()?.to_string(); + assert_ne!(port, rebound_listener.local_addr()?.port()); let extra_connections = Arc::new(AtomicUsize::new(0)); let (served_tx, served_rx) = tokio::sync::oneshot::channel(); let server = tokio::spawn(serve_fixture( 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 90923124b..24b53f986 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 @@ -275,7 +275,9 @@ async fn live_chromium_module_dials_only_the_host_returned_socket_and_rejects_ch -> tinybus::Result<()> { let allowed_listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?; let port = allowed_listener.local_addr()?.port(); - let denied_listener = tokio::net::TcpListener::bind(("127.0.0.2", port)).await?; + let denied_listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?; + let denied_port = denied_listener.local_addr()?.port(); + assert_ne!(port, denied_port); let allowed_address = allowed_listener.local_addr()?.to_string(); let extra_allowed_connections = Arc::new(AtomicUsize::new(0)); let (served_tx, served_rx) = tokio::sync::oneshot::channel(); @@ -303,7 +305,7 @@ async fn live_chromium_module_dials_only_the_host_returned_socket_and_rejects_ch // Simulate a policy refresh: the host changes from granting the fixture // socket to denying requests for the same hostname. browser.allowed.store(false, Ordering::SeqCst); - let denied_url = format!("http://fixture.test:{port}/after-policy-change"); + let denied_url = format!("http://fixture.test:{denied_port}/after-policy-change"); let denied: DesktopResponse = browser .proxy .call( diff --git a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/worker.rs b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/worker.rs index 4d77c63e1..ddd1bcee0 100644 --- a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/worker.rs +++ b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/worker.rs @@ -5,12 +5,13 @@ async fn live_chromium_module_routes_worker_egress_through_host_authorization() -> tinybus::Result<()> { let allowed_listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?; let page_port = allowed_listener.local_addr()?.port(); - let denied_listener = tokio::net::TcpListener::bind("127.0.0.2:0").await?; + let denied_listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?; let denied_port = denied_listener.local_addr()?.port(); + assert_ne!(page_port, denied_port); let html = format!( "" ) .into_bytes(); @@ -30,7 +31,7 @@ async fn live_chromium_module_routes_worker_egress_through_host_authorization() start_browser_with_fixture_host(allowed_address, page_port, "/worker-fixture", served_rx) .await?; - let worker_authorization = format!("authorize:fixture-policy:41:127.0.0.2:{denied_port}"); + let worker_authorization = format!("authorize:fixture-policy:41:127.0.0.1:{denied_port}"); let worker_authorized = tokio::time::timeout(Duration::from_secs(10), async { loop { if browser From f94c53926d12c965f12f594374f75dde5c82aa21 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Fri, 23 Oct 2026 11:57:06 +0000 Subject: [PATCH 05/15] test(browser): authorize denied host in live egress tests The live egress tests now pass the denied listener's full socket address to the browser fixture host instead of only its port, so the denied host is explicitly authorized and the tests exercise the intended rejection path. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../src/linked/linked_tests/live_tests.rs | 2 +- .../tinybus_module/browser_egress_live_tests/mod.rs | 13 +++++++++---- .../browser_egress_live_tests/worker.rs | 7 ++++--- 3 files changed, 14 insertions(+), 8 deletions(-) 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 21a89cd64..86ab91afe 100644 --- a/crates/tinycomputer-browser/src/linked/linked_tests/live_tests.rs +++ b/crates/tinycomputer-browser/src/linked/linked_tests/live_tests.rs @@ -97,7 +97,7 @@ async fn live_chromium_dials_only_the_exact_host_authorized_socket() { .execute(json!({ "id":"navigate", "action":"navigate", - "url":format!("http://127.0.0.1:{}/", denied_address.port()) + "url":format!("http://{denied_address}/") })) .await; browser 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 24b53f986..9025ed2e9 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 @@ -276,7 +276,8 @@ async fn live_chromium_module_dials_only_the_host_returned_socket_and_rejects_ch let allowed_listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?; let port = allowed_listener.local_addr()?.port(); let denied_listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?; - let denied_port = denied_listener.local_addr()?.port(); + let denied_address = denied_listener.local_addr()?; + let denied_port = denied_address.port(); assert_ne!(port, denied_port); let allowed_address = allowed_listener.local_addr()?.to_string(); let extra_allowed_connections = Arc::new(AtomicUsize::new(0)); @@ -290,9 +291,13 @@ async fn live_chromium_module_dials_only_the_host_returned_socket_and_rejects_ch None, )); - let browser = - start_browser_with_fixture_host(allowed_address.clone(), port, "/allowed", served_rx) - .await?; + let browser = start_browser_with_fixture_hosts( + vec![allowed_address.clone(), denied_address.to_string()], + port, + "/allowed", + served_rx, + ) + .await?; let authorizations_before_policy_change = browser .observations diff --git a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/worker.rs b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/worker.rs index ddd1bcee0..5200a1a1d 100644 --- a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/worker.rs +++ b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/worker.rs @@ -6,12 +6,13 @@ async fn live_chromium_module_routes_worker_egress_through_host_authorization() let allowed_listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?; let page_port = allowed_listener.local_addr()?.port(); let denied_listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?; - let denied_port = denied_listener.local_addr()?.port(); + let denied_address = denied_listener.local_addr()?; + let denied_port = denied_address.port(); assert_ne!(page_port, denied_port); let html = format!( "" ) .into_bytes(); @@ -31,7 +32,7 @@ async fn live_chromium_module_routes_worker_egress_through_host_authorization() start_browser_with_fixture_host(allowed_address, page_port, "/worker-fixture", served_rx) .await?; - let worker_authorization = format!("authorize:fixture-policy:41:127.0.0.1:{denied_port}"); + let worker_authorization = format!("authorize:fixture-policy:41:{denied_address}"); let worker_authorized = tokio::time::timeout(Duration::from_secs(10), async { loop { if browser From ce5b656bac1cce10d4cc786c8e770c4b779b0714 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Fri, 23 Oct 2026 12:01:55 +0000 Subject: [PATCH 06/15] test(browser_egress): clone observations to release the lock earlier The DNS rebinding test now clones the observation list instead of holding the mutex guard across the assertions, so the lock is released before the proxy call that follows. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../browser_egress_live_tests/dns_rebinding_tests.rs | 4 +--- 1 file changed, 1 insertion(+), 3 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 e0d0d4161..8f3536558 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 @@ -67,7 +67,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() @@ -88,8 +88,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( From 9e0d7fbe7da49f4e593d984bcec2d9968363c981 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Fri, 23 Oct 2026 12:07:37 +0000 Subject: [PATCH 07/15] test(browser): split live egress tests into focused modules The monolithic live_tests.rs file was replaced by a live_tests directory containing separate modules for navigation, denied requests, and DNS rebinding scenarios. This keeps each live Chromium egress test group readable and makes it easier to extend coverage without growing a single oversized file. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../src/linked/linked_tests/live_tests.rs | 759 ------------------ .../live_tests/denied_requests_tests.rs | 247 ++++++ .../live_tests/dns_rebinding_tests.rs | 91 +++ .../src/linked/linked_tests/live_tests/mod.rs | 270 +++++++ .../live_tests/navigation_tests.rs | 158 ++++ 5 files changed, 766 insertions(+), 759 deletions(-) delete mode 100644 crates/tinycomputer-browser/src/linked/linked_tests/live_tests.rs create mode 100644 crates/tinycomputer-browser/src/linked/linked_tests/live_tests/denied_requests_tests.rs create mode 100644 crates/tinycomputer-browser/src/linked/linked_tests/live_tests/dns_rebinding_tests.rs create mode 100644 crates/tinycomputer-browser/src/linked/linked_tests/live_tests/mod.rs create mode 100644 crates/tinycomputer-browser/src/linked/linked_tests/live_tests/navigation_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 deleted file mode 100644 index 86ab91afe..000000000 --- a/crates/tinycomputer-browser/src/linked/linked_tests/live_tests.rs +++ /dev/null @@ -1,759 +0,0 @@ -//! Live Chromium egress tests that use local HTTP and WebSocket fixtures. -#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] - -use super::EnforcedAgentBrowser; -use crate::engine::Launcher; -use crate::{BrowserDialTarget, DialGrant, EgressAuthorizer}; -use serde_json::json; -use std::{ - collections::HashMap, - io, - net::SocketAddr, - sync::{ - Arc, Mutex, - atomic::{AtomicUsize, Ordering}, - }, - time::Duration, -}; -use tokio::{ - io::{AsyncReadExt, AsyncWriteExt}, - net::TcpListener, -}; - -#[tokio::test] -#[cfg(live_browser_tests)] -async fn live_chromium_loopback_navigation_uses_the_authenticated_session_proxy() { - let fixture = TcpListener::bind("127.0.0.1:0").await.unwrap(); - let address = fixture.local_addr().unwrap(); - let server = tokio::spawn(async move { - let (mut socket, _) = fixture.accept().await.unwrap(); - let mut request = [0; 4096]; - let _ = socket.read(&mut request).await.unwrap(); - socket - .write_all( - b"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: 22\r\nConnection: close\r\n\r\n

proxy fixture

", - ) - .await - .unwrap(); - }); - let authorizations = Arc::new(AtomicUsize::new(0)); - let mut browser = EnforcedAgentBrowser::new(Arc::new(RejectAllButFixture { - address, - authorizations: authorizations.clone(), - denied_targets: Arc::new(Mutex::new(Vec::new())), - })) - .open("live-egress"); - let launch = browser - .execute(json!({"id":"launch","action":"launch","headless":true,"args":[]})) - .await; - assert_eq!(launch["success"], true, "{launch}"); - let navigation = browser - .execute(json!({ - "id":"navigate", - "action":"navigate", - "url":format!("http://127.0.0.1:{}/", address.port()) - })) - .await; - browser - .execute(json!({"id":"close","action":"close"})) - .await; - assert_eq!( - navigation["success"], - true, - "{navigation}; proxy authorizations: {}", - authorizations.load(Ordering::SeqCst) - ); - server.await.unwrap(); -} - -#[tokio::test] -#[cfg(live_browser_tests)] -async fn live_chromium_dials_only_the_exact_host_authorized_socket() { - let allowed = TcpListener::bind("127.0.0.1:0").await.unwrap(); - let allowed_address = allowed.local_addr().unwrap(); - let denied = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); - denied.set_nonblocking(true).unwrap(); - let denied_address = denied.local_addr().unwrap(); - assert_ne!(allowed_address.port(), denied_address.port()); - - let allowed_server = tokio::spawn(async move { - let (mut socket, _) = allowed.accept().await.unwrap(); - let mut request = [0; 4096]; - let _ = socket.read(&mut request).await.unwrap(); - socket - .write_all( - b"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: 30\r\nConnection: close\r\n\r\n

pinned socket fixture

", - ) - .await - .unwrap(); - }); - let mut browser = EnforcedAgentBrowser::new(Arc::new(AuthorizeExactSocket(allowed_address))) - .open("live-egress-socket-pinning"); - let launch = browser - .execute(json!({"id":"launch","action":"launch","headless":true,"args":[]})) - .await; - assert_eq!(launch["success"], true, "{launch}"); - let navigation = browser - .execute(json!({ - "id":"navigate", - "action":"navigate", - "url":format!("http://{denied_address}/") - })) - .await; - browser - .execute(json!({"id":"close","action":"close"})) - .await; - - assert_eq!(navigation["success"], true, "{navigation}"); - allowed_server.await.unwrap(); - assert_eq!( - denied.accept().unwrap_err().kind(), - io::ErrorKind::WouldBlock, - "Chromium must reach only the exact socket returned by the host grant" - ); -} - -#[tokio::test] -#[cfg(live_browser_tests)] -async fn live_chromium_subresource_never_reaches_a_denied_destination() { - let denied = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); - denied.set_nonblocking(true).unwrap(); - let denied_address = denied.local_addr().unwrap(); - 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 body = format!( - "", - denied_address.port() - ); - let fixture_server = tokio::spawn(async move { - let (mut socket, _) = fixture.accept().await.unwrap(); - let mut request = [0; 4096]; - let _ = socket.read(&mut request).await.unwrap(); - socket - .write_all( - format!( - "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{}", - body.len(), body - ) - .as_bytes(), - ) - .await - .unwrap(); - }); - let mut browser = EnforcedAgentBrowser::new(Arc::new(RejectAllButFixture { - address, - authorizations: Arc::new(AtomicUsize::new(0)), - denied_targets: denied_targets.clone(), - })) - .open("live-egress-subresource"); - let launch = browser - .execute(json!({"id":"launch","action":"launch","headless":true,"args":[]})) - .await; - assert_eq!(launch["success"], true, "{launch}"); - let navigation = browser - .execute(json!({ - "id":"navigate", - "action":"navigate", - "url":format!("http://127.0.0.1:{}/", address.port()) - })) - .await; - wait_for_denied_target(&denied_targets, denied_address.port()).await; - browser - .execute(json!({"id":"close","action":"close"})) - .await; - assert_eq!(navigation["success"], true, "{navigation}"); - fixture_server.await.unwrap(); - assert_eq!( - denied.accept().unwrap_err().kind(), - io::ErrorKind::WouldBlock, - "the denied subresource destination must never receive a connection" - ); -} - -#[tokio::test] -#[cfg(live_browser_tests)] -async fn live_chromium_uses_a_host_permitted_cross_origin_subresource_socket() { - let cdn_fixture = TcpListener::bind("127.0.0.1:0").await.unwrap(); - let cdn_address = cdn_fixture.local_addr().unwrap(); - let page_fixture = TcpListener::bind("127.0.0.1:0").await.unwrap(); - let page_address = page_fixture.local_addr().unwrap(); - let html = format!( - "

page fixture

", - cdn_address.port() - ); - let page_server = tokio::spawn(async move { - let (mut socket, _) = tokio::time::timeout(Duration::from_secs(10), page_fixture.accept()) - .await - .expect("Chromium requests the permitted page") - .unwrap(); - let mut request = [0; 4096]; - let _ = socket.read(&mut request).await.unwrap(); - let response = format!( - "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{html}", - html.len() - ); - socket.write_all(response.as_bytes()).await.unwrap(); - }); - let cdn_server = tokio::spawn(async move { - let (mut socket, _) = tokio::time::timeout(Duration::from_secs(10), cdn_fixture.accept()) - .await - .expect("Chromium requests the permitted cross-origin asset") - .unwrap(); - let mut request = [0; 4096]; - let _ = socket.read(&mut request).await.unwrap(); - socket - .write_all(b"HTTP/1.1 200 OK\r\nContent-Type: image/png\r\nContent-Length: 0\r\nConnection: close\r\n\r\n") - .await - .unwrap(); - }); - let addresses = HashMap::from([ - ("127.0.0.1".to_owned(), page_address), - ("cdn.fixture.test".to_owned(), cdn_address), - ]); - let mut browser = EnforcedAgentBrowser::new(Arc::new(AllowFixtureHosts { - addresses, - authorizations: Arc::new(AtomicUsize::new(0)), - })) - .open("live-egress-permitted-cross-origin"); - let launch = browser - .execute(json!({"id":"launch","action":"launch","headless":true,"args":[]})) - .await; - assert_eq!(launch["success"], true, "{launch}"); - let navigation = browser - .execute(json!({ - "id":"navigate", - "action":"navigate", - "url":format!("http://127.0.0.1:{}/", page_address.port()) - })) - .await; - browser - .execute(json!({"id":"close","action":"close"})) - .await; - assert_eq!(navigation["success"], true, "{navigation}"); - page_server.await.unwrap(); - cdn_server.await.unwrap(); -} - -#[tokio::test] -#[cfg(live_browser_tests)] -async fn live_chromium_worker_fetch_never_reaches_a_denied_destination() { - let denied = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); - denied.set_nonblocking(true).unwrap(); - let denied_address = denied.local_addr().unwrap(); - 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 = "

worker fixture

".to_string(); - let worker = format!( - "fetch('http://127.0.0.1:{}/private').catch(() => {{}});", - denied_address.port() - ); - let fixture_server = tokio::spawn(async move { - loop { - let (mut socket, _) = tokio::time::timeout(Duration::from_secs(10), fixture.accept()) - .await - .expect("Chromium requests the page and worker script") - .unwrap(); - let mut request = [0; 4096]; - let size = socket.read(&mut request).await.unwrap(); - let request = String::from_utf8_lossy(&request[..size]); - let (status, content_type, body, worker_script) = if request.contains("GET /worker.js") - { - ("200 OK", "application/javascript", worker.as_str(), true) - } else if request.contains("GET / ") { - ("200 OK", "text/html", html.as_str(), false) - } else { - ("404 Not Found", "text/plain", "not found", false) - }; - socket - .write_all( - format!( - "HTTP/1.1 {status}\r\nContent-Type: {content_type}\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}", - body.len() - ) - .as_bytes(), - ) - .await - .unwrap(); - if worker_script { - break; - } - } - }); - let mut browser = EnforcedAgentBrowser::new(Arc::new(RejectAllButFixture { - address, - authorizations: Arc::new(AtomicUsize::new(0)), - denied_targets: denied_targets.clone(), - })) - .open("live-egress-worker"); - let launch = browser - .execute(json!({"id":"launch","action":"launch","headless":true,"args":[]})) - .await; - assert_eq!(launch["success"], true, "{launch}"); - let navigation = browser - .execute(json!({ - "id":"navigate", - "action":"navigate", - "url":format!("http://127.0.0.1:{}/", address.port()) - })) - .await; - wait_for_denied_target(&denied_targets, denied_address.port()).await; - browser - .execute(json!({"id":"close","action":"close"})) - .await; - assert_eq!(navigation["success"], true, "{navigation}"); - fixture_server.await.unwrap(); - assert_eq!( - denied.accept().unwrap_err().kind(), - io::ErrorKind::WouldBlock, - "the denied worker fetch destination must never receive a connection" - ); -} - -#[tokio::test] -#[cfg(live_browser_tests)] -async fn live_chromium_dns_rebinding_never_reaches_the_rebound_private_socket() { - let allowed_listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); - let port = allowed_listener.local_addr().unwrap().port(); - let private = std::net::TcpListener::bind((std::net::Ipv6Addr::LOCALHOST, port)).unwrap(); - private.set_nonblocking(true).unwrap(); - let private_address = private.local_addr().unwrap(); - let allowed_address = allowed_listener.local_addr().unwrap(); - let extra_allowed_connections = Arc::new(AtomicUsize::new(0)); - let observed_addresses = Arc::new(Mutex::new(Vec::new())); - let extra_connections = extra_allowed_connections.clone(); - let body = format!("

fixture

"); - let allowed_server = tokio::spawn(async move { - let (mut socket, _) = - tokio::time::timeout(Duration::from_secs(10), allowed_listener.accept()) - .await - .expect("authorized navigation reaches the allowed fixture") - .unwrap(); - let mut request = [0; 4096]; - let _ = socket.read(&mut request).await.unwrap(); - let response = format!( - "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}", - body.len() - ); - socket.write_all(response.as_bytes()).await.unwrap(); - drop(socket); - - while let Ok((socket, _)) = allowed_listener.accept().await { - extra_connections.fetch_add(1, Ordering::SeqCst); - drop(socket); - } - }); - let denied_targets = Arc::new(Mutex::new(Vec::new())); - let mut browser = EnforcedAgentBrowser::new(Arc::new(RebindingAuthorizer { - allowed_address, - private_address, - authorizations: AtomicUsize::new(0), - denied_targets: denied_targets.clone(), - observed_addresses: observed_addresses.clone(), - })) - .open("live-egress-dns-rebinding"); - let launch = browser - .execute(json!({"id":"launch","action":"launch","headless":true,"args":[]})) - .await; - assert_eq!(launch["success"], true, "{launch}"); - let navigation = browser - .execute(json!({ - "id":"navigate", - "action":"navigate", - "url":format!("http://fixture.test:{port}/") - })) - .await; - wait_for_denied_target(&denied_targets, port).await; - browser - .execute(json!({"id":"close","action":"close"})) - .await; - assert_eq!(navigation["success"], true, "{navigation}"); - let observed_addresses = observed_addresses.lock().unwrap().clone(); - assert_eq!( - observed_addresses.first(), - Some(&allowed_address), - "the controlled resolver first returns the permitted address" - ); - assert!( - observed_addresses.len() >= 2 - && observed_addresses[1..] - .iter() - .all(|address| *address == private_address), - "the controlled resolver must rebind the name to the private address: {observed_addresses:?}" - ); - assert!( - tokio::time::timeout(Duration::from_millis(500), async { - while extra_allowed_connections.load(Ordering::SeqCst) == 0 { - tokio::task::yield_now().await; - } - }) - .await - .is_err(), - "the denied rebound request reached the previously allowed socket" - ); - assert_eq!( - private.accept().unwrap_err().kind(), - io::ErrorKind::WouldBlock, - "the rebound private destination must never receive a connection" - ); - allowed_server.abort(); - let _ = allowed_server.await; -} - -#[tokio::test] -#[cfg(live_browser_tests)] -async fn live_chromium_redirect_never_reaches_a_denied_destination() { - let denied = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); - denied.set_nonblocking(true).unwrap(); - let denied_address = denied.local_addr().unwrap(); - 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 fixture_server = tokio::spawn(async move { - let (mut socket, _) = fixture.accept().await.unwrap(); - let mut request = [0; 4096]; - let _ = socket.read(&mut request).await.unwrap(); - socket - .write_all( - format!( - "HTTP/1.1 302 Found\r\nLocation: http://127.0.0.1:{}/private\r\nContent-Length: 0\r\nConnection: close\r\n\r\n", - denied_address.port() - ) - .as_bytes(), - ) - .await - .unwrap(); - }); - let mut browser = EnforcedAgentBrowser::new(Arc::new(RejectAllButFixture { - address, - authorizations: Arc::new(AtomicUsize::new(0)), - denied_targets: denied_targets.clone(), - })) - .open("live-egress-redirect"); - let launch = browser - .execute(json!({"id":"launch","action":"launch","headless":true,"args":[]})) - .await; - assert_eq!(launch["success"], true, "{launch}"); - let navigation = browser - .execute(json!({ - "id":"navigate", - "action":"navigate", - "url":format!("http://127.0.0.1:{}/", address.port()) - })) - .await; - wait_for_denied_target(&denied_targets, denied_address.port()).await; - browser - .execute(json!({"id":"close","action":"close"})) - .await; - assert_eq!(navigation["success"], false, "{navigation}"); - fixture_server.await.unwrap(); - assert_eq!( - denied.accept().unwrap_err().kind(), - io::ErrorKind::WouldBlock, - "the denied redirect destination must never receive a connection" - ); -} - -#[tokio::test] -#[cfg(live_browser_tests)] -async fn live_chromium_websocket_never_reaches_a_denied_destination() { - let denied = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); - denied.set_nonblocking(true).unwrap(); - let denied_address = denied.local_addr().unwrap(); - 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 body = format!( - "", - denied_address.port() - ); - let fixture_server = tokio::spawn(async move { - let (mut socket, _) = fixture.accept().await.unwrap(); - let mut request = [0; 4096]; - let _ = socket.read(&mut request).await.unwrap(); - socket - .write_all( - format!( - "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{}", - body.len(), body - ) - .as_bytes(), - ) - .await - .unwrap(); - }); - let mut browser = EnforcedAgentBrowser::new(Arc::new(RejectAllButFixture { - address, - authorizations: Arc::new(AtomicUsize::new(0)), - denied_targets: denied_targets.clone(), - })) - .open("live-egress-websocket"); - let launch = browser - .execute(json!({"id":"launch","action":"launch","headless":true,"args":[]})) - .await; - assert_eq!(launch["success"], true, "{launch}"); - let navigation = browser - .execute(json!({ - "id":"navigate", - "action":"navigate", - "url":format!("http://127.0.0.1:{}/", address.port()) - })) - .await; - wait_for_denied_target(&denied_targets, denied_address.port()).await; - browser - .execute(json!({"id":"close","action":"close"})) - .await; - assert_eq!(navigation["success"], true, "{navigation}"); - fixture_server.await.unwrap(); - assert_eq!( - denied.accept().unwrap_err().kind(), - io::ErrorKind::WouldBlock, - "the denied WebSocket destination must never receive a connection" - ); -} - -#[cfg(live_browser_tests)] -#[derive(Debug)] -struct RejectAllButFixture { - address: SocketAddr, - authorizations: Arc, - denied_targets: Arc>>, -} - -#[cfg(live_browser_tests)] -#[derive(Debug)] -struct RebindingAuthorizer { - allowed_address: SocketAddr, - private_address: SocketAddr, - authorizations: AtomicUsize, - denied_targets: Arc>>, - observed_addresses: Arc>>, -} - -#[cfg(live_browser_tests)] -#[derive(Debug)] -struct AllowFixtureHosts { - addresses: HashMap, - authorizations: Arc, -} - -#[cfg(live_browser_tests)] -impl EgressAuthorizer for AllowFixtureHosts { - fn authorize( - &self, - target: BrowserDialTarget, - ) -> std::pin::Pin> + Send>> { - self.authorizations.fetch_add(1, Ordering::SeqCst); - let address = self - .addresses - .get(&target.hostname) - .copied() - .filter(|address| address.port() == target.port); - Box::pin(async move { - match address { - Some(address) => Ok(DialGrant { - lease: "live-cross-origin-fixture-lease".into(), - addresses: vec![address], - }), - None => Err(io::Error::new(io::ErrorKind::PermissionDenied, "denied")), - } - }) - } - - fn consume( - &self, - _: BrowserDialTarget, - grant: DialGrant, - address: SocketAddr, - ) -> std::pin::Pin> + Send>> { - Box::pin(async move { - if grant.addresses.contains(&address) { - Ok(()) - } else { - Err(io::Error::new(io::ErrorKind::PermissionDenied, "denied")) - } - }) - } - - fn validate( - &self, - _: String, - ) -> std::pin::Pin> + Send>> { - Box::pin(async { Ok(true) }) - } -} - -#[cfg(live_browser_tests)] -impl EgressAuthorizer for RebindingAuthorizer { - fn authorize( - &self, - target: BrowserDialTarget, - ) -> std::pin::Pin> + Send>> { - let attempt = self.authorizations.fetch_add(1, Ordering::SeqCst); - let resolved_address = if attempt == 0 { - self.allowed_address - } else { - self.private_address - }; - self.observed_addresses - .lock() - .unwrap() - .push(resolved_address); - let allowed = attempt == 0 - && target.hostname == "fixture.test" - && target.port == self.allowed_address.port(); - if !allowed { - self.denied_targets - .lock() - .unwrap() - .push((target.hostname, target.port)); - } - Box::pin(async move { - if allowed { - Ok(DialGrant { - lease: "live-dns-rebinding-lease".into(), - addresses: vec![resolved_address], - }) - } else { - Err(io::Error::new( - io::ErrorKind::PermissionDenied, - "rebound private address denied", - )) - } - }) - } - - fn consume( - &self, - _: BrowserDialTarget, - grant: DialGrant, - address: SocketAddr, - ) -> std::pin::Pin> + Send>> { - Box::pin(async move { - if grant.addresses.contains(&address) { - Ok(()) - } else { - Err(io::Error::new(io::ErrorKind::PermissionDenied, "denied")) - } - }) - } - - fn validate( - &self, - _: String, - ) -> std::pin::Pin> + Send>> { - Box::pin(async { Ok(true) }) - } -} - -#[cfg(live_browser_tests)] -#[derive(Debug)] -struct AuthorizeExactSocket(SocketAddr); - -#[cfg(live_browser_tests)] -impl EgressAuthorizer for AuthorizeExactSocket { - fn authorize( - &self, - _: BrowserDialTarget, - ) -> std::pin::Pin> + Send>> { - let address = self.0; - Box::pin(async move { - Ok(DialGrant { - lease: "live-pinned-socket-lease".into(), - addresses: vec![address], - }) - }) - } - - fn consume( - &self, - _: BrowserDialTarget, - grant: DialGrant, - address: SocketAddr, - ) -> std::pin::Pin> + Send>> { - Box::pin(async move { - if grant.addresses.contains(&address) { - Ok(()) - } else { - Err(io::Error::new(io::ErrorKind::PermissionDenied, "denied")) - } - }) - } - - fn validate( - &self, - _: String, - ) -> std::pin::Pin> + Send>> { - Box::pin(async { Ok(true) }) - } -} - -#[cfg(live_browser_tests)] -async fn wait_for_denied_target(denied_targets: &Arc>>, port: u16) { - tokio::time::timeout(Duration::from_secs(10), async { - loop { - let was_denied = denied_targets - .lock() - .unwrap() - .iter() - .any(|(_, denied_port)| *denied_port == port); - if was_denied { - break; - } - tokio::time::sleep(Duration::from_millis(10)).await; - } - }) - .await - .expect("Chromium should attempt the denied destination"); -} - -#[cfg(live_browser_tests)] -impl EgressAuthorizer for RejectAllButFixture { - fn authorize( - &self, - target: BrowserDialTarget, - ) -> std::pin::Pin> + Send>> { - let address = self.address; - self.authorizations.fetch_add(1, Ordering::SeqCst); - let allowed = target.hostname == "127.0.0.1" && target.port == address.port(); - if !allowed { - self.denied_targets - .lock() - .unwrap() - .push((target.hostname, target.port)); - } - Box::pin(async move { - if allowed { - Ok(DialGrant { - lease: "live-fixture-lease".into(), - addresses: vec![address], - }) - } else { - Err(io::Error::new(io::ErrorKind::PermissionDenied, "denied")) - } - }) - } - - fn consume( - &self, - _: BrowserDialTarget, - grant: DialGrant, - address: SocketAddr, - ) -> std::pin::Pin> + Send>> { - Box::pin(async move { - if grant.addresses.contains(&address) { - Ok(()) - } else { - Err(io::Error::new(io::ErrorKind::PermissionDenied, "denied")) - } - }) - } - - fn validate( - &self, - _: String, - ) -> std::pin::Pin> + Send>> { - Box::pin(async { Ok(true) }) - } -} diff --git a/crates/tinycomputer-browser/src/linked/linked_tests/live_tests/denied_requests_tests.rs b/crates/tinycomputer-browser/src/linked/linked_tests/live_tests/denied_requests_tests.rs new file mode 100644 index 000000000..3882f41b0 --- /dev/null +++ b/crates/tinycomputer-browser/src/linked/linked_tests/live_tests/denied_requests_tests.rs @@ -0,0 +1,247 @@ +use super::*; + +#[tokio::test] +#[cfg(live_browser_tests)] +async fn live_chromium_subresource_never_reaches_a_denied_destination() { + let denied = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); + denied.set_nonblocking(true).unwrap(); + let denied_address = denied.local_addr().unwrap(); + 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 body = format!( + "", + denied_address.port() + ); + let fixture_server = tokio::spawn(async move { + let (mut socket, _) = fixture.accept().await.unwrap(); + let mut request = [0; 4096]; + let _ = socket.read(&mut request).await.unwrap(); + socket + .write_all( + format!( + "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{}", + body.len(), body + ) + .as_bytes(), + ) + .await + .unwrap(); + }); + let mut browser = EnforcedAgentBrowser::new(Arc::new(RejectAllButFixture { + address, + authorizations: Arc::new(AtomicUsize::new(0)), + denied_targets: denied_targets.clone(), + })) + .open("live-egress-subresource"); + let launch = browser + .execute(json!({"id":"launch","action":"launch","headless":true,"args":[]})) + .await; + assert_eq!(launch["success"], true, "{launch}"); + let navigation = browser + .execute(json!({ + "id":"navigate", + "action":"navigate", + "url":format!("http://127.0.0.1:{}/", address.port()) + })) + .await; + wait_for_denied_target(&denied_targets, denied_address.port()).await; + browser + .execute(json!({"id":"close","action":"close"})) + .await; + assert_eq!(navigation["success"], true, "{navigation}"); + fixture_server.await.unwrap(); + assert_eq!( + denied.accept().unwrap_err().kind(), + io::ErrorKind::WouldBlock, + "the denied subresource destination must never receive a connection" + ); +} + +#[tokio::test] +#[cfg(live_browser_tests)] +async fn live_chromium_worker_fetch_never_reaches_a_denied_destination() { + let denied = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); + denied.set_nonblocking(true).unwrap(); + let denied_address = denied.local_addr().unwrap(); + 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 = "

worker fixture

".to_string(); + let worker = format!( + "fetch('http://127.0.0.1:{}/private').catch(() => {{}});", + denied_address.port() + ); + let fixture_server = tokio::spawn(async move { + loop { + let (mut socket, _) = tokio::time::timeout(Duration::from_secs(10), fixture.accept()) + .await + .expect("Chromium requests the page and worker script") + .unwrap(); + let mut request = [0; 4096]; + let size = socket.read(&mut request).await.unwrap(); + let request = String::from_utf8_lossy(&request[..size]); + let (status, content_type, body, worker_script) = if request.contains("GET /worker.js") + { + ("200 OK", "application/javascript", worker.as_str(), true) + } else if request.contains("GET / ") { + ("200 OK", "text/html", html.as_str(), false) + } else { + ("404 Not Found", "text/plain", "not found", false) + }; + socket + .write_all( + format!( + "HTTP/1.1 {status}\r\nContent-Type: {content_type}\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}", + body.len() + ) + .as_bytes(), + ) + .await + .unwrap(); + if worker_script { + break; + } + } + }); + let mut browser = EnforcedAgentBrowser::new(Arc::new(RejectAllButFixture { + address, + authorizations: Arc::new(AtomicUsize::new(0)), + denied_targets: denied_targets.clone(), + })) + .open("live-egress-worker"); + let launch = browser + .execute(json!({"id":"launch","action":"launch","headless":true,"args":[]})) + .await; + assert_eq!(launch["success"], true, "{launch}"); + let navigation = browser + .execute(json!({ + "id":"navigate", + "action":"navigate", + "url":format!("http://127.0.0.1:{}/", address.port()) + })) + .await; + wait_for_denied_target(&denied_targets, denied_address.port()).await; + browser + .execute(json!({"id":"close","action":"close"})) + .await; + assert_eq!(navigation["success"], true, "{navigation}"); + fixture_server.await.unwrap(); + assert_eq!( + denied.accept().unwrap_err().kind(), + io::ErrorKind::WouldBlock, + "the denied worker fetch destination must never receive a connection" + ); +} + +#[tokio::test] +#[cfg(live_browser_tests)] +async fn live_chromium_redirect_never_reaches_a_denied_destination() { + let denied = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); + denied.set_nonblocking(true).unwrap(); + let denied_address = denied.local_addr().unwrap(); + 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 fixture_server = tokio::spawn(async move { + let (mut socket, _) = fixture.accept().await.unwrap(); + let mut request = [0; 4096]; + let _ = socket.read(&mut request).await.unwrap(); + socket + .write_all( + format!( + "HTTP/1.1 302 Found\r\nLocation: http://127.0.0.1:{}/private\r\nContent-Length: 0\r\nConnection: close\r\n\r\n", + denied_address.port() + ) + .as_bytes(), + ) + .await + .unwrap(); + }); + let mut browser = EnforcedAgentBrowser::new(Arc::new(RejectAllButFixture { + address, + authorizations: Arc::new(AtomicUsize::new(0)), + denied_targets: denied_targets.clone(), + })) + .open("live-egress-redirect"); + let launch = browser + .execute(json!({"id":"launch","action":"launch","headless":true,"args":[]})) + .await; + assert_eq!(launch["success"], true, "{launch}"); + let navigation = browser + .execute(json!({ + "id":"navigate", + "action":"navigate", + "url":format!("http://127.0.0.1:{}/", address.port()) + })) + .await; + wait_for_denied_target(&denied_targets, denied_address.port()).await; + browser + .execute(json!({"id":"close","action":"close"})) + .await; + assert_eq!(navigation["success"], false, "{navigation}"); + fixture_server.await.unwrap(); + assert_eq!( + denied.accept().unwrap_err().kind(), + io::ErrorKind::WouldBlock, + "the denied redirect destination must never receive a connection" + ); +} + +#[tokio::test] +#[cfg(live_browser_tests)] +async fn live_chromium_websocket_never_reaches_a_denied_destination() { + let denied = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); + denied.set_nonblocking(true).unwrap(); + let denied_address = denied.local_addr().unwrap(); + 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 body = format!( + "", + denied_address.port() + ); + let fixture_server = tokio::spawn(async move { + let (mut socket, _) = fixture.accept().await.unwrap(); + let mut request = [0; 4096]; + let _ = socket.read(&mut request).await.unwrap(); + socket + .write_all( + format!( + "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{}", + body.len(), body + ) + .as_bytes(), + ) + .await + .unwrap(); + }); + let mut browser = EnforcedAgentBrowser::new(Arc::new(RejectAllButFixture { + address, + authorizations: Arc::new(AtomicUsize::new(0)), + denied_targets: denied_targets.clone(), + })) + .open("live-egress-websocket"); + let launch = browser + .execute(json!({"id":"launch","action":"launch","headless":true,"args":[]})) + .await; + assert_eq!(launch["success"], true, "{launch}"); + let navigation = browser + .execute(json!({ + "id":"navigate", + "action":"navigate", + "url":format!("http://127.0.0.1:{}/", address.port()) + })) + .await; + wait_for_denied_target(&denied_targets, denied_address.port()).await; + browser + .execute(json!({"id":"close","action":"close"})) + .await; + assert_eq!(navigation["success"], true, "{navigation}"); + fixture_server.await.unwrap(); + assert_eq!( + denied.accept().unwrap_err().kind(), + io::ErrorKind::WouldBlock, + "the denied WebSocket destination must never receive a connection" + ); +} diff --git a/crates/tinycomputer-browser/src/linked/linked_tests/live_tests/dns_rebinding_tests.rs b/crates/tinycomputer-browser/src/linked/linked_tests/live_tests/dns_rebinding_tests.rs new file mode 100644 index 000000000..557d7a0e4 --- /dev/null +++ b/crates/tinycomputer-browser/src/linked/linked_tests/live_tests/dns_rebinding_tests.rs @@ -0,0 +1,91 @@ +use super::*; + +#[tokio::test] +#[cfg(live_browser_tests)] +async fn live_chromium_dns_rebinding_never_reaches_the_rebound_private_socket() { + let allowed_listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); + let port = allowed_listener.local_addr().unwrap().port(); + let private = std::net::TcpListener::bind((std::net::Ipv6Addr::LOCALHOST, port)).unwrap(); + private.set_nonblocking(true).unwrap(); + let private_address = private.local_addr().unwrap(); + let allowed_address = allowed_listener.local_addr().unwrap(); + let extra_allowed_connections = Arc::new(AtomicUsize::new(0)); + let observed_addresses = Arc::new(Mutex::new(Vec::new())); + let extra_connections = extra_allowed_connections.clone(); + let body = format!("

fixture

"); + let allowed_server = tokio::spawn(async move { + let (mut socket, _) = + tokio::time::timeout(Duration::from_secs(10), allowed_listener.accept()) + .await + .expect("authorized navigation reaches the allowed fixture") + .unwrap(); + let mut request = [0; 4096]; + let _ = socket.read(&mut request).await.unwrap(); + let response = format!( + "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}", + body.len() + ); + socket.write_all(response.as_bytes()).await.unwrap(); + drop(socket); + + while let Ok((socket, _)) = allowed_listener.accept().await { + extra_connections.fetch_add(1, Ordering::SeqCst); + drop(socket); + } + }); + let denied_targets = Arc::new(Mutex::new(Vec::new())); + let mut browser = EnforcedAgentBrowser::new(Arc::new(RebindingAuthorizer { + allowed_address, + private_address, + authorizations: AtomicUsize::new(0), + denied_targets: denied_targets.clone(), + observed_addresses: observed_addresses.clone(), + })) + .open("live-egress-dns-rebinding"); + let launch = browser + .execute(json!({"id":"launch","action":"launch","headless":true,"args":[]})) + .await; + assert_eq!(launch["success"], true, "{launch}"); + let navigation = browser + .execute(json!({ + "id":"navigate", + "action":"navigate", + "url":format!("http://fixture.test:{port}/") + })) + .await; + wait_for_denied_target(&denied_targets, port).await; + browser + .execute(json!({"id":"close","action":"close"})) + .await; + assert_eq!(navigation["success"], true, "{navigation}"); + let observed_addresses = observed_addresses.lock().unwrap().clone(); + assert_eq!( + observed_addresses.first(), + Some(&allowed_address), + "the controlled resolver first returns the permitted address" + ); + assert!( + observed_addresses.len() >= 2 + && observed_addresses[1..] + .iter() + .all(|address| *address == private_address), + "the controlled resolver must rebind the name to the private address: {observed_addresses:?}" + ); + assert!( + tokio::time::timeout(Duration::from_millis(500), async { + while extra_allowed_connections.load(Ordering::SeqCst) == 0 { + tokio::task::yield_now().await; + } + }) + .await + .is_err(), + "the denied rebound request reached the previously allowed socket" + ); + assert_eq!( + private.accept().unwrap_err().kind(), + io::ErrorKind::WouldBlock, + "the rebound private destination must never receive a connection" + ); + allowed_server.abort(); + let _ = allowed_server.await; +} diff --git a/crates/tinycomputer-browser/src/linked/linked_tests/live_tests/mod.rs b/crates/tinycomputer-browser/src/linked/linked_tests/live_tests/mod.rs new file mode 100644 index 000000000..92045cc2b --- /dev/null +++ b/crates/tinycomputer-browser/src/linked/linked_tests/live_tests/mod.rs @@ -0,0 +1,270 @@ +//! Live Chromium egress tests that use local HTTP and WebSocket fixtures. +#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] + +use super::EnforcedAgentBrowser; +use crate::engine::Launcher; +use crate::{BrowserDialTarget, DialGrant, EgressAuthorizer}; +use serde_json::json; +use std::{ + collections::HashMap, + io, + net::SocketAddr, + sync::{ + Arc, Mutex, + atomic::{AtomicUsize, Ordering}, + }, + time::Duration, +}; +use tokio::{ + io::{AsyncReadExt, AsyncWriteExt}, + net::TcpListener, +}; + +mod denied_requests_tests; +mod dns_rebinding_tests; +mod navigation_tests; + +#[cfg(live_browser_tests)] +#[derive(Debug)] +struct RejectAllButFixture { + address: SocketAddr, + authorizations: Arc, + denied_targets: Arc>>, +} + +#[cfg(live_browser_tests)] +#[derive(Debug)] +struct RebindingAuthorizer { + allowed_address: SocketAddr, + private_address: SocketAddr, + authorizations: AtomicUsize, + denied_targets: Arc>>, + observed_addresses: Arc>>, +} + +#[cfg(live_browser_tests)] +#[derive(Debug)] +struct AllowFixtureHosts { + addresses: HashMap, + authorizations: Arc, +} + +#[cfg(live_browser_tests)] +impl EgressAuthorizer for AllowFixtureHosts { + fn authorize( + &self, + target: BrowserDialTarget, + ) -> std::pin::Pin> + Send>> { + self.authorizations.fetch_add(1, Ordering::SeqCst); + let address = self + .addresses + .get(&target.hostname) + .copied() + .filter(|address| address.port() == target.port); + Box::pin(async move { + match address { + Some(address) => Ok(DialGrant { + lease: "live-cross-origin-fixture-lease".into(), + addresses: vec![address], + }), + None => Err(io::Error::new(io::ErrorKind::PermissionDenied, "denied")), + } + }) + } + + fn consume( + &self, + _: BrowserDialTarget, + grant: DialGrant, + address: SocketAddr, + ) -> std::pin::Pin> + Send>> { + Box::pin(async move { + if grant.addresses.contains(&address) { + Ok(()) + } else { + Err(io::Error::new(io::ErrorKind::PermissionDenied, "denied")) + } + }) + } + + fn validate( + &self, + _: String, + ) -> std::pin::Pin> + Send>> { + Box::pin(async { Ok(true) }) + } +} + +#[cfg(live_browser_tests)] +impl EgressAuthorizer for RebindingAuthorizer { + fn authorize( + &self, + target: BrowserDialTarget, + ) -> std::pin::Pin> + Send>> { + let attempt = self.authorizations.fetch_add(1, Ordering::SeqCst); + let resolved_address = if attempt == 0 { + self.allowed_address + } else { + self.private_address + }; + self.observed_addresses + .lock() + .unwrap() + .push(resolved_address); + let allowed = attempt == 0 + && target.hostname == "fixture.test" + && target.port == self.allowed_address.port(); + if !allowed { + self.denied_targets + .lock() + .unwrap() + .push((target.hostname, target.port)); + } + Box::pin(async move { + if allowed { + Ok(DialGrant { + lease: "live-dns-rebinding-lease".into(), + addresses: vec![resolved_address], + }) + } else { + Err(io::Error::new( + io::ErrorKind::PermissionDenied, + "rebound private address denied", + )) + } + }) + } + + fn consume( + &self, + _: BrowserDialTarget, + grant: DialGrant, + address: SocketAddr, + ) -> std::pin::Pin> + Send>> { + Box::pin(async move { + if grant.addresses.contains(&address) { + Ok(()) + } else { + Err(io::Error::new(io::ErrorKind::PermissionDenied, "denied")) + } + }) + } + + fn validate( + &self, + _: String, + ) -> std::pin::Pin> + Send>> { + Box::pin(async { Ok(true) }) + } +} + +#[cfg(live_browser_tests)] +#[derive(Debug)] +struct AuthorizeExactSocket(SocketAddr); + +#[cfg(live_browser_tests)] +impl EgressAuthorizer for AuthorizeExactSocket { + fn authorize( + &self, + _: BrowserDialTarget, + ) -> std::pin::Pin> + Send>> { + let address = self.0; + Box::pin(async move { + Ok(DialGrant { + lease: "live-pinned-socket-lease".into(), + addresses: vec![address], + }) + }) + } + + fn consume( + &self, + _: BrowserDialTarget, + grant: DialGrant, + address: SocketAddr, + ) -> std::pin::Pin> + Send>> { + Box::pin(async move { + if grant.addresses.contains(&address) { + Ok(()) + } else { + Err(io::Error::new(io::ErrorKind::PermissionDenied, "denied")) + } + }) + } + + fn validate( + &self, + _: String, + ) -> std::pin::Pin> + Send>> { + Box::pin(async { Ok(true) }) + } +} + +#[cfg(live_browser_tests)] +async fn wait_for_denied_target(denied_targets: &Arc>>, port: u16) { + tokio::time::timeout(Duration::from_secs(10), async { + loop { + let was_denied = denied_targets + .lock() + .unwrap() + .iter() + .any(|(_, denied_port)| *denied_port == port); + if was_denied { + break; + } + tokio::time::sleep(Duration::from_millis(10)).await; + } + }) + .await + .expect("Chromium should attempt the denied destination"); +} + +#[cfg(live_browser_tests)] +impl EgressAuthorizer for RejectAllButFixture { + fn authorize( + &self, + target: BrowserDialTarget, + ) -> std::pin::Pin> + Send>> { + let address = self.address; + self.authorizations.fetch_add(1, Ordering::SeqCst); + let allowed = target.hostname == "127.0.0.1" && target.port == address.port(); + if !allowed { + self.denied_targets + .lock() + .unwrap() + .push((target.hostname, target.port)); + } + Box::pin(async move { + if allowed { + Ok(DialGrant { + lease: "live-fixture-lease".into(), + addresses: vec![address], + }) + } else { + Err(io::Error::new(io::ErrorKind::PermissionDenied, "denied")) + } + }) + } + + fn consume( + &self, + _: BrowserDialTarget, + grant: DialGrant, + address: SocketAddr, + ) -> std::pin::Pin> + Send>> { + Box::pin(async move { + if grant.addresses.contains(&address) { + Ok(()) + } else { + Err(io::Error::new(io::ErrorKind::PermissionDenied, "denied")) + } + }) + } + + fn validate( + &self, + _: String, + ) -> std::pin::Pin> + Send>> { + Box::pin(async { Ok(true) }) + } +} diff --git a/crates/tinycomputer-browser/src/linked/linked_tests/live_tests/navigation_tests.rs b/crates/tinycomputer-browser/src/linked/linked_tests/live_tests/navigation_tests.rs new file mode 100644 index 000000000..d3b1e1993 --- /dev/null +++ b/crates/tinycomputer-browser/src/linked/linked_tests/live_tests/navigation_tests.rs @@ -0,0 +1,158 @@ +use super::*; + +#[tokio::test] +#[cfg(live_browser_tests)] +async fn live_chromium_loopback_navigation_uses_the_authenticated_session_proxy() { + let fixture = TcpListener::bind("127.0.0.1:0").await.unwrap(); + let address = fixture.local_addr().unwrap(); + let server = tokio::spawn(async move { + let (mut socket, _) = fixture.accept().await.unwrap(); + let mut request = [0; 4096]; + let _ = socket.read(&mut request).await.unwrap(); + socket + .write_all( + b"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: 22\r\nConnection: close\r\n\r\n

proxy fixture

", + ) + .await + .unwrap(); + }); + let authorizations = Arc::new(AtomicUsize::new(0)); + let mut browser = EnforcedAgentBrowser::new(Arc::new(RejectAllButFixture { + address, + authorizations: authorizations.clone(), + denied_targets: Arc::new(Mutex::new(Vec::new())), + })) + .open("live-egress"); + let launch = browser + .execute(json!({"id":"launch","action":"launch","headless":true,"args":[]})) + .await; + assert_eq!(launch["success"], true, "{launch}"); + let navigation = browser + .execute(json!({ + "id":"navigate", + "action":"navigate", + "url":format!("http://127.0.0.1:{}/", address.port()) + })) + .await; + browser + .execute(json!({"id":"close","action":"close"})) + .await; + assert_eq!( + navigation["success"], + true, + "{navigation}; proxy authorizations: {}", + authorizations.load(Ordering::SeqCst) + ); + server.await.unwrap(); +} + +#[tokio::test] +#[cfg(live_browser_tests)] +async fn live_chromium_dials_only_the_exact_host_authorized_socket() { + let allowed = TcpListener::bind("127.0.0.1:0").await.unwrap(); + let allowed_address = allowed.local_addr().unwrap(); + let denied = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); + denied.set_nonblocking(true).unwrap(); + let denied_address = denied.local_addr().unwrap(); + assert_ne!(allowed_address.port(), denied_address.port()); + + let allowed_server = tokio::spawn(async move { + let (mut socket, _) = allowed.accept().await.unwrap(); + let mut request = [0; 4096]; + let _ = socket.read(&mut request).await.unwrap(); + socket + .write_all( + b"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: 30\r\nConnection: close\r\n\r\n

pinned socket fixture

", + ) + .await + .unwrap(); + }); + let mut browser = EnforcedAgentBrowser::new(Arc::new(AuthorizeExactSocket(allowed_address))) + .open("live-egress-socket-pinning"); + let launch = browser + .execute(json!({"id":"launch","action":"launch","headless":true,"args":[]})) + .await; + assert_eq!(launch["success"], true, "{launch}"); + let navigation = browser + .execute(json!({ + "id":"navigate", + "action":"navigate", + "url":format!("http://{denied_address}/") + })) + .await; + browser + .execute(json!({"id":"close","action":"close"})) + .await; + + assert_eq!(navigation["success"], true, "{navigation}"); + allowed_server.await.unwrap(); + assert_eq!( + denied.accept().unwrap_err().kind(), + io::ErrorKind::WouldBlock, + "Chromium must reach only the exact socket returned by the host grant" + ); +} + +#[tokio::test] +#[cfg(live_browser_tests)] +async fn live_chromium_uses_a_host_permitted_cross_origin_subresource_socket() { + let cdn_fixture = TcpListener::bind("127.0.0.1:0").await.unwrap(); + let cdn_address = cdn_fixture.local_addr().unwrap(); + let page_fixture = TcpListener::bind("127.0.0.1:0").await.unwrap(); + let page_address = page_fixture.local_addr().unwrap(); + let html = format!( + "

page fixture

", + cdn_address.port() + ); + let page_server = tokio::spawn(async move { + let (mut socket, _) = tokio::time::timeout(Duration::from_secs(10), page_fixture.accept()) + .await + .expect("Chromium requests the permitted page") + .unwrap(); + let mut request = [0; 4096]; + let _ = socket.read(&mut request).await.unwrap(); + let response = format!( + "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{html}", + html.len() + ); + socket.write_all(response.as_bytes()).await.unwrap(); + }); + let cdn_server = tokio::spawn(async move { + let (mut socket, _) = tokio::time::timeout(Duration::from_secs(10), cdn_fixture.accept()) + .await + .expect("Chromium requests the permitted cross-origin asset") + .unwrap(); + let mut request = [0; 4096]; + let _ = socket.read(&mut request).await.unwrap(); + socket + .write_all(b"HTTP/1.1 200 OK\r\nContent-Type: image/png\r\nContent-Length: 0\r\nConnection: close\r\n\r\n") + .await + .unwrap(); + }); + let addresses = HashMap::from([ + ("127.0.0.1".to_owned(), page_address), + ("cdn.fixture.test".to_owned(), cdn_address), + ]); + let mut browser = EnforcedAgentBrowser::new(Arc::new(AllowFixtureHosts { + addresses, + authorizations: Arc::new(AtomicUsize::new(0)), + })) + .open("live-egress-permitted-cross-origin"); + let launch = browser + .execute(json!({"id":"launch","action":"launch","headless":true,"args":[]})) + .await; + assert_eq!(launch["success"], true, "{launch}"); + let navigation = browser + .execute(json!({ + "id":"navigate", + "action":"navigate", + "url":format!("http://127.0.0.1:{}/", page_address.port()) + })) + .await; + browser + .execute(json!({"id":"close","action":"close"})) + .await; + assert_eq!(navigation["success"], true, "{navigation}"); + page_server.await.unwrap(); + cdn_server.await.unwrap(); +} From 6267be3b978f7fdbcc1c2d62a7eacb598660ac4a Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Fri, 23 Oct 2026 12:12:38 +0000 Subject: [PATCH 08/15] test(browser_egress): bind rebound listener to same port on ipv6 The DNS rebinding test now binds the rebound listener to the same port as the allowed listener but on the IPv6 loopback address, so the two sockets share a port while remaining distinct endpoints. The assertions were updated to check that the ports match and the addresses differ, which better exercises the rebinding scenario. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../browser_egress_live_tests/dns_rebinding_tests.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 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 8f3536558..788692a7f 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 @@ -6,10 +6,11 @@ use super::*; async fn live_chromium_module_never_dials_a_rebound_private_socket() -> tinybus::Result<()> { let allowed_listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?; let port = allowed_listener.local_addr()?.port(); - let rebound_listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?; + let rebound_listener = tokio::net::TcpListener::bind((std::net::Ipv6Addr::LOCALHOST, port)).await?; let allowed_address = allowed_listener.local_addr()?.to_string(); let rebound_address = rebound_listener.local_addr()?.to_string(); - assert_ne!(port, rebound_listener.local_addr()?.port()); + assert_eq!(port, rebound_listener.local_addr()?.port()); + assert_ne!(allowed_address, rebound_address); let extra_connections = Arc::new(AtomicUsize::new(0)); let (served_tx, served_rx) = tokio::sync::oneshot::channel(); let server = tokio::spawn(serve_fixture( From 8b5eb8e277a7478562ca94e0061b8cc64a6fd41f Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Fri, 23 Oct 2026 12:12:44 +0000 Subject: [PATCH 09/15] style: wrap long listener bind line in dns rebinding test Reformat the rebound listener bind call in the DNS rebinding live test to satisfy the line length limit. No behaviour change. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../browser_egress_live_tests/dns_rebinding_tests.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 788692a7f..2d9444389 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 @@ -6,7 +6,8 @@ use super::*; async fn live_chromium_module_never_dials_a_rebound_private_socket() -> tinybus::Result<()> { let allowed_listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?; let port = allowed_listener.local_addr()?.port(); - let rebound_listener = tokio::net::TcpListener::bind((std::net::Ipv6Addr::LOCALHOST, port)).await?; + let rebound_listener = + tokio::net::TcpListener::bind((std::net::Ipv6Addr::LOCALHOST, port)).await?; let allowed_address = allowed_listener.local_addr()?.to_string(); let rebound_address = rebound_listener.local_addr()?.to_string(); assert_eq!(port, rebound_listener.local_addr()?.port()); From 42182a3fb6099c80c46126ffc47ca81f1eed4c55 Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Fri, 23 Oct 2026 18:44:12 +0530 Subject: [PATCH 10/15] chore(release): 0.15.1 --- Cargo.lock | 20 ++++++++++---------- Cargo.toml | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fdfcf4461..dc7921552 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2765,7 +2765,7 @@ dependencies = [ [[package]] name = "tinycomputer" -version = "0.15.0" +version = "0.15.1" dependencies = [ "getrandom 0.4.3", "serde", @@ -2784,7 +2784,7 @@ dependencies = [ [[package]] name = "tinycomputer-accessibility" -version = "0.15.0" +version = "0.15.1" dependencies = [ "arboard", "command-group", @@ -2800,7 +2800,7 @@ dependencies = [ [[package]] name = "tinycomputer-browser" -version = "0.15.0" +version = "0.15.1" dependencies = [ "agent-browser", "base64 0.22.1", @@ -2819,7 +2819,7 @@ dependencies = [ [[package]] name = "tinycomputer-bus" -version = "0.15.0" +version = "0.15.1" dependencies = [ "base64 0.22.1", "serde", @@ -2829,7 +2829,7 @@ dependencies = [ [[package]] name = "tinycomputer-core" -version = "0.15.0" +version = "0.15.1" dependencies = [ "serde", "serde_json", @@ -2841,7 +2841,7 @@ dependencies = [ [[package]] name = "tinycomputer-cursor" -version = "0.15.0" +version = "0.15.1" dependencies = [ "block2 0.6.2", "getrandom 0.4.3", @@ -2856,7 +2856,7 @@ dependencies = [ [[package]] name = "tinycomputer-desktop" -version = "0.15.0" +version = "0.15.1" dependencies = [ "agent-desktop-core", "agent-desktop-linux", @@ -2871,7 +2871,7 @@ dependencies = [ [[package]] name = "tinycomputer-engine" -version = "0.15.0" +version = "0.15.1" dependencies = [ "getrandom 0.4.3", "serde", @@ -2888,7 +2888,7 @@ dependencies = [ [[package]] name = "tinycomputer-examples" -version = "0.15.0" +version = "0.15.1" dependencies = [ "base64 0.22.1", "serde", @@ -2906,7 +2906,7 @@ dependencies = [ [[package]] name = "tinycomputer-skills" -version = "0.15.0" +version = "0.15.1" dependencies = [ "serde_json", "tinycomputer-bus", diff --git a/Cargo.toml b/Cargo.toml index fd1bd9a3f..184e0d1fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ exclude = ["vendor", "worktrees"] # true`, so the version the release workflow bumps is written in exactly one # place and every crate moves together. [workspace.package] -version = "0.15.0" +version = "0.15.1" edition = "2024" rust-version = "1.89" license = "GPL-3.0-only" From fe409bc5a12bb5b5957aaeb90adfc8d118802b96 Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Fri, 23 Oct 2026 20:32:17 +0530 Subject: [PATCH 11/15] fix(deps): bump tokio to 1.53.3 for RUSTSEC-2026-0386 --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dc7921552..87784060f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3049,9 +3049,9 @@ checksum = "fd3ca314f692efd6c868f8408f53fe444634a845f96c028b97d35f6a1f79f0ee" [[package]] name = "tokio" -version = "1.53.1" +version = "1.53.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "202caea871b69668250d242070849eb495be178ed697a3e98aebce5bc81a0bed" +checksum = "ce3335fa71841cda333a58d7615b03901380ecf09d59b3296d21f8bbac0dde4e" dependencies = [ "bytes", "libc", From c37c898bbc4f0a0d66c4e624c80ce983d8fb8c76 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Sat, 24 Oct 2026 04:03:31 +0000 Subject: [PATCH 12/15] test(browser_egress): cover caller-supplied egress identity being ignored Add a live test asserting that a browser session opened with caller-supplied policy_id and generation still authorizes and consumes sockets under the host-provided module scope. The fixture helper now accepts optional caller options so the open-session payload can be overridden per test. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../browser_egress_live_tests/mod.rs | 76 ++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) 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 bb9ea3400..ceea63764 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 @@ -231,6 +231,7 @@ async fn start_browser_with_fixture_hosts_for_policy( shared_observations, test_connector_map, None, + None, ) .await } @@ -252,6 +253,7 @@ async fn start_browser_with_fixture_hosts_and_resolution( None, None, resolved_address, + None, ) .await } @@ -267,6 +269,7 @@ async fn start_browser_with_fixture_hosts_for_policy_and_resolution( shared_observations: Option>>>, test_connector_map: Option<(String, String)>, resolved_address: Option>>, + caller_options: Option, ) -> tinybus::Result { let bus = MemoryBus::new(); let broker = Broker::new(); @@ -311,7 +314,7 @@ async fn start_browser_with_fixture_hosts_for_policy_and_resolution( let opened: DesktopResponse = proxy .call( browser_names::methods::OPEN_SESSION, - (serde_json::json!({}),), + (caller_options.unwrap_or_else(|| serde_json::json!({})),), ) .await?; let session = successful_data(&opened)["id"].clone(); @@ -346,6 +349,77 @@ async fn start_browser_with_fixture_hosts_for_policy_and_resolution( }) } +#[tokio::test] +async fn live_chromium_module_ignores_caller_supplied_egress_identity() -> tinybus::Result<()> { + let allowed_listener = tokio::net::TcpListener::bind("[::1]:0").await?; + let allowed_address = allowed_listener.local_addr()?.to_string(); + let port = allowed_listener.local_addr()?.port(); + let (served_tx, served_rx) = tokio::sync::oneshot::channel(); + let allowed_server = tokio::spawn(serve_fixture( + allowed_listener, + b"identity fixture" + .to_vec(), + Arc::new(AtomicUsize::new(0)), + served_tx, + None, + )); + let browser = start_browser_with_fixture_hosts_for_policy_and_resolution( + vec![allowed_address.clone()], + port, + "/identity", + served_rx, + "module-policy", + 73, + None, + None, + None, + Some(serde_json::json!({ + "policy_id": "caller-policy", + "generation": 999, + "egress": {"policy_id": "caller-policy", "generation": 999} + })), + ) + .await?; + + { + let calls = browser.observations.lock().unwrap(); + assert!( + calls + .iter() + .any(|call| call.starts_with("authorize:module-policy:73:fixture.test:")), + "the loaded module did not use its host-provided egress scope: {calls:?}" + ); + assert!( + !calls + .iter() + .any(|call| call.contains("caller-policy") || call.contains(":999:")), + "caller-supplied identity reached the host authority: {calls:?}" + ); + assert!( + calls + .iter() + .any(|call| call == &format!("consume:{allowed_address}")), + "the host did not consume the socket under the module scope: {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(); + allowed_server.abort(); + Ok(()) +} + #[tokio::test] async fn live_chromium_module_dials_only_the_host_returned_socket_and_rejects_changed_policy() -> tinybus::Result<()> { From e79a71ac7aef8bb7b6676d1048c2efaface4a9e9 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Sat, 24 Oct 2026 04:17:44 +0000 Subject: [PATCH 13/15] chore(deps): bump tinybus to 0.1.9 and tinytools to 0.6.0 Update the lockfile for the tinybus 0.1.9 and tinytools 0.6.0 releases, which swap the zip dependency for rawzip and add icu_casemap and unicode-normalization for case folding and text normalization. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- Cargo.lock | 68 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 87784060f..759f8371e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1143,6 +1143,28 @@ dependencies = [ "cc", ] +[[package]] +name = "icu_casemap" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2edfd120d8445de853cf53a1abec916f638f933a70a6f4bf8f7e2d7b7f884e9" +dependencies = [ + "icu_casemap_data", + "icu_collections", + "icu_locale_core", + "icu_properties", + "icu_provider", + "potential_utf", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_casemap_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "059fcda0fc8d33effc6633a8cf0d8a3c17caf7d7c91918fba9918744f501e4e8" + [[package]] name = "icu_collections" version = "2.3.0" @@ -1151,6 +1173,7 @@ checksum = "fa68d21081c4a05d5a901a1c62add574c77048b6a1c67be3b50ce0b60d4ca513" dependencies = [ "displaydoc", "potential_utf", + "serde", "utf8_iter", "yoke", "zerofrom", @@ -1165,6 +1188,7 @@ checksum = "d56e28588da92eee5c3201a6eff33fabdd49b62269c8938d4ff050ce4d900deb" dependencies = [ "displaydoc", "litemap", + "serde", "tinystr", "writeable", "zerovec", @@ -1219,6 +1243,8 @@ checksum = "d27bbb9d3abbefac45d55f647c9de1d44aafcd1186eb91879afef17c396c3e73" dependencies = [ "displaydoc", "icu_locale_core", + "serde", + "stable_deref_trait", "writeable", "yoke", "zerofrom", @@ -1935,6 +1961,8 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661" dependencies = [ + "serde_core", + "writeable", "zerovec", ] @@ -2145,6 +2173,12 @@ dependencies = [ "rand_core 0.10.1", ] +[[package]] +name = "rawzip" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac9999039f74cd73c03158cddfe4362991703c74efe5ce5c8073026f80a5e48c" + [[package]] name = "redox_syscall" version = "0.5.18" @@ -2645,7 +2679,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" dependencies = [ "fastrand", - "getrandom 0.4.3", + "getrandom 0.3.4", "once_cell", "rustix 1.1.4", "windows-sys 0.61.2", @@ -2723,11 +2757,13 @@ dependencies = [ [[package]] name = "tinybus" -version = "0.1.6" +version = "0.1.9" dependencies = [ "async-trait", "flate2", + "icu_casemap", "libc", + "rawzip", "serde", "serde_json", "sha2 0.10.9", @@ -2738,13 +2774,13 @@ dependencies = [ "tokio", "toml", "tracing", + "unicode-normalization", "ureq", - "zip", ] [[package]] name = "tinybus-macros" -version = "0.1.6" +version = "0.1.9" dependencies = [ "proc-macro2", "quote", @@ -2753,7 +2789,7 @@ dependencies = [ [[package]] name = "tinybus-module" -version = "0.1.6" +version = "0.1.9" dependencies = [ "async-trait", "serde", @@ -3016,13 +3052,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1e27c91459209c2986af3dcf603a5a74a4368754ce37414f59acc971167f643" dependencies = [ "displaydoc", + "serde_core", "zerovec", ] [[package]] name = "tinytools" -version = "0.5.0" -source = "git+https://github.com/tinyhumansai/tinytools?rev=bd60b9b52f1998b4483b9cf107a72d3338e672f8#bd60b9b52f1998b4483b9cf107a72d3338e672f8" +version = "0.6.0" +source = "git+https://github.com/tinyhumansai/tinytools?rev=3a01641f8ebd8a55656cd212f9a90638d958a447#3a01641f8ebd8a55656cd212f9a90638d958a447" dependencies = [ "anyhow", "async-trait", @@ -3032,8 +3069,8 @@ dependencies = [ [[package]] name = "tinytools-agent" -version = "0.5.0" -source = "git+https://github.com/tinyhumansai/tinytools?rev=bd60b9b52f1998b4483b9cf107a72d3338e672f8#bd60b9b52f1998b4483b9cf107a72d3338e672f8" +version = "0.6.0" +source = "git+https://github.com/tinyhumansai/tinytools?rev=3a01641f8ebd8a55656cd212f9a90638d958a447#3a01641f8ebd8a55656cd212f9a90638d958a447" dependencies = [ "regex", "serde", @@ -3322,6 +3359,15 @@ version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" +[[package]] +name = "unicode-normalization" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75cd3fb03d5288b3ba9a1ee103ac7e9cbb59f0b03d64f8ddfcc04dd42758a85d" +dependencies = [ + "tinyvec", +] + [[package]] name = "universal-hash" version = "0.5.1" @@ -3573,7 +3619,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.48.0", ] [[package]] @@ -4117,6 +4163,7 @@ dependencies = [ "displaydoc", "yoke", "zerofrom", + "zerovec", ] [[package]] @@ -4125,6 +4172,7 @@ version = "0.11.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb0464e17806c1d976d5cba29399c7f08e516e279e2ba493f63123b5fca67dd8" dependencies = [ + "serde", "yoke", "zerofrom", "zerovec-derive", From b31c9328c48f9725677e14b29259b60c80261644 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Sat, 24 Oct 2026 04:39:11 +0000 Subject: [PATCH 14/15] test(browser_egress): add inline favicon to dns rebinding fixture The allowed fixture page now declares an empty data-URI favicon so the browser does not issue an implicit /favicon.ico request that could interfere with the connection accounting in the rebinding test. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../browser_egress_live_tests/dns_rebinding_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 56135e843..f5d047050 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 @@ -16,7 +16,7 @@ async fn live_chromium_module_never_dials_a_rebound_private_socket() -> tinybus: let (served_tx, served_rx) = tokio::sync::oneshot::channel(); let server = tokio::spawn(serve_fixture( allowed_listener, - b"allowed fixture".to_vec(), + b"allowed fixture".to_vec(), extra_connections.clone(), served_tx, None, From 42d885051262175e53ce90b69e2ed87232666351 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Sat, 24 Oct 2026 04:39:30 +0000 Subject: [PATCH 15/15] test(browser_egress): wrap long fixture byte literal Reformat the allowed fixture HTML byte literal in the DNS rebinding live test so it fits within the line width limit. No behaviour change. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../browser_egress_live_tests/dns_rebinding_tests.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 f5d047050..78ce87f29 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 @@ -16,7 +16,8 @@ async fn live_chromium_module_never_dials_a_rebound_private_socket() -> tinybus: let (served_tx, served_rx) = tokio::sync::oneshot::channel(); let server = tokio::spawn(serve_fixture( allowed_listener, - b"allowed fixture".to_vec(), + b"allowed fixture" + .to_vec(), extra_connections.clone(), served_tx, None,