Skip to content

Reject DER-encoded asymmetric keys as HMAC secrets (CVE-2026-85394) - #422

Open
emgaurav wants to merge 2 commits into
mpdavis:masterfrom
emgaurav:fix/cve-2026-85394-der-hmac
Open

emgaurav wants to merge 2 commits into
mpdavis:masterfrom
emgaurav:fix/cve-2026-85394-der-hmac

Conversation

@emgaurav

Copy link
Copy Markdown

Summary

  • Completes the CVE-2024-33663 HMAC guard so DER-encoded asymmetric keys (and certs) cannot be used as HMAC secrets. This is CVE-2026-85394 / GHSA-6c5p-j8vq-pqhj.
  • Adds is_der_format() and applies it in both HMAC backends (native and cryptography) alongside the existing PEM/SSH checks. Detection is structural ASN.1 rather than calling cryptography loaders, so the native-only install path stays covered.
  • Also fixes test_incorrect_public_key_hmac_signing, which passed a curve class to generate_private_key() and never reached its CVE-2024-33663 assertion on current cryptography.

Fixes #414

Test plan

  • Reproduced the advisory: PEM public key as HMAC secret is rejected; the same key in DER previously signed/verified a forged HS256 token via jwt.decode(..., algorithms=["RS256","HS256"]) and jws.verify(..., algorithms=None). After the change both encodings raise JWKError.
  • Full suite: 474 passed, 12 skipped (with cryptography + pycryptodome).
  • Native-only install (cryptography uninstalled): DER HMAC secret rejected; 176 tests passed under -m "not (cryptography or pycryptodome or backend_compatibility)".
  • flake8, isort --check-only, and black --check clean.
  • Confirm CI on this PR for the tox matrix (base / cryptography-only / pycryptodome / compatibility).

Made with Cursor

zepto-gaurav and others added 2 commits September 16, 2026 13:14
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>
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.

Algorithm-confusion guard bypassed by DER-encoded public keys (incomplete CVE-2024-33663 fix)

2 participants