Skip to content

Commit 97e6a6f

Browse files
authored
Merge pull request #47 from arpitjain099/alert-autofix-22
Fix code scanning alert no. 22: Full server-side request forgery
2 parents 0466d2c + cc58473 commit 97e6a6f

File tree

1 file changed

+14
-1
lines changed
  • End_to_end_Solutions/AOAISearchDemo/app/backend/data_client

1 file changed

+14
-1
lines changed

End_to_end_Solutions/AOAISearchDemo/app/backend/data_client/data_client.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)