Skip to content

Commit

Permalink
Fail if proxy tries to connect to itself.
Browse files Browse the repository at this point in the history
  • Loading branch information
zlogic committed Aug 2, 2024
1 parent ceb4b10 commit 6a656df
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/proxy.rs
Original file line number Diff line number Diff line change
@@ -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<String>,
tunnel_domains: Vec<String>,
listen_addr: SocketAddr,
}

struct ProxyConnection {
@@ -240,6 +242,12 @@ impl ProxyConnection {
direct_connection: bool,
initial_data: Option<Vec<u8>>,
) -> Result<DestinationConnection, ProxyError> {
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);

0 comments on commit 6a656df

Please sign in to comment.