Skip to content

Fix JWK refresh cache check#99

Open
e345ee wants to merge 1 commit into
EpicGames:mainfrom
e345ee:fix-jwk-cache-refresh
Open

Fix JWK refresh cache check#99
e345ee wants to merge 1 commit into
EpicGames:mainfrom
e345ee:fix-jwk-cache-refresh

Conversation

@e345ee

@e345ee e345ee commented Jul 3, 2026

Copy link
Copy Markdown

What

Fix the JWK cache short-circuit so fetch_new_keys(Some(kid)) skips the network fetch only when the requested kid is actually present in the local cache.

Why

The previous check used desired.map(|d| cache.get(d)).is_some(), which returns true for every Some(kid) regardless of whether the cache contains that key. As a result, a missing or rotated JWK could never be fetched after startup, preventing key rotation from taking effect until the server restarted.

Fixes #78.

How

  • Replace the cache guard with desired.and_then(|d| cache.get(d)).is_some().
  • Add a regression test with a local JWKS endpoint that first serves old-kid, then serves new-kid, verifying that requesting the missing key triggers a refresh.

Testing

  • cargo +nightly fmt --all -- --check
  • cargo clippy -p lore-server --all-targets -- -D warnings --no-deps
  • cargo clippy --all-targets -- -D warnings --no-deps
  • cargo test

When a caller requests a missing desired key, the cache guard used Option::map and short-circuited every Some(kid) request before checking whether the key existed. This prevented key rotation from loading new JWKS entries until restart.

Use and_then so only an actual cached entry skips the fetch, and add a regression test that refreshes from a JWKS endpoint after the requested kid changes.

Fixes EpicGames#78

Signed-off-by: Sadovoi Grisha <gsad1030@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

JWK key-ring loader hardening

1 participant