JWT Empty Key Forgery

A 2024–2026 bug cluster where a JOSE library accepts a zero-length HMAC key, so the signature becomes a public, deterministic function of header+payload that anyone can reproduce — forging tokens with no secret at all.

How it works

HMAC with an empty key still produces a valid, well-defined digest; hmac.new(b'', msg, sha256) is reproducible by any party. If a verifier can be made to use '' / b'' / an empty JWK k as the HMAC secret, the signature check passes for an attacker-crafted token. Three distinct code paths reach it:

  1. No zero-length-key check. validate_raw_key tests only isinstance(key, bytes); the unsafe-prefix denylist (PEM/SSH markers) does not match empty bytes, so b'' passes every gate. The realistic trigger is caller code sourcing the key from somewhere that can be empty at runtime: os.environ.get('JWT_SECRET', ''), an unset config value, a missing JWK.
  2. Empty signature equals empty computed signature. A verifier that computes an empty signature for an edge case and compares strings accepts an empty token signature (HarbourJwt unknown-alg; see JWT None Algorithm).
  3. Type-confusion into empty key. An RSA/EC JWK with no alg is treated as an oct (HMAC) key of zero length — algorithm confusion collapsing into empty-key HMAC (libjwt).

The kid=/ / kid=../../dev/null path from JWT Header Injection is the same primitive reached through a header parameter: the resolved “key file” is empty, so an empty-secret HMAC verifies.

Notable cases

LibraryIDDetail
Authlib ≤ 1.7.2CVE-2026-114616OctKey.import_key / HMACAlgorithm accept b''; HS256/384/512 forgery. Distinct from the key=None jwk-injection CVE-2026-27962.
ruby-jwtUSN-9059-1HMAC verified with empty/missing key → token forgery, auth bypass.
python-jose ≤ 3.5.0CVE-2026-120459HMACKey/CryptographyHMACKey accept zero-length secrets; key resolving to '', b'' or empty JWK k.
PyJWT (PyJWK path) < 2.13.0CVE-2026-102266Empty symmetric JWK via PyJWK/PyJWKSet forges HS256; the PyJWK path skipped the empty-key validation the raw-byte path had.
fast-jwtCVE-2026-107720createVerifier accepts unsigned tokens when key is ''/null even with a non-empty algorithm allow-list.
libjwtGHSA-q843-6q5f-w55gRSA JWK without alg used as empty-key HMAC; __setkey_check() permits any non-none requested alg when key->alg == JWT_ALG_NONE.
@web-token/jwt-frameworkGHSA-4mxj-75j2-j8hcAES key-wrap (A128/192/256KW) accepts oct keys shorter than required and zero-pads them; an empty key wraps any CEK → JWE token disclosure/forgery. Fixed 3.4.13/4.0.9/4.1.11/4.2.6.

The pattern recurs because each library guards a different corner (prefix denylist, truthiness, JWK alg hint) but none enforced a minimum key length on the HMAC path. Python-specific coverage: Python JWT Library Vulnerabilities.

Detection and testing

  • Where HS* is accepted, re-sign a tampered token using an empty secret ("") and submit it; acceptance is forgery.
  • Combine with header injection: kid pointing at /dev/null or any empty/predictable file, signed with an empty/known secret.
  • For JWK-based verifiers, submit an oct JWK with empty k, and an asymmetric JWK with alg omitted, to probe type confusion.
  • Code review: any HMAC sign/verify with no minimum-length check; key material defaulted to '' when an env var or config is absent; JWK import that keys off the alg hint rather than kty.

Defenses

  • Reject zero-length (and sub-256-bit) HMAC keys at import and before verify; fail closed when the key source is empty.
  • Bind key type to algorithm by kty, not the JWK alg hint; never let an asymmetric key become an HMAC secret.
  • Upgrade to fixed versions (PyJWT 2.15.1+, Authlib 1.9.5+, python-jose patched, ruby-jwt patched, fast-jwt 6.3.0+, libjwt patched, jwt-framework per above).
  • Prefer asymmetric signing so no secret-sized key sits in verifier config at all.

Sources