mirror of
https://github.com/home-assistant/core.git
synced 2026-08-28 10:16:02 -05:00
async_validate_access_token ran a full HMAC-SHA256 signature verify plus claims validation on every authenticated request, even though the signature of a given token string never changes. Only the exp claim is time-dependent. Cache the (refresh_token_id, exp) of each successfully validated token in a bounded LRU. On a repeat request the hot path becomes a dict lookup, an exp comparison and the existing refresh-token lookup, skipping the HMAC verify entirely. Security is unchanged: - Only tokens that pass the full signature/issuer/iat verification are ever cached, so a forged token can never enter the cache. - The refresh token is re-fetched from the store on every call, so a revoked or removed token (its refresh token is gone) is still rejected, and an inactive user is still rejected. - The exp claim is rechecked against the same leeway on every cache hit, so an expired token is still rejected (and evicted). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PXQwLpKCf8FvhWoSc2Jw61