-
Notifications
You must be signed in to change notification settings - Fork 400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code Scanning security alert fixes #129
Open
arpitjain099
wants to merge
78
commits into
Azure-Samples:main
Choose a base branch
from
arpitjain099:codeql
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
78 commits
Select commit
Hold shift + click to select a range
631666b
Update CONTRIBUTING.md
arpitjain099 e128466
Fix code scanning alert no. 27: Information exposure through an excep…
arpitjain099 28ba282
Fix code scanning alert no. 3: DOM text reinterpreted as HTML
arpitjain099 3e2e469
Fix code scanning alert no. 57: Information exposure through an excep…
arpitjain099 091e80a
Fix code scanning alert no. 49: Information exposure through an excep…
arpitjain099 86c2346
Fix code scanning alert no. 9: Reflected server-side cross-site scrip…
arpitjain099 fd98ac4
Fix code scanning alert no. 2: DOM text reinterpreted as HTML
arpitjain099 ef5c46d
Merge pull request #18 from arpitjain099/alert-autofix-2
arpitjain099 cf24ac2
Merge pull request #17 from arpitjain099/alert-autofix-9
arpitjain099 75d1e85
Merge pull request #16 from arpitjain099/alert-autofix-49
arpitjain099 e40c6cf
Fix code scanning alert no. 56: Information exposure through an excep…
arpitjain099 a45d967
Fix code scanning alert no. 63: Information exposure through an excep…
arpitjain099 055a78b
Fix code scanning alert no. 51: Information exposure through an excep…
arpitjain099 91f1919
Merge pull request #20 from arpitjain099/alert-autofix-51
arpitjain099 760c74a
Merge pull request #19 from arpitjain099/alert-autofix-63
arpitjain099 df67a2e
Fix code scanning alert no. 64: Information exposure through an excep…
arpitjain099 61d6b9d
Fix code scanning alert no. 8: Reflected server-side cross-site scrip…
arpitjain099 b2414ef
Fix code scanning alert no. 10: Reflected server-side cross-site scri…
arpitjain099 aebd8e8
Fix code scanning alert no. 11: Reflected server-side cross-site scri…
arpitjain099 8bf43ae
Fix code scanning alert no. 12: Reflected server-side cross-site scri…
arpitjain099 cde4d70
Fix code scanning alert no. 13: Reflected server-side cross-site scri…
arpitjain099 7611246
Fix code scanning alert no. 14: Reflected server-side cross-site scri…
arpitjain099 238b125
Fix code scanning alert no. 30: Information exposure through an excep…
arpitjain099 84948e2
Fix code scanning alert no. 32: Information exposure through an excep…
arpitjain099 3b469ab
Fix code scanning alert no. 33: Information exposure through an excep…
arpitjain099 163c963
Fix code scanning alert no. 28: Information exposure through an excep…
arpitjain099 f9b0a70
Fix code scanning alert no. 31: Information exposure through an excep…
arpitjain099 d9b5979
Fix code scanning alert no. 29: Information exposure through an excep…
arpitjain099 59a4a6c
Fix code scanning alert no. 34: Information exposure through an excep…
arpitjain099 5017ff3
Fix code scanning alert no. 35: Information exposure through an excep…
arpitjain099 015da9a
Merge pull request #21 from arpitjain099/alert-autofix-64
arpitjain099 23fa24b
Merge pull request #22 from arpitjain099/alert-autofix-8
arpitjain099 d9d0a70
Merge pull request #23 from arpitjain099/alert-autofix-10
arpitjain099 4b5e65e
Merge pull request #24 from arpitjain099/alert-autofix-11
arpitjain099 f9579e6
Merge pull request #35 from arpitjain099/alert-autofix-35
arpitjain099 8320f4a
Merge pull request #33 from arpitjain099/alert-autofix-29
arpitjain099 7c5b15f
Merge pull request #32 from arpitjain099/alert-autofix-31
arpitjain099 cdd94c5
Merge branch 'codeql' into alert-autofix-33
arpitjain099 3381420
Merge pull request #29 from arpitjain099/alert-autofix-32
arpitjain099 81df4d7
Merge pull request #28 from arpitjain099/alert-autofix-30
arpitjain099 97d7256
Merge pull request #27 from arpitjain099/alert-autofix-14
arpitjain099 611af8e
Merge pull request #26 from arpitjain099/alert-autofix-13
arpitjain099 10c9d0f
Merge pull request #25 from arpitjain099/alert-autofix-12
arpitjain099 0cdfd43
Merge branch 'codeql' into alert-autofix-34
arpitjain099 9a933a4
Merge pull request #30 from arpitjain099/alert-autofix-33
arpitjain099 26a0d0f
Merge pull request #34 from arpitjain099/alert-autofix-34
arpitjain099 f40c656
Merge branch 'codeql' into alert-autofix-28
arpitjain099 98b4f8e
Merge pull request #31 from arpitjain099/alert-autofix-28
arpitjain099 ddc261a
Fix code scanning alert no. 18: Full server-side request forgery
arpitjain099 1dac837
Merge pull request #36 from arpitjain099/alert-autofix-18
arpitjain099 dc2a53c
Fix code scanning alert no. 66: Information exposure through an excep…
arpitjain099 0f8533a
Fix code scanning alert no. 45: Information exposure through an excep…
arpitjain099 2075149
Fix code scanning alert no. 39: Information exposure through an excep…
arpitjain099 4f1b260
Fix code scanning alert no. 38: Information exposure through an excep…
arpitjain099 d3640fd
Fix code scanning alert no. 42: Information exposure through an excep…
arpitjain099 178266e
Fix code scanning alert no. 41: Information exposure through an excep…
arpitjain099 332552f
Merge pull request #37 from arpitjain099/alert-autofix-66
arpitjain099 8a8865e
Merge pull request #38 from arpitjain099/alert-autofix-45
arpitjain099 b1a1327
Merge pull request #39 from arpitjain099/alert-autofix-39
arpitjain099 2e19f99
Merge pull request #40 from arpitjain099/alert-autofix-38
arpitjain099 214ebd7
Merge branch 'codeql' into alert-autofix-42
arpitjain099 6c416f5
Merge pull request #41 from arpitjain099/alert-autofix-42
arpitjain099 f847274
Merge branch 'codeql' into alert-autofix-41
arpitjain099 00027f8
Merge pull request #42 from arpitjain099/alert-autofix-41
arpitjain099 f6456ee
Fix code scanning alert no. 24: Information exposure through an excep…
arpitjain099 bc8c79f
Merge pull request #43 from arpitjain099/alert-autofix-24
arpitjain099 409e515
Fix code scanning alert no. 67: Information exposure through an excep…
arpitjain099 0a9d856
Fix code scanning alert no. 65: Information exposure through an excep…
arpitjain099 d8e6936
Fix code scanning alert no. 38: Information exposure through an excep…
arpitjain099 18eebbf
Merge pull request #44 from arpitjain099/alert-autofix-67
arpitjain099 1355a3a
Merge pull request #45 from arpitjain099/alert-autofix-65
arpitjain099 0466d2c
Merge pull request #46 from arpitjain099/alert-autofix-38
arpitjain099 cc58473
Fix code scanning alert no. 22: Full server-side request forgery
arpitjain099 97e6a6f
Merge pull request #47 from arpitjain099/alert-autofix-22
arpitjain099 5a9bb05
Fix code scanning alert no. 22: Full server-side request forgery
arpitjain099 a9b392e
Fix code scanning alert no. 18: Full server-side request forgery
arpitjain099 5f4aa39
Merge pull request #49 from arpitjain099/alert-autofix-18
arpitjain099 029a87f
Merge pull request #48 from arpitjain099/alert-autofix-22
arpitjain099 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,26 @@ | |
from typing import List, Optional | ||
|
||
from common.logging.log_helper import CustomLogger | ||
from urllib.parse import urlparse | ||
from urllib.parse import urlparse, urljoin | ||
|
||
def _validate_base_uri(self, base_uri: str): | ||
parsed_uri = urlparse(base_uri) | ||
if parsed_uri.scheme not in ["http", "https"]: | ||
raise ValueError("Invalid URI scheme") | ||
if not parsed_uri.netloc: | ||
raise ValueError("Invalid URI netloc") | ||
|
||
def _validate_base_uri(self, base_uri: str): | ||
parsed_uri = urlparse(base_uri) | ||
if parsed_uri.scheme not in ["http", "https"]: | ||
raise ValueError("Invalid URI scheme") | ||
if not parsed_uri.netloc: | ||
raise ValueError("Invalid URI netloc") | ||
|
||
def _validate_path(self, path: str): | ||
if not path.startswith("/"): | ||
raise ValueError("Invalid path") | ||
|
||
class DataClient: | ||
class HttpMethod(Enum): | ||
|
@@ -21,8 +41,22 @@ class HttpMethod(Enum): | |
DELETE="DELETE" | ||
|
||
def __init__(self, base_uri: str, logger: CustomLogger): | ||
self._validate_base_uri(base_uri) | ||
self.base_uri = base_uri | ||
self.base_uri = self._validate_base_uri(base_uri) | ||
self.logger = logger | ||
|
||
def _validate_base_uri(self, base_uri: str) -> str: | ||
# Ensure the base_uri is a trusted URL | ||
if not base_uri.startswith("https://trusted-domain.com"): | ||
raise ValueError("Invalid base URI") | ||
return base_uri | ||
|
||
def _sanitize_path(self, path: str) -> str: | ||
# Sanitize the path to prevent malicious input | ||
if ".." in path or path.startswith("/"): | ||
raise ValueError("Invalid path") | ||
return path | ||
Comment on lines
+49
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need these? Can't we use the functions we defined above? |
||
|
||
def check_chat_session(self, user_id: str, conversation_id: str) -> bool: | ||
path = f"/check-chat-session/{user_id}/{conversation_id}" | ||
|
@@ -113,6 +147,8 @@ def get_user_resources(self, user_id: str) -> List[ResourceProfile]: | |
|
||
@retry(reraise=True, stop = stop_after_attempt(3), wait = wait_exponential(multiplier = 1, max = 60)) | ||
def _make_request(self, path: str, method: HttpMethod, payload: Optional[dict] = None) -> str: | ||
path = self._sanitize_path(path) | ||
self._validate_path(path) | ||
|
||
headers = self.logger.get_converation_and_dialog_ids() | ||
properties = self.logger.get_updated_properties(headers) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we have duplicate code here