litellm/tests/test_litellm/proxy
Talal 5e10ea4136
Improve(mcp): respect X-Forwarded- headers in OAuth endpoints (#16036)
* fix(mcp): respect X-Forwarded-Proto header in OAuth endpoints

When LiteLLM proxy is deployed behind a reverse proxy (like nginx or a load balancer) that terminates SSL/TLS, the proxy receives HTTP requests internally but should expose HTTPS URLs externally. This change detects the X-Forwarded-Proto header and uses it to construct correct redirect URIs and endpoint URLs.

Changes:
- Added X-Forwarded-Proto detection to authorize, token, oauth_protected_resource_mcp, oauth_authorization_server_mcp, and register_client endpoints
- Added comprehensive tests for X-Forwarded-Proto header support across all affected endpoints
- Fixed existing tests to properly mock request.headers

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix formatting

* feat(mcp): support X-Forwarded-Host for proxy base URL reconstruction

Extended X-Forwarded-Proto support to also handle X-Forwarded-Host and X-Forwarded-Port headers. This allows LiteLLM to correctly construct redirect URIs and endpoint URLs when deployed behind a reverse proxy that changes the host/port.

Example scenario:
- Internal URL: http://localhost:8888/github/mcp
- External URL: https://proxy.abc.com/github/mcp
- Proxy sets: X-Forwarded-Proto: https, X-Forwarded-Host: proxy.abc.com

Changes:
- Added get_request_base_url() helper function to centralize X-Forwarded-* header handling
- Replaced all inline X-Forwarded-Proto checks with calls to the helper function
- Helper handles X-Forwarded-Proto, X-Forwarded-Host, and X-Forwarded-Port
- Added tests for X-Forwarded-Host scenarios in authorize and token endpoints

Fixes issue where protected resource URL mismatch occurred:
  Error: Protected resource http://proxy.abc.com:8888/github/mcp
  does not match expected https://proxy.abc.com/github/mcp

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* chore: replace Yelp-specific hostnames with generic examples

Changed all references from chatproxy.yelpcorp.com to proxy.example.com in:
- test_proxy_forwarding.py (default host parameter)
- TEST_PROXY_FORWARDING.md (documentation examples)
- discoverable_endpoints.py (docstring example)
- test_discoverable_endpoints.py (test mock data)

This makes the code more generic and suitable for open source.
All 13 tests still passing.

* remove accidentally added files

* fix formatting

* add new test for get_base_url

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-29 19:11:32 -07:00
..
_experimental/mcp_server Improve(mcp): respect X-Forwarded- headers in OAuth endpoints (#16036) 2025-10-29 19:11:32 -07:00
anthropic_endpoints
auth Fix Token Spend is under budget for passthrough (#15805) 2025-10-22 10:55:22 -07:00
client test fix 2025-09-26 11:06:26 -07:00
common_utils [Bug Fix] Tags as metadata dicts were raising exceptions (#15625) 2025-10-17 13:20:07 -07:00
db attempt to avoid/minimize deadlocks (#15281) 2025-10-24 12:22:38 -07:00
experimental/mcp_server
google_endpoints fix gemini cli by actually streaming the response (#15264) 2025-10-07 11:26:39 -07:00
guardrails feat(guardrails): Add per-request profile overrides to PANW Prisma AIRS (#16069) 2025-10-29 19:05:59 -07:00
health_endpoints
hooks Perf speed up pytest (#15951) 2025-10-27 19:43:40 -07:00
image_endpoints test fix 2025-10-17 10:46:42 -07:00
management_endpoints Perf speed up pytest (#15951) 2025-10-27 19:43:40 -07:00
management_helpers [MCP Gateway] Litellm mcp fixes team control (#15304) 2025-10-07 16:48:00 -07:00
middleware
openai_files_endpoint fix issue from pr review 2025-10-01 11:57:10 +08:00
pass_through_endpoints fixes exception handling 2025-10-25 16:55:16 -07:00
response_api_endpoints [Fix] - Responses API - add /openai routes for responses API. (Azure OpenAI SDK Compatibility) (#15988) 2025-10-27 19:12:13 -07:00
spend_tracking Perf speed up pytest (#15951) 2025-10-27 19:43:40 -07:00
test_configs
ui_crud_endpoints test: add UI theme settings retrieval and update tests 2025-09-30 10:01:44 -05:00
vector_store_endpoints [Feat] LLM API Endpoint - Expose OpenAI Compatible /vector_stores/{vector_store_id}/search endpoint (#12749) 2025-07-18 18:18:53 -07:00
__init__.py test fix 2025-10-17 10:46:42 -07:00
test_batch_metadata_none_fix.py Fix issue #13995: Handle None metadata in batch requests (#13996) 2025-08-27 14:51:09 -07:00
test_caching_routes.py
test_common_request_processing.py [Feat] Cost Tracking - specify a global vendor discount for costs. (#15546) 2025-10-14 20:07:04 -07:00
test_custom_proxy.py fix(ui/): fix routing for custom server root path (#15701) 2025-10-23 13:59:29 -07:00
test_fastapi_offline_routes.py [Bug Fix] - Get Routes (#13466) 2025-08-09 12:52:23 -07:00
test_health_check_functions.py
test_litellm_pre_call_utils.py [Fix] Guardrails - Ensure Key Guardrails are applied (#16025) 2025-10-28 16:40:49 -07:00
test_proxy_cli.py feature/add max requests env var 2025-09-28 19:18:56 +01:00
test_proxy_server.py [Feat] Tag Management - Add support for setting tag based budgets (#15433) 2025-10-10 19:24:50 -07:00
test_proxy_types.py
test_proxy_utils.py fix(ui/): fix routing for custom server root path (#15701) 2025-10-23 13:59:29 -07:00
test_route_llm_request.py Fix create, search vector store error (#13285) 2025-08-06 11:15:17 -07:00
test_shared_health_check.py Add shared healthcheck 2025-10-09 22:18:05 +05:30
test_spend_log_cleanup.py Fix/gemini api key environment variable support (#12507) 2025-07-29 15:56:01 -07:00
test_swagger_chat_completions.py [Bug Fix] Allow using Swagger for /chat/completions (#13469) 2025-08-09 15:35:45 -07:00
test_team_member_update.py