Skip to content
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
wants to merge 78 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
631666b
Update CONTRIBUTING.md
arpitjain099 Oct 20, 2024
e128466
Fix code scanning alert no. 27: Information exposure through an excep…
arpitjain099 Oct 20, 2024
28ba282
Fix code scanning alert no. 3: DOM text reinterpreted as HTML
arpitjain099 Oct 20, 2024
3e2e469
Fix code scanning alert no. 57: Information exposure through an excep…
arpitjain099 Oct 20, 2024
091e80a
Fix code scanning alert no. 49: Information exposure through an excep…
arpitjain099 Oct 20, 2024
86c2346
Fix code scanning alert no. 9: Reflected server-side cross-site scrip…
arpitjain099 Oct 20, 2024
fd98ac4
Fix code scanning alert no. 2: DOM text reinterpreted as HTML
arpitjain099 Oct 20, 2024
ef5c46d
Merge pull request #18 from arpitjain099/alert-autofix-2
arpitjain099 Oct 20, 2024
cf24ac2
Merge pull request #17 from arpitjain099/alert-autofix-9
arpitjain099 Oct 20, 2024
75d1e85
Merge pull request #16 from arpitjain099/alert-autofix-49
arpitjain099 Oct 20, 2024
e40c6cf
Fix code scanning alert no. 56: Information exposure through an excep…
arpitjain099 Oct 20, 2024
a45d967
Fix code scanning alert no. 63: Information exposure through an excep…
arpitjain099 Oct 20, 2024
055a78b
Fix code scanning alert no. 51: Information exposure through an excep…
arpitjain099 Oct 20, 2024
91f1919
Merge pull request #20 from arpitjain099/alert-autofix-51
arpitjain099 Oct 20, 2024
760c74a
Merge pull request #19 from arpitjain099/alert-autofix-63
arpitjain099 Oct 20, 2024
df67a2e
Fix code scanning alert no. 64: Information exposure through an excep…
arpitjain099 Oct 20, 2024
61d6b9d
Fix code scanning alert no. 8: Reflected server-side cross-site scrip…
arpitjain099 Oct 20, 2024
b2414ef
Fix code scanning alert no. 10: Reflected server-side cross-site scri…
arpitjain099 Oct 20, 2024
aebd8e8
Fix code scanning alert no. 11: Reflected server-side cross-site scri…
arpitjain099 Oct 20, 2024
8bf43ae
Fix code scanning alert no. 12: Reflected server-side cross-site scri…
arpitjain099 Oct 20, 2024
cde4d70
Fix code scanning alert no. 13: Reflected server-side cross-site scri…
arpitjain099 Oct 20, 2024
7611246
Fix code scanning alert no. 14: Reflected server-side cross-site scri…
arpitjain099 Oct 20, 2024
238b125
Fix code scanning alert no. 30: Information exposure through an excep…
arpitjain099 Oct 20, 2024
84948e2
Fix code scanning alert no. 32: Information exposure through an excep…
arpitjain099 Oct 20, 2024
3b469ab
Fix code scanning alert no. 33: Information exposure through an excep…
arpitjain099 Oct 20, 2024
163c963
Fix code scanning alert no. 28: Information exposure through an excep…
arpitjain099 Oct 20, 2024
f9b0a70
Fix code scanning alert no. 31: Information exposure through an excep…
arpitjain099 Oct 20, 2024
d9b5979
Fix code scanning alert no. 29: Information exposure through an excep…
arpitjain099 Oct 20, 2024
59a4a6c
Fix code scanning alert no. 34: Information exposure through an excep…
arpitjain099 Oct 20, 2024
5017ff3
Fix code scanning alert no. 35: Information exposure through an excep…
arpitjain099 Oct 20, 2024
015da9a
Merge pull request #21 from arpitjain099/alert-autofix-64
arpitjain099 Oct 20, 2024
23fa24b
Merge pull request #22 from arpitjain099/alert-autofix-8
arpitjain099 Oct 20, 2024
d9d0a70
Merge pull request #23 from arpitjain099/alert-autofix-10
arpitjain099 Oct 20, 2024
4b5e65e
Merge pull request #24 from arpitjain099/alert-autofix-11
arpitjain099 Oct 20, 2024
f9579e6
Merge pull request #35 from arpitjain099/alert-autofix-35
arpitjain099 Oct 20, 2024
8320f4a
Merge pull request #33 from arpitjain099/alert-autofix-29
arpitjain099 Oct 20, 2024
7c5b15f
Merge pull request #32 from arpitjain099/alert-autofix-31
arpitjain099 Oct 20, 2024
cdd94c5
Merge branch 'codeql' into alert-autofix-33
arpitjain099 Oct 20, 2024
3381420
Merge pull request #29 from arpitjain099/alert-autofix-32
arpitjain099 Oct 20, 2024
81df4d7
Merge pull request #28 from arpitjain099/alert-autofix-30
arpitjain099 Oct 20, 2024
97d7256
Merge pull request #27 from arpitjain099/alert-autofix-14
arpitjain099 Oct 20, 2024
611af8e
Merge pull request #26 from arpitjain099/alert-autofix-13
arpitjain099 Oct 20, 2024
10c9d0f
Merge pull request #25 from arpitjain099/alert-autofix-12
arpitjain099 Oct 20, 2024
0cdfd43
Merge branch 'codeql' into alert-autofix-34
arpitjain099 Oct 20, 2024
9a933a4
Merge pull request #30 from arpitjain099/alert-autofix-33
arpitjain099 Oct 20, 2024
26a0d0f
Merge pull request #34 from arpitjain099/alert-autofix-34
arpitjain099 Oct 20, 2024
f40c656
Merge branch 'codeql' into alert-autofix-28
arpitjain099 Oct 20, 2024
98b4f8e
Merge pull request #31 from arpitjain099/alert-autofix-28
arpitjain099 Oct 20, 2024
ddc261a
Fix code scanning alert no. 18: Full server-side request forgery
arpitjain099 Oct 20, 2024
1dac837
Merge pull request #36 from arpitjain099/alert-autofix-18
arpitjain099 Oct 20, 2024
dc2a53c
Fix code scanning alert no. 66: Information exposure through an excep…
arpitjain099 Oct 20, 2024
0f8533a
Fix code scanning alert no. 45: Information exposure through an excep…
arpitjain099 Oct 20, 2024
2075149
Fix code scanning alert no. 39: Information exposure through an excep…
arpitjain099 Oct 20, 2024
4f1b260
Fix code scanning alert no. 38: Information exposure through an excep…
arpitjain099 Oct 20, 2024
d3640fd
Fix code scanning alert no. 42: Information exposure through an excep…
arpitjain099 Oct 20, 2024
178266e
Fix code scanning alert no. 41: Information exposure through an excep…
arpitjain099 Oct 20, 2024
332552f
Merge pull request #37 from arpitjain099/alert-autofix-66
arpitjain099 Oct 20, 2024
8a8865e
Merge pull request #38 from arpitjain099/alert-autofix-45
arpitjain099 Oct 20, 2024
b1a1327
Merge pull request #39 from arpitjain099/alert-autofix-39
arpitjain099 Oct 20, 2024
2e19f99
Merge pull request #40 from arpitjain099/alert-autofix-38
arpitjain099 Oct 20, 2024
214ebd7
Merge branch 'codeql' into alert-autofix-42
arpitjain099 Oct 20, 2024
6c416f5
Merge pull request #41 from arpitjain099/alert-autofix-42
arpitjain099 Oct 20, 2024
f847274
Merge branch 'codeql' into alert-autofix-41
arpitjain099 Oct 20, 2024
00027f8
Merge pull request #42 from arpitjain099/alert-autofix-41
arpitjain099 Oct 20, 2024
f6456ee
Fix code scanning alert no. 24: Information exposure through an excep…
arpitjain099 Oct 20, 2024
bc8c79f
Merge pull request #43 from arpitjain099/alert-autofix-24
arpitjain099 Oct 20, 2024
409e515
Fix code scanning alert no. 67: Information exposure through an excep…
arpitjain099 Oct 20, 2024
0a9d856
Fix code scanning alert no. 65: Information exposure through an excep…
arpitjain099 Oct 20, 2024
d8e6936
Fix code scanning alert no. 38: Information exposure through an excep…
arpitjain099 Oct 20, 2024
18eebbf
Merge pull request #44 from arpitjain099/alert-autofix-67
arpitjain099 Oct 20, 2024
1355a3a
Merge pull request #45 from arpitjain099/alert-autofix-65
arpitjain099 Oct 20, 2024
0466d2c
Merge pull request #46 from arpitjain099/alert-autofix-38
arpitjain099 Oct 20, 2024
cc58473
Fix code scanning alert no. 22: Full server-side request forgery
arpitjain099 Oct 20, 2024
97e6a6f
Merge pull request #47 from arpitjain099/alert-autofix-22
arpitjain099 Oct 20, 2024
5a9bb05
Fix code scanning alert no. 22: Full server-side request forgery
arpitjain099 Oct 20, 2024
a9b392e
Fix code scanning alert no. 18: Full server-side request forgery
arpitjain099 Oct 20, 2024
5f4aa39
Merge pull request #49 from arpitjain099/alert-autofix-18
arpitjain099 Oct 20, 2024
029a87f
Merge pull request #48 from arpitjain099/alert-autofix-22
arpitjain099 Oct 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ a proposal for your work first, to be sure that we can use it.
## <a name="submit"></a> Submission Guidelines

