@@ -13,7 +13,11 @@ use std::os::{
1313 fd:: AsFd ,
1414 unix:: io:: { AsRawFd , BorrowedFd , FromRawFd , IntoRawFd , RawFd } ,
1515} ;
16- use std:: { net:: SocketAddr , sync:: Arc , time:: Duration } ;
16+ use std:: {
17+ net:: { IpAddr , Ipv4Addr , Ipv6Addr , SocketAddr } ,
18+ sync:: Arc ,
19+ time:: Duration ,
20+ } ;
1721#[ cfg( feature = "tls" ) ]
1822use tokio_rustls:: rustls:: { ClientConfig , ServerConfig } ;
1923
@@ -46,6 +50,11 @@ pub(crate) struct ServiceConfig {
4650 pub tcp_config : TcpConfig ,
4751 #[ cfg( feature = "tls" ) ]
4852 pub tls_config : Option < TlsConfig > ,
53+ /// Trusted proxy addresses for HAProxy PROXY protocol and X-Forwarded-For header parsing.
54+ /// When a connection comes from one of these addresses, the real client IP will be extracted
55+ /// from PROXY protocol headers (for TCP) or X-Forwarded-For headers (for WebSocket).
56+ /// By default, loopback addresses (127.0.0.1 and ::1) are included in this list.
57+ pub trusted_proxies : Vec < IpAddr > ,
4958}
5059
5160impl Default for ServiceConfig {
@@ -61,6 +70,11 @@ impl Default for ServiceConfig {
6170 tcp_config : Default :: default ( ) ,
6271 #[ cfg( feature = "tls" ) ]
6372 tls_config : None ,
73+ // Default: trust loopback addresses
74+ trusted_proxies : vec ! [
75+ IpAddr :: V4 ( Ipv4Addr :: LOCALHOST ) ,
76+ IpAddr :: V6 ( Ipv6Addr :: LOCALHOST ) ,
77+ ] ,
6478 }
6579 }
6680}
0 commit comments