Skip to content

Ignore unknown kty in import_key_set (RFC 7517 §5) - #914

Closed
RalphBragg wants to merge 1 commit into
authlib:mainfrom
RalphBragg:fix/jwks-import-ignore-unknown-kty
Closed

RalphBragg wants to merge 1 commit into
authlib:mainfrom
RalphBragg:fix/jwks-import-ignore-unknown-kty

Conversation

@RalphBragg

Copy link
Copy Markdown

What

JsonWebKey.import_key_set() now skips a key whose kty is present but not recognised, instead of raising KeyError and failing the whole set.

Why

Today import_key_set does [cls.import_key(k) for k in keys]; the first key with an unregistered kty raises KeyError (e.g. KeyError: 'AKP') and the entire set fails to import. RFC 7517 §5 says a processor SHOULD ignore key types it does not understand.

This is becoming a live problem as post-quantum keys (ML-DSA, kty:"AKP", RFC 9964) begin appearing in published JWKS next to RSA/EC keys: a consumer stops verifying every signature from that issuer, including the classical ones, the moment such a key is published. Relates to #913.

Change

  • import_key_set skips only keys whose kty is explicitly present and not in JWK_KEY_CLS; a recognised-but-malformed key still raises as before.
  • Added test_jwk_import_key_set_ignores_unknown_kty.

tests/jose/test_jwk.py passes (26 passed). I know authlib.jose is deprecated in favour of joserfc; happy to also PR joserfc (it has the same behaviour), but since authlib.jose still ships and is widely used pre-2.0, this keeps it safe in the meantime.

import_key_set raised KeyError on the first key whose kty was not registered,
failing the whole set. Skip a key whose kty is present but unrecognised, per
RFC 7517 Section 5, so classical keys published alongside a post-quantum key
(ML-DSA, kty AKP) remain usable.
@azmeuk

azmeuk commented Jul 24, 2026

Copy link
Copy Markdown
Member

Hi, thank you for your contribution, but unfortunatelyauthlib.jose is currently deprecated and will be removed in the upcoming 1.8 version in favor of joserfc. We won't take any contribution on authlib.jose now.

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.

2 participants