Skip to content

fix: ignore non-RSA keys when parsing the JWKS in the token verifier - #917

Open
frederikprijck wants to merge 2 commits into
masterfrom
fix/token-verifier-skip-unsupported-jwks-keys
Open

frederikprijck wants to merge 2 commits into
masterfrom
fix/token-verifier-skip-unsupported-jwks-keys

Conversation

@frederikprijck

@frederikprijck frederikprijck commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Changes

JwksFetcher._parse_jwks converted every key in the JWKS with the RSA key parser. If the JWKS also contained a key of another type (for example EC), PyJWT raised InvalidKeyError: Not an RSA key and the whole set was unusable:

  • AsymmetricSignatureVerifier / TokenVerifier failed for every token, including RS256 tokens signed with a valid RSA key that is in the same set. The error was a PyJWT InvalidKeyError, not the SDK's TokenValidationError.
  • AsyncJwksFetcher swallows errors with a bare except, so it reported RSA Public Key with ID "..." was not found. for every key id, which hides the actual cause.

Only keys with kty RSA are parsed now, any other key is skipped (kty is case-sensitive, RFC 7517 section 4.1, so "rsa" is skipped too). Requesting a key id that belongs to a skipped key fails with the existing TokenValidationError (... was not found), also when no RSA key is left.

Observable differences, all for JWKS documents that contain a key that is not an RSA key:

  • The sync verifier no longer raises InvalidKeyError. It verifies tokens signed with an RSA key from the set, and raises TokenValidationError for a key id that is not an RSA key.
  • A JWKS that was parsed is cached for the TTL. Before, a parse that raised never set the cache date, so the JWKS was fetched again on every call.

Nothing changes for JWKS documents that only contain RSA keys.

RFC 7517 section 5 says that implementations should ignore JWKs in a JWK Set that use kty values they do not understand, so a verifier that only supports RSA keys should not be affected by the other keys a JWKS publishes.

  • src/auth0/authentication/token_verifier.py: JwksFetcher._parse_jwks skips keys whose kty is not RSA (AsyncJwksFetcher shares this code path).

Alternative considered: catching InvalidKeyError per key. Filtering on kty was preferred as it is explicit, and a malformed RSA key still surfaces as an error.

References

Testing

Seven tests were added to tests/authentication/test_token_verifier.py:

  • JwksFetcher and AsyncJwksFetcher return the RSA key from a JWKS that also contains keys that are not RSA keys (an unknown type, EC, a key without kty and one with a lowercase kty).
  • Requesting the key id of a skipped key raises TokenValidationError (was not found).
  • A JWKS without any RSA key raises TokenValidationError and is fetched once.
  • End to end: TokenVerifier.verify accepts an RS256 token signed with a freshly generated RSA key when the JWKS also contains other key types.

Six of the seven fail on master: four with InvalidKeyError: Not an RSA key, and two (async) because the error is swallowed. The seventh, the async "was not found" test, passes on master and guards behavior that is preserved.

The tests/authentication suite passes (119 tests), with PyJWT 2.12.1 (the lockfile) and with the latest, 2.15.1, on Python 3.12. Tests outside tests/authentication need a Docker daemon for WireMock and were not run.

  • This change adds unit test coverage
  • This change adds integration test coverage
  • This change has been tested on the latest version of the platform/language or why not

Checklist

🤖 Generated with Claude Code

JwksFetcher._parse_jwks converted every key in the JWKS with the RSA key
parser. A JWKS that also contained a key of another type (for example EC
or OKP) made PyJWT raise "Not an RSA key", which made the synchronous
verifier fail for every token, including RS256 tokens signed with a valid
RSA key in the same set. The async verifier swallowed the error and reported
"RSA Public Key with ID ... was not found" for every key id.

Only keys with kty "RSA" are parsed now, other keys are skipped. Requesting
a key id that belongs to a skipped key still fails with the existing
"was not found" error.

Co-Authored-By: Claude <noreply@anthropic.com>
@frederikprijck
frederikprijck requested a review from a team as a code owner December 3, 2026 18:03
Add a key without kty, a key with a lowercase kty (kty is case-sensitive) and a
JWKS without any RSA key to the verifier tests, for both the sync and the
async fetcher. Move the cryptography import to the top of the test module and
put the async_token_verifier import in sorted order. The _parse_jwks
docstring now says RSA signatures, as the verifier accepts any RSA algorithm.

Co-Authored-By: Claude <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant