From bcea651c9315f778afcefda620142750e5555146 Mon Sep 17 00:00:00 2001 From: oc-code-08 Date: Mon, 23 Nov 2026 10:48:37 -0600 Subject: [PATCH] fleet-proxy: pin explicit-allow for unadvertised dial ports (#13464) do_request dials the frame-declared port verbatim via a named dial_port helper: absent means the laptop-agent default, any frame-valid u16 passes through with no services_map membership check. Refusing unadvertised ports would break the deliberate --service-port consumer (client.rs pins 8080); the #6582 contract holds via frame-boundary type/range validation (#6516) plus token gating. Test pins the dial-site rule. --- pkgs/fleet/crates/fleet-proxy/src/serve.rs | 42 +++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/pkgs/fleet/crates/fleet-proxy/src/serve.rs b/pkgs/fleet/crates/fleet-proxy/src/serve.rs index 3d8713068f..ec7a0df43a 100644 --- a/pkgs/fleet/crates/fleet-proxy/src/serve.rs +++ b/pkgs/fleet/crates/fleet-proxy/src/serve.rs @@ -713,7 +713,7 @@ impl Broker { if client { self.last_used.store(now_secs(), Ordering::Relaxed); } - let port = req.port.unwrap_or(fleet_config::PORT_LAPTOP_AGENT); + let port = dial_port(req.port); let token_path = match &req.token_file { Some(p) => std::path::PathBuf::from(p), None => self.config.default_token_file(), @@ -833,6 +833,27 @@ impl Broker { /// plan falls to the next leg. const CF_EDGE_STATUSES: [u16; 3] = [502, 503, 530]; +/// The port `do_request` dials for one parsed request +/// (#13464): the client-declared port verbatim, or the +/// laptop-agent default when the frame named none. There is +/// deliberately NO `services_map` membership check here. The +/// advertised table (`Config::services`, the hello map) is a +/// host-local, configurable advertisement — discovery for the +/// hello and the shims — not an access-control list, and the +/// in-tree consumer `fleet proxy connect --request …` +/// `--service-port N` deliberately addresses operator-chosen +/// ports outside it (client.rs pins `--service-port 8080`): +/// refusing unadvertised ports would break that consumer +/// (#6583 disposition (a)). The #6582 contract still holds: the +/// port is validated where it is read — type and range at the +/// frame boundary (`parse_port`, #6516) — and the dial itself +/// stays token-gated. Residual risk, recorded: an unadvertised +/// port receiving an arbitrary body is only as constrained as +/// the service behind it (#6583 (b)). +fn dial_port(requested: Option) -> u16 { + requested.unwrap_or(fleet_config::PORT_LAPTOP_AGENT) +} + /// The attempt plan for one request, the Python broker's plan /// exactly (code#10356). The Cloudflare leg is in play only for /// the laptop-agent daemon port, only when the caller's @@ -2178,6 +2199,25 @@ mod tests { assert_eq!(req.port, Some(65535)); } + #[test] + fn dial_port_passes_any_frame_valid_port_through() { + // The #13464 decision, pinned at the dial site: no + // services_map membership filtering. Absent means the + // laptop-agent default; a table port passes through + // unchanged; a non-table port -- the --service-port case, + // e.g. 8080, which client.rs pins as parseable -- passes + // through verbatim, up to the top of the u16 range the + // frame boundary validated (#6516). A future membership + // refusal must change this test, not slip past it. + assert_eq!(dial_port(None), fleet_config::PORT_LAPTOP_AGENT); + assert_eq!( + dial_port(Some(fleet_config::PORT_LAPTOP_AGENT)), + fleet_config::PORT_LAPTOP_AGENT + ); + assert_eq!(dial_port(Some(8080)), 8080); + assert_eq!(dial_port(Some(65535)), 65535); + } + #[test] fn parse_request_refuses_present_but_invalid_ports() { // Every shape the pre-fix chain silently collapsed to the