From 07a77946e34daf78b4a6bfb99a46f4694ef4bd37 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Fri, 23 Oct 2026 00:14:28 +0000 Subject: [PATCH 1/2] test(browser): cover exact-socket egress pinning in live chromium Add a live test that grants a single authorized socket and asserts Chromium dials only that exact address, with a listener on the same port at a different host left untouched. A small authorizer fixture supplies the pinned grant so the check exercises the real dial path. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../src/linked/linked_tests/live_tests.rs | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) 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 085f0214b..4b9486e12 100644 --- a/crates/tinycomputer-browser/src/linked/linked_tests/live_tests.rs +++ b/crates/tinycomputer-browser/src/linked/linked_tests/live_tests.rs @@ -65,6 +65,51 @@ async fn live_chromium_loopback_navigation_uses_the_authenticated_session_proxy( 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.2:0").await.unwrap(); + let allowed_address = allowed.local_addr().unwrap(); + let denied = std::net::TcpListener::bind(("127.0.0.1", allowed_address.port())).unwrap(); + denied.set_nonblocking(true).unwrap(); + + 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: 26\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://127.0.0.1:{}/", allowed_address.port()) + })) + .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() { @@ -243,6 +288,48 @@ struct RejectAllButFixture { denied_targets: Arc>>, } +#[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(3), async { From 6b0a3c8536cc41ef117bbcadb8deed75cc28965a Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Fri, 23 Oct 2026 00:15:45 +0000 Subject: [PATCH 2/2] test(browser): fix content-length in live socket fixture The fixture response declared a Content-Length of 26 while the body is 30 bytes, so the test server advertised a shorter body than it sent. The header now matches the actual body length. 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 4b9486e12..556a14328 100644 --- a/crates/tinycomputer-browser/src/linked/linked_tests/live_tests.rs +++ b/crates/tinycomputer-browser/src/linked/linked_tests/live_tests.rs @@ -79,7 +79,7 @@ async fn live_chromium_dials_only_the_exact_host_authorized_socket() { let _ = socket.read(&mut request).await.unwrap(); socket .write_all( - b"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: 26\r\nConnection: close\r\n\r\n

pinned socket fixture

", + 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();