### <a name="submit-issue"></a> Submitting an Issue
Before you submit an issue, search the archive, maybe your question was already answered.
Before you submit an issue, search the archive, maybe your question has already been answered.

If your issue appears to be a bug, and hasn't been reported, open a new issue.
Help us to maximize the effort we can spend fixing issues and adding new
Expand Down
8 changes: 4 additions & 4 deletions End_to_end_Solutions/AOAISearchDemo/app/backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def chat():
return jsonify(response.to_item()), 400
except Exception as e:
logger.exception(f"Exception in /chat: {e}", extra=properties)
response = ChatResponse(answer=Answer(), error=str(e), show_retry=True)
response = ChatResponse(answer=Answer(), error="An internal error has occurred.", show_retry=True)
return jsonify(response.to_item()), 500


Expand All @@ -352,7 +352,7 @@ def get_all_user_profiles():
return jsonify(user_profiles_dict)
except Exception as e:
logger.exception(f"Exception in /user-profiles: {e}")
return jsonify({"error": str(e)}), 500
return jsonify({"error": "An internal error has occurred."}), 500


@app.route("/chat-sessions/<user_id>/<conversation_id>", methods=["DELETE"])
Expand All @@ -369,7 +369,7 @@ def clear_chat_session(user_id: str, conversation_id: str):
logger.exception(
f"Exception in /chat-sessions/<user_id>/<conversation_id>: {e}"
)
return jsonify({"error": str(e)}), 500
return jsonify({"error": "An internal error has occurred."}), 500


@app.route("/search-settings", methods=["GET"])
Expand All @@ -391,7 +391,7 @@ def get_search_settings():
return jsonify(search_settings.to_item())
except Exception as e:
logger.exception(f"Exception in /search-settings: {e}")
return jsonify({"error": str(e)}), 500
return jsonify({"error": "An internal error has occurred."}), 500


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Comment on lines +15 to +30
Copy link
Collaborator

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


def _validate_path(self, path: str):
if not path.startswith("/"):
raise ValueError("Invalid path")

class DataClient:
class HttpMethod(Enum):
Expand All @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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}"
Expand Down Expand Up @@ -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)
Expand Down
Loading