From 6a656df86dca15de2e692fec90c0456f8472b8c6 Mon Sep 17 00:00:00 2001 From: Dmitry Zolotukhin Date: Fri, 2 Aug 2024 17:25:06 +0200 Subject: [PATCH] Fail if proxy tries to connect to itself. --- src/proxy.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/proxy.rs b/src/proxy.rs index 096e2a5..5f3a7cf 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -53,6 +53,7 @@ impl Server { let options = Arc::new(ProxyOptions { pac_path: self.pac_path.clone(), tunnel_domains: self.tunnel_domains.clone(), + listen_addr: self.listen_addr, }); loop { match listener.accept().await { @@ -76,6 +77,7 @@ impl Server { struct ProxyOptions { pac_path: Option, tunnel_domains: Vec, + listen_addr: SocketAddr, } struct ProxyConnection { @@ -240,6 +242,12 @@ impl ProxyConnection { direct_connection: bool, initial_data: Option>, ) -> Result { + if addr.port() == self.options.listen_addr.port() + && ((self.options.listen_addr.ip().is_loopback() && addr.ip().is_loopback()) + || addr.ip() == self.options.listen_addr.ip()) + { + return Err("Loop detected".into()); + } if !direct_connection && addr.is_ipv4() { let (sender, receiver) = oneshot::channel(); let connection_request = network::SocketConnectionRequest::new(sender, initial_data);