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:
- No zero-length-key check.
validate_raw_keytests onlyisinstance(key, bytes); the unsafe-prefix denylist (PEM/SSH markers) does not match empty bytes, sob''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. - 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).
- Type-confusion into empty key. An RSA/EC JWK with no
algis 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
| Library | ID | Detail |
|---|---|---|
| Authlib ≤ 1.7.2 | CVE-2026-114616 | OctKey.import_key / HMACAlgorithm accept b''; HS256/384/512 forgery. Distinct from the key=None jwk-injection CVE-2026-27962. |
| ruby-jwt | USN-9059-1 | HMAC verified with empty/missing key → token forgery, auth bypass. |
| python-jose ≤ 3.5.0 | CVE-2026-120459 | HMACKey/CryptographyHMACKey accept zero-length secrets; key resolving to '', b'' or empty JWK k. |
| PyJWT (PyJWK path) < 2.13.0 | CVE-2026-102266 | Empty symmetric JWK via PyJWK/PyJWKSet forges HS256; the PyJWK path skipped the empty-key validation the raw-byte path had. |
| fast-jwt | CVE-2026-107720 | createVerifier accepts unsigned tokens when key is ''/null even with a non-empty algorithm allow-list. |
| libjwt | GHSA-q843-6q5f-w55g | RSA 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-framework | GHSA-4mxj-75j2-j8hc | AES 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:
kidpointing at/dev/nullor 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 withalgomitted, 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 thealghint rather thankty.
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 JWKalghint; 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.
Related
- JSON Web Tokens
- JWT Algorithm Confusion
- JWT None Algorithm
- JWT Header Injection
- JWT Secret Cracking
- Python JWT Library Vulnerabilities
Sources
- Authlib accepts empty HMAC key, allowing JWS/JWT forgery (CVE-2026-114616) · original
- USN-9059-1: ruby-jwt HMAC verification with empty/missing key allows token forgery · original
- python-jose JWT forgery with an empty HMAC key (CVE-2026-120459) · original
- python-jose authentication bypass through 3.5.0 · original
- PyJWT: PyJWK accepts empty HMAC keys (CVE-2026-102266) · original
- fast-jwt empty-key unsigned-accept model (CVE-2026-107720) · original
- libjwt algorithm confusion: JWT forgery with RSA JWK as empty-key HMAC · original
- jwt-framework: AES key wrap accepts short oct keys zero-padded (empty key wraps every CEK) · original
- Off the Curve: JWT forgery CTF writeup (kid=/ empty key) · original
- CVE-2026-23993: HarbourJwt empty-signature bypass · original