mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-11-04 00:33:12 +00:00
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.
This commit is contained in:
1 parent
4b92080e3e
commit
bbffc1de5a
1 file changed
+13
@@ -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(
|
||||
|
||||
Reference in new issue
Block a user