Skip to content

Reject unhashable JWK algorithms before algorithm lookup - #1222

Open
FanWu-ai wants to merge 1 commit into
jpadilla:masterfrom
FanWu-ai:fix/unhashable-jwk-algorithms-20261006
Open

FanWu-ai wants to merge 1 commit into
jpadilla:masterfrom
FanWu-ai:fix/unhashable-jwk-algorithms-20261006

Conversation

@FanWu-ai

@FanWu-ai FanWu-ai commented Oct 6, 2026

Copy link
Copy Markdown

A JWK with a non-empty array or object as its alg value raises a raw TypeError during the algorithm dictionary lookup. Because PyJWKSet skips unusable keys by catching PyJWTError, one malformed entry aborts an otherwise usable key set.

Validate the selected algorithm's type before the cryptography availability check and algorithm lookup. Selected non-string algorithm values now raise InvalidKeyError, allowing the existing key-set filtering to retain valid siblings. Explicit valid algorithm overrides retain their existing behavior. Falsey metadata values, including empty arrays and objects, continue through the existing algorithm-inference path; this patch does not change that compatibility behavior.

Add eight regression/control cases for array/object algorithms, direct construction, mixed key sets, entirely unusable sets, and explicit overrides. Six cases fail on unchanged master.

Validation (Linux, CPython 3.12.14):

  • Unmodified baseline full crypto suite: 471 passed, 4 built-in skips for tests requiring cryptography to be absent.
  • Final full crypto suite: 479 passed, the same 4 built-in skips.
  • Separate project-supported no-crypto configuration: 294 passed, 189 built-in crypto-required skips. This supplements the fully exercised crypto configuration, rather than replacing it.
  • Full pre-commit (13 hooks), repository-wide mypy (25 files), strict HTML documentation build, Sphinx doctests, README/usage doctests, wheel/sdist build and twine validation: all passed.
  • git diff --check: passed.

AI disclosure: OpenAI Codex was used to inspect the code, reproduce the failure, implement the patch, write regression tests, run checks, and prepare this description. The hosted CI matrix has not been run locally.

@FanWu-ai
FanWu-ai marked this pull request as ready for review October 6, 2026 04:32
@auvipy
auvipy requested review from auvipy and jpadilla October 6, 2026 05:20

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