mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-07 08:26:10 +00:00
fix(github-copilot): narrow Enterprise host trust
This commit is contained in:
parent
1975924956
commit
b5f11bc4b2
2 changed files with 17 additions and 3 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue