From ce54297375d7378607226df06e50a5ab3f12cc17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=A7=E9=A9=8A?= Date: Wed, 18 Nov 2026 12:15:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B8=B3=E8=99=9F=E4=BC=BA=E6=9C=8D?= =?UTF-8?q?=E5=99=A8=20http=20=E8=A2=AB=E6=8B=92=E7=9A=84=E9=82=A3?= =?UTF-8?q?=E4=B8=80=E5=8F=A5=E4=B8=8D=E5=86=8D=E8=AA=AA=E3=80=8C=E4=B9=8B?= =?UTF-8?q?=E5=BE=8C=E6=9C=83=E5=86=8D=E8=A9=A6=E3=80=8D=EF=BC=9Blocalhost?= =?UTF-8?q?=20=E7=9A=84=E5=8E=9F=E5=9B=A0=E4=B8=8D=E5=86=8D=E8=A2=AB?= =?UTF-8?q?=E5=90=9E=E6=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 一般拒絕(0c250d5 起)和 localhost 拒絕(a23f420)都說「之後會再試」,可是登入、建立帳號、 兩步驗證、配對、還原會回到表單,不會再試;只有長連線、備用連線、--serve 會再試(文件本來就這樣 分)。兩句都拿掉括號。localhost 那句沒有 http://,why_unreachable 只放行帶 http:// 的拒絕, 所以 relay_agent 的解析器擋下時只剩「網路連線出了問題」——改成「網址是 http://localhost」。 plain_hop 的註解把「每個位址都是 loopback」加回來(localhost 以外的名字仍要全部是)。 已驗證: 全部 cargo test(不帶金鑰、DOCKER_HOST 指到不存在)654 通過(新斷言加在既有的 a_one_word_name_is_never_a_number 裡);clippy -D warnings 乾淨; 新斷言 why_unreachable(localhost 拒絕) 原樣傳出——把 http:// 拿掉時 a_one_word_name_is_never_a_number 失敗,還原後逐位元組相同 未驗證: 真的 /etc/hosts 有 fe80::1%lo0 的 Mac(只有單元測試);verify-anybot 沒重跑(手機上看不到差別) Co-Authored-By: Claude Opus 5.5 --- src/remote.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/remote.rs b/src/remote.rs index 3b3c58a..f5814eb 100644 --- a/src/remote.rs +++ b/src/remote.rs @@ -1916,8 +1916,8 @@ fn base(url: &str) -> String { /// computer's key may go to it unencrypted. `host` is the name in the URL and `addrs` what it /// resolved to — the very addresses about to be connected to (a name can answer differently the /// second time, so the check is made at the moment of connecting, on what it answered then). -/// Off the air: this machine (a loopback address; for `localhost` only its loopback addresses -/// are kept, and it is refused when none is); a one-word name (`one_word_name`), taken to be another +/// Off the air: this machine (every resolved address a loopback one; for `localhost` only its +/// loopback addresses are kept, and it is refused when none is); a one-word name (`one_word_name`), taken to be another /// container of the same Docker network (http://relay:8080 — see SECURITY.md about such names on /// an ordinary network); or a server reached through this machine's Tailscale tunnel /// (lantls::tunnel_route: Tailscale addresses whose route leaves from the tunnel; one with no @@ -1925,13 +1925,13 @@ fn base(url: &str) -> String { /// isn't Tailscale: a Wi-Fi can hand those out. The answer is the addresses to connect to. pub(crate) fn plain_hop(host: &str, addrs: &[std::net::SocketAddr]) -> Result, String> { let host = host.trim_start_matches('[').trim_end_matches(']'); - let refuse = || Err(format!("帳號伺服器 {host} 用的是 http://,這台到它的路不經過 Tailscale:帳號密碼和這台電腦的金鑰會在網路上明文傳送,所以先不連(之後會再試)。請改用 https://,或等 Tailscale 連上")); + let refuse = || Err(format!("帳號伺服器 {host} 用的是 http://,這台到它的路不經過 Tailscale:帳號密碼和這台電腦的金鑰會在網路上明文傳送,所以先不連。請改用 https://,或等 Tailscale 連上")); // `localhost`: only its loopback addresses (an older Mac's hosts file adds fe80::1%lo0, and // one could send it anywhere); none at all, and it isn't this machine. if host.eq_ignore_ascii_case("localhost") { let here: Vec = addrs.iter().filter(|a| a.ip().to_canonical().is_loopback()).copied().collect(); if here.is_empty() && !addrs.is_empty() { - return Err("帳號伺服器的網址是 localhost,可是這台電腦把 localhost 查到別的位址(看 /etc/hosts):帳號密碼和這台電腦的金鑰都不會送過去,所以先不連(之後會再試)".to_string()); + return Err("帳號伺服器的網址是 http://localhost,可是這台電腦把 localhost 查到別的位址(看 /etc/hosts):帳號密碼和這台電腦的金鑰都不會送過去,所以先不連".to_string()); } return Ok(here); } @@ -3230,6 +3230,9 @@ mod tests { assert_eq!(kept, both[1..].to_vec()); let e = crate::lantls::with_tunnels(&[], || plain_hop("localhost", &[link_local])).unwrap_err(); assert!(e.contains("localhost") && e.contains("/etc/hosts"), "{e}"); + // Said as it is when the http client's resolver refuses (not 「網路連線出了問題」). + let refused = ureq::Error::Io(std::io::Error::new(std::io::ErrorKind::PermissionDenied, e.clone())); + assert_eq!(why_unreachable(&refused), e); // (A number that does land on this machine is still this machine.) assert!(plain_hop("0x7f000001", &at("127.0.0.1")).is_ok()); }