Security-sensitive code must ensure (1) the correct auth path is used without accidental overrides, (2) sensitive auth material is never leaked in logs, and (3) auth-mode “sentinels” and provider handles can’t be accidentally triggered or misused.
Apply these rules:
Authorization if a user may have provided one. If you must set it, gate it behind an explicit “header missing/expected mode” check.api-key and authorization) and ensure all response/request logging uses it; cover it with unit tests.Example (redact sensitive headers):
SENSITIVE_HEADERS = {"api-key", "authorization"}
def redact_sensitive_headers(headers: dict[str, str]) -> dict[str, str]:
return {k: ("<redacted>" if k.lower() in SENSITIVE_HEADERS else v) for k, v in headers.items()}
Example (auth provider discipline):
_refresh_api_key() (or refresh a callable provider) when you’re about to use API-key auth (i.e., when AD token auth isn’t active / you’re falling back). Add tests that assert the provider is not called when AD auth is used.Enter the URL of a public GitHub repository