@@ -21,8 +21,20 @@ class HttpMethod(Enum):
2121 DELETE = "DELETE"
2222
2323 def __init__ (self , base_uri : str , logger : CustomLogger ):
24- self .base_uri = base_uri
24+ self .base_uri = self . _validate_base_uri ( base_uri )
2525 self .logger = logger
26+
27+ def _validate_base_uri (self , base_uri : str ) -> str :
28+ # Ensure the base_uri is a trusted URL
29+ if not base_uri .startswith ("https://trusted-domain.com" ):
30+ raise ValueError ("Invalid base URI" )
31+ return base_uri
32+
33+ def _sanitize_path (self , path : str ) -> str :
34+ # Sanitize the path to prevent malicious input
35+ if ".." in path or path .startswith ("/" ):
36+ raise ValueError ("Invalid path" )
37+ return path
2638
2739 def check_chat_session (self , user_id : str , conversation_id : str ) -> bool :
2840 path = f"/check-chat-session/{ user_id } /{ conversation_id } "
@@ -113,6 +125,7 @@ def get_user_resources(self, user_id: str) -> List[ResourceProfile]:
113125
114126 @retry (reraise = True , stop = stop_after_attempt (3 ), wait = wait_exponential (multiplier = 1 , max = 60 ))
115127 def _make_request (self , path : str , method : HttpMethod , payload : Optional [dict ] = None ) -> str :
128+ path = self ._sanitize_path (path )
116129
117130 headers = self .logger .get_converation_and_dialog_ids ()
118131 properties = self .logger .get_updated_properties (headers )
0 commit comments