Repository navigation
fix(auth): ignore unusable jwks keys so non-standard use does not break oidc login - #447
Merged
Merged
Conversation
…ak oidc login RFC 7517 §4.2 allows "use" values other than sig/enc, and §5 says a JWK Set's keys with unsupported values SHOULD be ignored. joserfc's KeySet.import_key_set skips only an unknown kty and raises on any other bad key, and authlib's parse_id_token imports the whole set, so an IdP publishing SAML keys next to its signing keys (Zitadel: use=saml_response_sig) broke every browser login. The OAuth client now reduces the fetched JWKS to keys joserfc imports on their own before authlib sees it. Each kept key was already acceptable, dropped keys cannot verify anything, and an empty result still fails closed. Closes #446 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #446. Browser OIDC login failed with
KeyParameterError: 'use' must be one of ['sig', 'enc']when the IdP's JWKS contains a key with a non-standarduse(Zitadel publishes SAML keys withuse: saml_ca/saml_response_sig/saml_metadata_sig).Spec: RFC 7517 §4.2 — "Other values MAY be used." §5 — "Implementations SHOULD ignore JWKs within a JWK Set that use 'kty' values that are not understood by them, that are missing required members, or for which values are out of the supported ranges."
Root cause: joserfc 1.7.5
KeySet.import_key_setskips only an unknownkty(authlib/joserfc#103) and raises on any other bad key, failing the whole set. authlib ≥1.7parse_id_tokenimports the whole set. The bearer path was unaffected because_select_jwkimports only thekid-named key.Change
mlflow_oidc_auth/oauth.py:usable_jwks()drops each keyJWKRegistry.import_keyrejects (baduse/key_ops, missing members, unsupported curve, non-object), logging only thekidat debug._OAuth2App(StarletteOAuth2App)overridesfetch_jwk_setso the cached set,force=Truerefresh and_refresh_oidc_jwksall get the filtered set;_OAuthwires it in, andreset_oauth()keeps it.Security posture: nothing is accepted that was not before — every kept key imports standalone, signature verification (
use, kty/alg checks, metadata algorithm list) is unchanged, dropped keys cannot verify, and an empty result still fails closed (MissingKeyError). The bearer path is deliberately untouched (it is already immune and stricter in the edge cases). Asecurity-reviewerpass found no exploitable issues; its three low/nit items (reset path,KeyErrorfor unsupported curves, a comment) are addressed.Tests
mlflow_oidc_auth/tests/test_jwks_nonstandard_use.py(20 tests): pins the upstream defect (joserfc still rejects; stock authlib client fails login), filter unit cases, a real RS256 id_token throughparse_id_tokenagainst a Zitadel-shaped set, forced refresh filtering, and negative tests — token signed by a dropped key, mismatched signature under the sigkid, wrongiss, empty set fails closed, no key material logged.Verification
pre-commit run --all-files— passpytest mlflow_oidc_auth/tests/ --ignore=mlflow_oidc_auth/tests/hooks— 5848 passed, 107 skippedmlflow_oidc_auth/tests/hooks/test_*.pyper file — all pass🤖 Generated with Claude Code