@@ -10,7 +10,7 @@ use spin_world::v1::redis::{self as v1, RedisParameter, RedisResult};
1010use spin_world:: v2:: redis:: { self as v2, Connection as RedisConnection , Error } ;
1111
1212pub const ALLOWED_REDIS_HOSTS_KEY : MetadataKey < Option < HashSet < String > > > =
13- MetadataKey :: new ( "allowed_redis_hosts " ) ;
13+ MetadataKey :: new ( "allowed_outbound_hosts " ) ;
1414
1515pub use host_component:: OutboundRedisComponent ;
1616
@@ -50,21 +50,21 @@ impl Default for OutboundRedis {
5050
5151impl OutboundRedis {
5252 fn is_address_allowed ( & self , address : & str , default : bool ) -> bool {
53- fn do_check ( allowed_hosts : Option < & HashSet < String > > , address : & str , default : bool ) -> bool {
54- let Some ( allowed_hosts) = allowed_hosts else {
55- return default;
56- } ;
57- allowed_hosts. contains ( address)
58- }
53+ let url = url:: Url :: parse ( address) . ok ( ) ;
54+ let host = url. as_ref ( ) . and_then ( |u| u. host_str ( ) ) . unwrap_or ( address) ;
55+ let is_allowed = if let Some ( allowed_hosts) = self . allowed_hosts . as_ref ( ) {
56+ allowed_hosts. contains ( host)
57+ } else {
58+ default
59+ } ;
5960
60- let response = do_check ( self . allowed_hosts . as_ref ( ) , address, default) ;
61- if !response {
61+ if !is_allowed {
6262 terminal:: warn!(
6363 "A component tried to make a HTTP request to non-allowed address {address:?}."
6464 ) ;
65- eprintln ! ( "To allow requests, add 'allowed_redis_hosts = [{address :?}]' to the manifest component section." ) ;
65+ eprintln ! ( "To allow requests, add 'allowed_outbound_hosts = [{host :?}]' to the manifest component section." ) ;
6666 }
67- response
67+ is_allowed
6868 }
6969
7070 async fn establish_connection (
0 commit comments