fix: 帳號伺服器 http 被拒的那一句不再說「之後會再試」;localhost 的原因不再被吞掉
一般拒絕(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 <noreply@anthropic.com>
This commit is contained in:
parent
a23f420074
commit
ce54297375
|
|
@ -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<Vec<std::net::SocketAddr>, 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<std::net::SocketAddr> = 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());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue