The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(cli): bind the sibling refresh fallback to the same user and team
mateo-berrifb123b33de18
diff --git a/litellm/proxy/client/cli/commands/pkce_login.py b/litellm/proxy/client/cli/commands/pkce_login.pyindex 2d8d5bf68bb..d00f9a86bfe 100644--- a/litellm/proxy/client/cli/commands/pkce_login.py+++ b/litellm/proxy/client/cli/commands/pkce_login.py@@ -485,16 +485,19 @@ def fresh_api_key(return refreshed.access_token+_CREDENTIAL_IDENTITY_FIELDS: Final = ("base_url", "token_endpoint", "resource", "user_id", "team_id")++def _key_rotated_by_a_sibling(record: Mapping[str, object] | None, token_data: Mapping[str, object], now: float) -> str | None:"""The key a sibling process saved, but only when it continues this very credential:- same proxy, same token endpoint, same resource, and not yet expired. A concurrent- ``lite login`` against a different proxy replaces the same file, and its key must never- be sent to this one."""+ same proxy, same token endpoint, same resource, same user and team, and not yet expired.+ A concurrent ``lite login`` against a different proxy, or as someone else on this one,+ replaces the same file, and its key must never be sent as this credential."""if record is None or record.get("refresh_token") == token_data.get("refresh_token"):return None- if any(record.get(field) != token_data.get(field) for field in ("base_url", "token_endpoint", "resource")):+ if any(record.get(field) != token_data.get(field) for field in _CREDENTIAL_IDENTITY_FIELDS):return Noneexpires_at: Final = record.get("expires_at")if not isinstance(expires_at, (int, float)) or now >= expires_at:diff --git a/tests/test_litellm/proxy/client/cli/test_pkce_login.py b/tests/test_litellm/proxy/client/cli/test_pkce_login.pyindex 39f750835df..bbdcbb6635d 100644--- a/tests/test_litellm/proxy/client/cli/test_pkce_login.py+++ b/tests/test_litellm/proxy/client/cli/test_pkce_login.py@@ -68,6 +68,8 @@ STORED = {"token_endpoint": f"{BASE}/token","revocation_endpoint": f"{BASE}/revoke","resource": BASE,+ "user_id": "user-1",+ "team_id": "team-a",}@@ -590,6 +592,9 @@ def test_fresh_api_key_uses_a_sibling_rotation_when_its_own_refresh_loses_the_ra{"base_url": "https://other.example.com"},{"token_endpoint": "https://other.example.com/token"},{"resource": "https://other.example.com"},+ {"user_id": "someone-else"},+ {"team_id": "another-team"},+ {"team_id": None},{"expires_at": 999_000.0},{"expires_at": None},{"key": ""},@@ -600,12 +605,15 @@ def test_fresh_api_key_uses_a_sibling_rotation_when_its_own_refresh_loses_the_ra"other-base-url","other-token-endpoint","other-resource",+ "other-user",+ "other-team",+ "no-team","expired","no-expiry","empty-key",],)-def test_fresh_api_key_never_substitutes_a_sibling_record_for_another_proxy_or_a_dead_key(sibling_record):+def test_fresh_api_key_never_substitutes_a_sibling_record_for_another_proxy_identity_or_a_dead_key(sibling_record):rotated = {**STORED, "key": "sk-cli-sibling", "refresh_token": "llm_srefresh_sibling", "expires_at": 1_003_600.0}foreign = {**rotated, **sibling_record}http = _FakeHttp({("POST", f"{BASE}/token"): _FakeResponse(400, {"error": "invalid_grant"})})