Conversation
The guard added for CVE-2024-33663 identified asymmetric keys by their text format only, matching PEM armor and SSH prefixes. A DER-encoded key is binary and has neither, so it was accepted as an HMAC secret: an attacker holding the service's public key could sign an HS256 token with its DER bytes and have it verify, when the verifying algorithms were not restricted. DER carries nothing to match on, so is_der_format() recognizes it by its ASN.1 structure instead. The check is pure Python rather than deferring to cryptography's key loaders, because the native backend is the one used when cryptography is not installed. Co-authored-by: Cursor <cursoragent@cursor.com>
generate_private_key() requires an EllipticCurve instance, so passing the SECP256R1 class raised a TypeError before the test could assert anything, leaving the CVE-2024-33663 regression uncovered. Co-authored-by: Cursor <cursoragent@cursor.com>
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
is_der_format()and applies it in both HMAC backends (nativeandcryptography) alongside the existing PEM/SSH checks. Detection is structural ASN.1 rather than callingcryptographyloaders, so the native-only install path stays covered.test_incorrect_public_key_hmac_signing, which passed a curve class togenerate_private_key()and never reached its CVE-2024-33663 assertion on current cryptography.Fixes #414
Test plan
jwt.decode(..., algorithms=["RS256","HS256"])andjws.verify(..., algorithms=None). After the change both encodings raiseJWKError.cryptographyuninstalled): DER HMAC secret rejected; 176 tests passed under-m "not (cryptography or pycryptodome or backend_compatibility)".flake8,isort --check-only, andblack --checkclean.Made with Cursor