From b5f11bc4b2dea0c982917df359bd149d3fd2f409 Mon Sep 17 00:00:00 2001 From: codgician <15964984+codgician@users.noreply.github.com> Date: Tue, 28 Jul 2026 16:44:07 +0800 Subject: [PATCH] fix(github-copilot): narrow Enterprise host trust --- litellm/llms/github_copilot/authenticator.py | 4 +--- .../test_github_copilot_authenticator.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/litellm/llms/github_copilot/authenticator.py b/litellm/llms/github_copilot/authenticator.py index e7d84835fee..9f7c33c4487 100644 --- a/litellm/llms/github_copilot/authenticator.py +++ b/litellm/llms/github_copilot/authenticator.py @@ -58,9 +58,7 @@ def _is_trusted_api_base(api_base: str) -> bool: return True if hostname in _configured_allowed_api_hosts(): return True - return any( - hostname == oauth_host or hostname.endswith(f".{oauth_host}") for oauth_host in _configured_oauth_hosts() - ) + return any(hostname == f"copilot-api.{oauth_host}" for oauth_host in _configured_oauth_hosts()) class Authenticator: diff --git a/tests/test_litellm/llms/github_copilot/test_github_copilot_authenticator.py b/tests/test_litellm/llms/github_copilot/test_github_copilot_authenticator.py index 4e5023d11de..0e6a7fea489 100644 --- a/tests/test_litellm/llms/github_copilot/test_github_copilot_authenticator.py +++ b/tests/test_litellm/llms/github_copilot/test_github_copilot_authenticator.py @@ -94,6 +94,22 @@ class TestGitHubCopilotAuthenticator: with patch.dict(os.environ, environment, clear=True): assert authenticator.get_api_base() == "https://copilot-api.company.ghe.com" + def test_get_api_base_rejects_other_oauth_subdomains(self, authenticator): + environment = { + "GITHUB_COPILOT_API_BASE": "https://evil.company.ghe.com", + "GITHUB_COPILOT_DEVICE_CODE_URL": "https://company.ghe.com/login/device/code", + "GITHUB_COPILOT_ACCESS_TOKEN_URL": "https://company.ghe.com/login/oauth/access_token", + } + with ( + patch.dict(os.environ, environment, clear=True), + patch("litellm.llms.github_copilot.authenticator.verbose_logger.warning") as mock_warning, + ): + assert authenticator.get_api_base() is None + + mock_warning.assert_called_once_with( + "Ignoring GITHUB_COPILOT_API_BASE because it is not a trusted HTTPS GitHub Copilot endpoint" + ) + def test_get_api_base_trusts_explicit_allowed_host(self, authenticator): environment = { "GITHUB_COPILOT_API_BASE": "https://copilot-proxy.example.com",