Skip to content

Commit 5a9bb05

Browse files
Fix code scanning alert no. 22: Full server-side request forgery
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 97e6a6f commit 5a9bb05

File tree

1 file changed

+23
-0
lines changed
  • End_to_end_Solutions/AOAISearchDemo/app/backend/data_client

1 file changed

+23
-0
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,26 @@
1212
from typing import List, Optional
1313

1414
from common.logging.log_helper import CustomLogger
15+
from urllib.parse import urlparse
16+
from urllib.parse import urlparse, urljoin
17+
18+
def _validate_base_uri(self, base_uri: str):
19+
parsed_uri = urlparse(base_uri)
20+
if parsed_uri.scheme not in ["http", "https"]:
21+
raise ValueError("Invalid URI scheme")
22+
if not parsed_uri.netloc:
23+
raise ValueError("Invalid URI netloc")
24+
25+
def _validate_base_uri(self, base_uri: str):
26+
parsed_uri = urlparse(base_uri)
27+
if parsed_uri.scheme not in ["http", "https"]:
28+
raise ValueError("Invalid URI scheme")
29+
if not parsed_uri.netloc:
30+
raise ValueError("Invalid URI netloc")
31+
32+
def _validate_path(self, path: str):
33+
if not path.startswith("/"):
34+
raise ValueError("Invalid path")
1535

1636
class DataClient:
1737
class HttpMethod(Enum):
@@ -21,6 +41,8 @@ class HttpMethod(Enum):
2141
DELETE="DELETE"
2242

2343
def __init__(self, base_uri: str, logger: CustomLogger):
44+
self._validate_base_uri(base_uri)
45+
self.base_uri = base_uri
2446
self.base_uri = self._validate_base_uri(base_uri)
2547
self.logger = logger
2648

@@ -126,6 +148,7 @@ def get_user_resources(self, user_id: str) -> List[ResourceProfile]:
126148
@retry(reraise=True, stop = stop_after_attempt(3), wait = wait_exponential(multiplier = 1, max = 60))
127149
def _make_request(self, path: str, method: HttpMethod, payload: Optional[dict] = None) -> str:
128150
path = self._sanitize_path(path)
151+
self._validate_path(path)
129152

130153
headers = self.logger.get_converation_and_dialog_ids()
131154
properties = self.logger.get_updated_properties(headers)

0 commit comments

Comments
 (0)