fix(app): don't connect to localhost through vpn

This commit is contained in:
adamelmore
2026-01-27 14:55:50 -06:00
parent d7948c2376
commit 1ebf63c70c
2 changed files with 36 additions and 3 deletions

View File

@@ -52,7 +52,32 @@ fn configure_display_backend() -> Option<String> {
}
fn main() {
unsafe { std::env::set_var("NO_PROXY", "127.0.0.1,localhost,::1") };
// Ensure loopback connections are never sent through proxy settings.
// Some VPNs/proxies set HTTP_PROXY/HTTPS_PROXY/ALL_PROXY without excluding localhost.
const LOOPBACK: [&str; 3] = ["127.0.0.1", "localhost", "::1"];
let upsert = |key: &str| {
let mut items = std::env::var(key)
.unwrap_or_default()
.split(',')
.map(|v| v.trim())
.filter(|v| !v.is_empty())
.map(|v| v.to_string())
.collect::<Vec<_>>();
for host in LOOPBACK {
if items.iter().any(|v| v.eq_ignore_ascii_case(host)) {
continue;
}
items.push(host.to_string());
}
// Safety: called during startup before any threads are spawned.
unsafe { std::env::set_var(key, items.join(",")) };
};
upsert("NO_PROXY");
upsert("no_proxy");
#[cfg(target_os = "linux")]
{