-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Litellm azure ai dev fix #8857
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
Litellm azure ai dev fix #8857
Conversation
The latest updates on your projects. Learn more about Vercel for Git βοΈ
|
""" | ||
Returns True if the request should use `api-key` header for authentication. | ||
""" | ||
if "services.ai.azure.com" in api_base or "openai.azure.com" in api_base: |
Check failure
Code scanning / CodeQL
Incomplete URL substring sanitization High
services.ai.azure.com
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 months ago
To fix the problem, we need to parse the URL and check the hostname explicitly rather than using a substring check. This ensures that the check is performed on the actual host part of the URL, preventing bypasses through embedding.
The best way to fix the problem without changing existing functionality is to use the urlparse
function from the urllib.parse
module to extract the hostname from the api_base
URL and then check if it matches the allowed hosts.
We will modify the _should_use_api_key_header
method to parse the URL and check the hostname. This change will be made in the file litellm/llms/azure_ai/chat/transformation.py
.
-
Copy modified lines R42-R45
@@ -41,3 +41,6 @@ | ||
""" | ||
if "services.ai.azure.com" in api_base or "openai.azure.com" in api_base: | ||
from urllib.parse import urlparse | ||
parsed_url = urlparse(api_base) | ||
host = parsed_url.hostname | ||
if host and (host.endswith("services.ai.azure.com") or host.endswith("openai.azure.com")): | ||
return True |
""" | ||
Returns True if the request should use `api-key` header for authentication. | ||
""" | ||
if "services.ai.azure.com" in api_base or "openai.azure.com" in api_base: |
Check failure
Code scanning / CodeQL
Incomplete URL substring sanitization High
openai.azure.com
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 months ago
To fix the problem, we should parse the URL using a proper URL parsing library and then check the hostname to ensure it matches the expected domain. This approach is more robust and prevents the possibility of bypassing the check by embedding the allowed host in an unexpected location.
- We will use the
urlparse
function from theurllib.parse
module to parse the URL. - We will then check if the hostname of the parsed URL ends with the expected domain.
-
Copy modified line R5 -
Copy modified lines R43-R44
@@ -4,2 +4,3 @@ | ||
from httpx import Response | ||
from urllib.parse import urlparse | ||
|
||
@@ -41,3 +42,4 @@ | ||
""" | ||
if "services.ai.azure.com" in api_base or "openai.azure.com" in api_base: | ||
parsed_url = urlparse(api_base) | ||
if parsed_url.hostname and (parsed_url.hostname.endswith("services.ai.azure.com") or parsed_url.hostname.endswith("openai.azure.com")): | ||
return True |
Title
Relevant issues
Type
π New Feature
π Bug Fix
π§Ή Refactoring
π Documentation
π Infrastructure
β Test
Changes
[REQUIRED] Testing - Attach a screenshot of any new tests passing locally
If UI changes, send a screenshot/GIF of working UI fixes