From ee3e812186e56a574a6e289cc8f2b9134c5396fc Mon Sep 17 00:00:00 2001 From: xodn348 Date: Sat, 2 May 2026 05:16:56 +0000 Subject: [PATCH] fix(proxy): wire general_settings.user_url_validation/user_url_allowed_hosts to litellm globals --- litellm/proxy/proxy_server.py | 9 ++++ .../test_proxy_config_unit_test.py | 54 +++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 7893673ec5f..dcb846a177d 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -4060,6 +4060,15 @@ class ProxyConfig: raise ValueError( "allowed_ips is an Enterprise Feature. Please add a valid LITELLM_LICENSE to your envionment." ) + ## URL VALIDATION SETTINGS ## + _user_url_validation = general_settings.get("user_url_validation", None) + if _user_url_validation is not None: + litellm.user_url_validation = bool(_user_url_validation) + _user_url_allowed_hosts = general_settings.get( + "user_url_allowed_hosts", None + ) + if _user_url_allowed_hosts is not None: + litellm.user_url_allowed_hosts = list(_user_url_allowed_hosts) ## BUDGET RESCHEDULER ## proxy_budget_rescheduler_min_time = general_settings.get( "proxy_budget_rescheduler_min_time", proxy_budget_rescheduler_min_time diff --git a/tests/proxy_unit_tests/test_proxy_config_unit_test.py b/tests/proxy_unit_tests/test_proxy_config_unit_test.py index 36cd08fa5f5..faa60636886 100644 --- a/tests/proxy_unit_tests/test_proxy_config_unit_test.py +++ b/tests/proxy_unit_tests/test_proxy_config_unit_test.py @@ -316,3 +316,57 @@ async def test_json_logs_calls_turn_on_json(): # Cleanup os.unlink(temp_file_path) litellm.json_logs = False + + +@pytest.mark.asyncio +async def test_general_settings_url_validation_wired_to_litellm(): + """ + Regression test for https://github.com/BerriAI/litellm/issues/26599 + + user_url_validation and user_url_allowed_hosts set in general_settings must be + propagated to litellm module globals so that url_utils.validate_url / + safe_get / async_safe_get honour them at runtime. + """ + import tempfile + + import yaml + + config_content = { + "model_list": [ + { + "model_name": "test-model", + "litellm_params": {"model": "openai/gpt-4", "api_key": "test-key"}, + } + ], + "general_settings": { + "user_url_validation": False, + "user_url_allowed_hosts": ["10.80.1.20", "internal.corp"], + }, + } + + with tempfile.NamedTemporaryFile( + mode="w", suffix=".yaml", delete=False + ) as temp_file: + yaml.dump(config_content, temp_file) + temp_file_path = temp_file.name + + original_validation = litellm.user_url_validation + original_hosts = litellm.user_url_allowed_hosts + + try: + proxy_config = ProxyConfig() + await proxy_config.load_config( + router=None, + config_file_path=temp_file_path, + ) + + assert litellm.user_url_validation is False, ( + "user_url_validation from general_settings should set litellm.user_url_validation" + ) + assert litellm.user_url_allowed_hosts == ["10.80.1.20", "internal.corp"], ( + "user_url_allowed_hosts from general_settings should set litellm.user_url_allowed_hosts" + ) + finally: + os.unlink(temp_file_path) + litellm.user_url_validation = original_validation + litellm.user_url_allowed_hosts = original_hosts