fix(auth): update is_master_key callers and type pass-through key lookup

Key regeneration still called is_master_key with the old api_key/_master_key
keywords and raised TypeError. Also restores the str contract of get_api_key
and drops the duplicate hashlib imports left in proxy/utils.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Yujong Lee 2026-10-26 16:04:37 -07:00
parent 05ac93f165
commit e585e3321c
3 changed files with 16 additions and 14 deletions

View file

@ -279,6 +279,9 @@ _CLAUDE_MODEL_ROUTES: Final = frozenset(
)
_CLAUDE_MODEL_NORMALIZED: Final = "litellm.claude_model_normalized"
_GENERAL_SETTINGS_ADAPTER: Final = TypeAdapter(dict[str, object])
_PASS_THROUGH_HEADERS_ADAPTER: Final[TypeAdapter[Mapping[str, object] | None]] = TypeAdapter(
Mapping[str, object] | None
)
async def _normalize_claude_model(
@ -1350,14 +1353,17 @@ def _query_api_key(route: str, request: Request) -> str | None:
return safe_get_request_query_params(request).get("key")
def _pass_through_header_api_key(endpoint: dict, route: str, request: Request) -> str | None:
headers: Final[dict | None] = endpoint.get("headers") if endpoint.get("path", "") == route else None
if headers is None:
def _pass_through_header_api_key(endpoint: Mapping[str, object], route: str, request: Request) -> str | None:
if endpoint.get("path", "") != route:
return None
return request.headers.get(headers.get("litellm_user_api_key", ""))
headers: Final = _PASS_THROUGH_HEADERS_ADAPTER.validate_python(endpoint.get("headers"))
header_name: Final = headers.get("litellm_user_api_key", "") if headers is not None else None
return request.headers.get(header_name) if isinstance(header_name, str) else None
def _pass_through_api_key(pass_through_endpoints: list[dict] | None, route: str, request: Request) -> str | None:
def _pass_through_api_key(
pass_through_endpoints: Sequence[Mapping[str, object]] | None, route: str, request: Request
) -> str | None:
header_values: Final = tuple(
value
for value in (
@ -1375,17 +1381,17 @@ def _header_or_none(value: object) -> str | None:
def get_api_key(
custom_litellm_key_header: str | None,
api_key: str | None,
api_key: str,
azure_api_key_header: str | None,
anthropic_api_key_header: str | None,
google_ai_studio_api_key_header: str | None,
azure_apim_header: str | None,
pass_through_endpoints: list[dict] | None,
pass_through_endpoints: Sequence[Mapping[str, object]] | None,
route: str,
request: Request,
*,
custom_header: str | None = None,
) -> tuple[str | None, str | None]:
) -> tuple[str, str | None]:
selected: Final = select_api_key(
PresentedKeys(
custom_header=custom_header,

View file

@ -6378,9 +6378,7 @@ async def regenerate_key_fn(
# value in that field.
regenerate_target_key: Final = data.key if data and data.key else key
is_master_key_regeneration: Final = (
data is not None
and data.new_master_key is not None
and is_master_key(api_key=regenerate_target_key, _master_key=master_key)
data is not None and data.new_master_key is not None and is_master_key(regenerate_target_key, master_key)
)
if (
@ -6408,7 +6406,7 @@ async def regenerate_key_fn(
detail={"error": "DB not connected. prisma_client is None"},
)
_is_master_key_valid: Final = is_master_key(api_key=key, _master_key=master_key)
_is_master_key_valid: Final = is_master_key(key, master_key)
if master_key is not None and data and _is_master_key_valid:
if data.new_master_key is None:

View file

@ -7882,7 +7882,6 @@ async def send_email(
def hash_password(password: str) -> str:
"""Hash a password using scrypt with a random salt."""
import base64
import hashlib
import os
salt: Final = os.urandom(16)
@ -7893,7 +7892,6 @@ def hash_password(password: str) -> str:
def verify_password(password: str, stored: str) -> bool:
"""Verify a password against a stored hash. Supports scrypt and SHA256."""
import base64
import hashlib
import secrets
if stored.startswith("scrypt:"):