-
Notifications
You must be signed in to change notification settings - Fork 40
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
Add Foundry client and server #61
base: main
Are you sure you want to change the base?
Conversation
|
||
def _matcher(request: requests.Request) -> requests.Response | None: | ||
"""Mock requests that check for the existence of blobs.""" | ||
if "blob.core.windows.net/" in request.url: |
Check failure
Code scanning / CodeQL
Incomplete URL substring sanitization High test
blob.core.windows.net/
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 8 hours ago
To fix the problem, we need to parse the URL and check the hostname properly instead of using a substring check. This can be done using the urlparse
function from the urllib.parse
module. We will extract the hostname from the URL and ensure it matches the expected host "blob.core.windows.net".
- Parse the URL using
urlparse
. - Extract the hostname from the parsed URL.
- Check if the hostname matches "blob.core.windows.net".
- Update the code in the
_matcher
function to implement these changes.
-
Copy modified lines R19-R21 -
Copy modified line R23 -
Copy modified line R25
@@ -18,7 +18,9 @@ | ||
"""Mock requests that check for the existence of blobs.""" | ||
if "blob.core.windows.net/" in request.url: | ||
from urllib.parse import urlparse | ||
parsed_url = urlparse(request.url) | ||
if parsed_url.hostname == "blob.core.windows.net": | ||
# Split off the SAS token. | ||
path, _ = request.url.split("?", 1) | ||
path, _ = parsed_url.path.split("?", 1) | ||
# Split off the storage account URL. | ||
_, path = path.split("blob.core.windows.net/", 1) | ||
path = path.lstrip('/') | ||
|
|
||
def _matcher(request: requests.Request) -> requests.Response | None: | ||
"""Mock requests that check for the existence of blobs.""" | ||
if "blob.core.windows.net/" in request.url: |
Check failure
Code scanning / CodeQL
Incomplete URL substring sanitization High test
blob.core.windows.net/
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 8 hours ago
To fix the problem, we need to parse the URL and check its hostname to ensure it matches the expected domain. This can be done using the urlparse
function from the urllib.parse
module. Specifically, we should extract the hostname from the URL and verify that it ends with "blob.core.windows.net".
- Parse the URL using
urlparse
. - Extract the hostname from the parsed URL.
- Check if the hostname ends with "blob.core.windows.net".
- Update the
_matcher
function to implement these changes.
-
Copy modified lines R58-R60
@@ -57,3 +57,5 @@ | ||
"""Mock requests that check for the existence of blobs.""" | ||
if "blob.core.windows.net/" in request.url: | ||
from urllib.parse import urlparse | ||
parsed_url = urlparse(request.url) | ||
if parsed_url.hostname and parsed_url.hostname.endswith("blob.core.windows.net"): | ||
# Split off the SAS token. |
|
||
def _matcher(request: requests.Request) -> requests.Response | None: | ||
"""Mock requests that check for the existence of blobs.""" | ||
if "blob.core.windows.net/" in request.url: |
Check failure
Code scanning / CodeQL
Incomplete URL substring sanitization High test
blob.core.windows.net/
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 5 hours ago
To fix the problem, we need to parse the URL and check the hostname instead of performing a substring check on the raw URL string. This ensures that the check is accurate and not prone to bypasses.
- Use the
urlparse
function from theurllib.parse
module to parse the URL. - Extract the hostname from the parsed URL and check if it matches the expected hostname "blob.core.windows.net".
- Update the
_matcher
function to perform this check.
-
Copy modified line R10 -
Copy modified lines R104-R105 -
Copy modified line R107
@@ -9,2 +9,3 @@ | ||
from typing import Generator | ||
from urllib.parse import urlparse | ||
|
||
@@ -102,7 +103,6 @@ | ||
"""Mock requests that check for the existence of blobs.""" | ||
if "blob.core.windows.net/" in request.url: | ||
parsed_url = urlparse(request.url) | ||
if parsed_url.hostname == "blob.core.windows.net": | ||
# Split off the SAS token. | ||
path, _ = request.url.split("?", 1) | ||
# Split off the storage account URL. | ||
_, path = path.split("blob.core.windows.net/", 1) | ||
path = parsed_url.path.lstrip('/') | ||
|
|
||
def _matcher(request: requests.Request) -> requests.Response | None: | ||
"""Mock requests that check for the existence of blobs.""" | ||
if "blob.core.windows.net/" in request.url: |
Check failure
Code scanning / CodeQL
Incomplete URL substring sanitization High test
blob.core.windows.net/
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 5 hours ago
To fix the problem, we should parse the URL and check the hostname instead of using a substring check. This ensures that the check is performed on the correct part of the URL and prevents bypassing the security check by embedding the allowed host in an unexpected location.
The best way to fix the problem is to use the urlparse
function from the urllib.parse
module to extract the hostname from the URL and then check if it matches the expected hostname. This approach is more robust and aligns with the recommended practices.
-
Copy modified lines R103-R105 -
Copy modified line R107
@@ -102,7 +102,7 @@ | ||
"""Mock requests that check for the existence of blobs.""" | ||
if "blob.core.windows.net/" in request.url: | ||
from urllib.parse import urlparse | ||
parsed_url = urlparse(request.url) | ||
if parsed_url.hostname == "blob.core.windows.net": | ||
# Split off the SAS token. | ||
path, _ = request.url.split("?", 1) | ||
# Split off the storage account URL. | ||
_, path = path.split("blob.core.windows.net/", 1) | ||
path, _ = parsed_url.path.split("?", 1) | ||
|
Add code and documentation for a Foundry client and server.