@@ -52,30 +52,31 @@ impl SocketAddrOrHostname {
5252 if port. parse :: < u16 > ( ) . is_err ( ) {
5353 return false ;
5454 }
55-
55+
5656 // Check that there are no other colons in the host part
5757 if host. contains ( ':' ) {
5858 return false ;
5959 }
60-
60+
6161 // Basic hostname validation
6262 if host. is_empty ( ) || host. len ( ) > 253 {
6363 return false ;
6464 }
65-
65+
6666 // Check each label
6767 for label in host. split ( '.' ) {
6868 if label. is_empty ( ) || label. len ( ) > 63 {
6969 return false ;
7070 }
7171 // Check for valid characters (letters, digits, hyphens, but not starting/ending with hyphen)
72- if !label. chars ( ) . all ( |c| c. is_alphanumeric ( ) || c == '-' )
73- || label. starts_with ( '-' )
74- || label. ends_with ( '-' ) {
72+ if !label. chars ( ) . all ( |c| c. is_alphanumeric ( ) || c == '-' )
73+ || label. starts_with ( '-' )
74+ || label. ends_with ( '-' )
75+ {
7576 return false ;
7677 }
7778 }
78-
79+
7980 // Additional validation: ensure it looks like a proper hostname
8081 // Must have at least one dot or be a valid single label
8182 if !host. contains ( '.' ) {
@@ -84,7 +85,7 @@ impl SocketAddrOrHostname {
8485 return false ;
8586 }
8687 }
87-
88+
8889 true
8990 } else {
9091 false // No port specified
@@ -98,16 +99,16 @@ impl<'de> serde::Deserialize<'de> for SocketAddrOrHostname {
9899 D : serde:: Deserializer < ' de > ,
99100 {
100101 use serde:: Deserialize ;
101-
102+
102103 #[ derive( Deserialize ) ]
103104 #[ serde( untagged) ]
104105 enum SocketAddrOrString {
105106 SocketAddr ( SocketAddr ) ,
106107 String ( String ) ,
107108 }
108-
109+
109110 let value = SocketAddrOrString :: deserialize ( deserializer) ?;
110-
111+
111112 match value {
112113 SocketAddrOrString :: SocketAddr ( addr) => Ok ( SocketAddrOrHostname :: SocketAddr ( addr) ) ,
113114 SocketAddrOrString :: String ( hostname) => {
@@ -268,7 +269,7 @@ impl EgressSource {
268269 . map ( |lookup| lookup. item )
269270 }
270271
271- fn resolve_proxy_protocol ( & ' _ self , address : SocketAddr ) -> anyhow:: Result < ProxyProto < ' _ > > {
272+ async fn resolve_proxy_protocol ( & ' _ self , address : SocketAddr ) -> anyhow:: Result < ProxyProto < ' _ > > {
272273 use ppp:: v2:: { Addresses , IPv4 , IPv6 } ;
273274 let source_name = & self . name ;
274275
@@ -980,19 +981,27 @@ mod test {
980981 // Valid hostnames with ports
981982 assert ! ( SocketAddrOrHostname :: is_valid_hostname( "example.com:8080" ) ) ;
982983 assert ! ( SocketAddrOrHostname :: is_valid_hostname( "localhost:5000" ) ) ;
983- assert ! ( SocketAddrOrHostname :: is_valid_hostname( "api.example.org:443" ) ) ;
984-
984+ assert ! ( SocketAddrOrHostname :: is_valid_hostname(
985+ "api.example.org:443"
986+ ) ) ;
987+
985988 // Valid single label hostnames
986989 assert ! ( SocketAddrOrHostname :: is_valid_hostname( "api:8080" ) ) ;
987990 assert ! ( SocketAddrOrHostname :: is_valid_hostname( "test:5000" ) ) ;
988-
991+
989992 // Invalid cases
990993 assert ! ( !SocketAddrOrHostname :: is_valid_hostname( "example.com" ) ) ; // No port
991- assert ! ( !SocketAddrOrHostname :: is_valid_hostname( "example.com:invalid" ) ) ; // Invalid port
994+ assert ! ( !SocketAddrOrHostname :: is_valid_hostname(
995+ "example.com:invalid"
996+ ) ) ; // Invalid port
992997 assert ! ( !SocketAddrOrHostname :: is_valid_hostname( "" ) ) ; // Empty string
993998 assert ! ( !SocketAddrOrHostname :: is_valid_hostname( ":8080" ) ) ; // No hostname
994- assert ! ( !SocketAddrOrHostname :: is_valid_hostname( "example.com:8080:extra" ) ) ; // Multiple colons
995- assert ! ( !
SocketAddrOrHostname :: is_valid_hostname
( "[email protected] :8080" ) ) ; // Invalid characters 999+ assert ! ( !SocketAddrOrHostname :: is_valid_hostname(
1000+ "example.com:8080:extra"
1001+ ) ) ; // Multiple colons
1002+ assert ! ( !SocketAddrOrHostname :: is_valid_hostname(
1003+ 1004+ ) ) ; // Invalid characters
9961005 }
9971006
9981007 #[ test]
0 commit comments