From bbffc1de5aa33a90d932e47dadaebbca7a7808b8 Mon Sep 17 00:00:00 2001 From: Leo Camus Date: Tue, 20 Oct 2026 16:12:00 +0200 Subject: [PATCH] fix: bracket a bare IPv6 ID server when deriving the API server (#16624) With the API server field empty, get_api_server_ builds the URL from the ID server as "http://{host}:21114". For an ID server entered as a bare IPv6 address such as 2001:db8::1, which test_if_valid_server accepts, increase_port leaves it unchanged and the result is http://2001:db8::1:21114. That does not parse as a URL (InvalidPort), so login and every other API request fail. Wrap the address in brackets in that branch only. Hostnames, IPv4 and "[addr]:port" take the same path as before. --- src/common.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/common.rs b/src/common.rs index b9b690265..d00d94adf 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1251,6 +1251,11 @@ fn get_api_server_(api: String, custom: String) -> String { if !s0.is_empty() { let s = crate::increase_port(&s0, -2); if s == s0 { + let s = if hbb_common::is_ipv6_str(&s) && !s.starts_with('[') { + format!("[{s}]") + } else { + s + }; return format!("http://{}:{}", s, config::RENDEZVOUS_PORT - 2); } else { return format!("http://{}", s); @@ -3209,6 +3214,14 @@ mod tests { assert!(!is_public("https://rustdesk.com@evil.test")); } + #[test] + fn test_api_server_from_bare_ipv6_rendezvous_server() { + assert_eq!( + get_api_server_("".to_owned(), "2001:db8::1".to_owned()), + "http://[2001:db8::1]:21114" + ); + } + #[test] fn test_should_use_tcp_proxy_for_api_url() { assert!(should_use_tcp_proxy_for_api_url(