Skip to content

fix(auth): ignore unusable jwks keys so non-standard use does not break oidc login - #447

Merged
kharkevich merged 1 commit into
mainfrom
fix/jwks-nonstandard-use
Oct 6, 2026
Merged

kharkevich merged 1 commit into
mainfrom
fix/jwks-nonstandard-use

Conversation

@kharkevich

Copy link
Copy Markdown
Member

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-standard use (Zitadel publishes SAML keys with use: 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_set skips only an unknown kty (authlib/joserfc#103) and raises on any other bad key, failing the whole set. authlib ≥1.7 parse_id_token imports the whole set. The bearer path was unaffected because _select_jwk imports only the kid-named key.

Change

mlflow_oidc_auth/oauth.py:

  • usable_jwks() drops each key JWKRegistry.import_key rejects (bad use/key_ops, missing members, unsupported curve, non-object), logging only the kid at debug.
  • _OAuth2App(StarletteOAuth2App) overrides fetch_jwk_set so the cached set, force=True refresh and _refresh_oidc_jwks all get the filtered set; _OAuth wires it in, and reset_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). A security-reviewer pass found no exploitable issues; its three low/nit items (reset path, KeyError for 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 through parse_id_token against a Zitadel-shaped set, forced refresh filtering, and negative tests — token signed by a dropped key, mismatched signature under the sig kid, wrong iss, empty set fails closed, no key material logged.

Verification

  • pre-commit run --all-files — pass
  • pytest mlflow_oidc_auth/tests/ --ignore=mlflow_oidc_auth/tests/hooks — 5848 passed, 107 skipped
  • mlflow_oidc_auth/tests/hooks/test_*.py per file — all pass
  • Keycloak e2e not run locally (CI job)

🤖 Generated with Claude Code

…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]>
@kharkevich
kharkevich merged commit 7107281 into main Oct 6, 2026
18 checks passed
@kharkevich
kharkevich deleted the fix/jwks-nonstandard-use branch October 6, 2026 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] OIDC login fails when IdP JWKS contains keys with non-standard use

1 participant