Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test(node): prove the policy clients ignore environment proxies
A client that honors HTTP_PROXY or ALL_PROXY hands the target hostname to
the proxy's own resolver, which bypasses the resolver policy entirely.
Each production builder is exercised in a child process with the proxy
variables pointed at a decoy loopback listener: the IP-literal request
must reach the real listener and the decoy must see zero connections.
  • Loading branch information
beardthelion committed Nov 18, 2026
commit bde6c08ec994ee392380f8a4779e8d4b63634c85
32 changes: 32 additions & 0 deletions crates/twigpine-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2533,6 +2533,38 @@ mod gossip_ssrf_tests {
assert_eq!(accepted.load(Ordering::SeqCst), 0);
}

// A configured proxy receives the target hostname and resolves it itself,
// which bypasses the resolver policy, so the shared client must ignore
// proxy env vars. The parent binds the decoy "proxy" listener and points
// HTTP_PROXY/ALL_PROXY at it; the child requests an IP-literal URL on a
// second listener, which needs no resolution. If the client honored the
// proxy, the decoy sees a connection.
#[tokio::test]
async fn shared_client_ignores_env_proxy() {
use crate::isolated_child::{in_child, run_isolated};
if !in_child() {
let (proxy_port, proxy_hits) = counting_listener().await;
let proxy = format!("http://127.0.0.1:{proxy_port}");
run_isolated(
"gossip_ssrf_tests::shared_client_ignores_env_proxy",
&[("HTTP_PROXY", proxy.as_str()), ("ALL_PROXY", proxy.as_str())],
);
assert_eq!(
proxy_hits.load(Ordering::SeqCst),
0,
"the client must not dial the configured proxy"
);
return;
}
let (port, accepted) = counting_listener().await;
production_http_client()
.get(format!("http://127.0.0.1:{port}/"))
.send()
.await
.expect("an IP-literal request must succeed");
assert_eq!(accepted.load(Ordering::SeqCst), 1);
}

// The announce funnel stores a hostname the string gate accepts. The ping
// rounds must then never reach the listener it resolves to.
#[sqlx::test]
Expand Down
29 changes: 29 additions & 0 deletions crates/twigpine-node/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3549,6 +3549,35 @@ mod tests {
assert_eq!(calls.load(std::sync::atomic::Ordering::SeqCst), 1);
}

// Same proxy-bypass guard as the shared client: a configured proxy would
// resolve the peer's hostname itself, skipping the resolver policy. The
// parent binds the decoy proxy listener and sets HTTP_PROXY/ALL_PROXY on
// the child; the child requests an IP-literal URL on a second listener.
#[tokio::test]
async fn sync_client_ignores_env_proxy() {
use crate::isolated_child::{in_child, run_isolated};
if !in_child() {
let (proxy_port, proxy_hits) = counting_listener().await;
let proxy = format!("http://127.0.0.1:{proxy_port}");
run_isolated(
"sync::tests::sync_client_ignores_env_proxy",
&[("HTTP_PROXY", proxy.as_str()), ("ALL_PROXY", proxy.as_str())],
);
assert_eq!(
proxy_hits.load(std::sync::atomic::Ordering::SeqCst),
0,
"the client must not dial the configured proxy"
);
return;
}
let (port, accepted) = counting_listener().await;
let _ = build_sync_http_client()
.get(format!("http://127.0.0.1:{port}/"))
.send()
.await;
assert_eq!(accepted.load(std::sync::atomic::Ordering::SeqCst), 1);
}

#[tokio::test]
async fn sync_client_refuses_a_name_that_resolves_to_loopback_in_register_replica() {
let (resolver, calls) = loopback_resolver();
Expand Down