# 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
| 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: `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.
## Related
- [[JSON Web Tokens]]
- [[JWT Algorithm Confusion]]
- [[JWT None Algorithm]]
- [[JWT Header Injection]]
- [[JWT Secret Cracking]]
- [[Python JWT Library Vulnerabilities]]
## Sources
- [[raw/github.com/authlib-accepts-empty-hmac-key-allowing-jws-jwt-forgery-cve-2026-11461-12634|Authlib accepts empty HMAC key, allowing JWS/JWT forgery (CVE-2026-114616)]]
- [[raw/ubuntu.com/usn-9059-1-ruby-jwt-hmac-verification-with-empty-missing-key-allows-to-14615|USN-9059-1: ruby-jwt HMAC verification with empty/missing key allows token forgery]]
- [[raw/blog.ostorlab.co/python-jose-jwt-forgery-with-an-empty-hmac-key-cve-2026-120459-15663|python-jose JWT forgery with an empty HMAC key (CVE-2026-120459)]]
- [[raw/github.com/python-jose-authentication-bypass-through-3-5-0-13577|python-jose authentication bypass through 3.5.0]]
- [[raw/osv.dev/pyjwt-pyjwk-accepts-empty-hmac-keys-cve-2026-102266-12778|PyJWT: PyJWK accepts empty HMAC keys (CVE-2026-102266)]]
- [[raw/exploit-intel.com/fast-jwt-empty-key-unsigned-accept-model-cve-2026-107720-14806|fast-jwt empty-key unsigned-accept model (CVE-2026-107720)]]
- [[raw/github.com/libjwt-algorithm-confusion-jwt-forgery-with-rsa-jwk-as-empty-key-hmac-14313|libjwt algorithm confusion: JWT forgery with RSA JWK as empty-key HMAC]]
- [[raw/github.com/jwt-framework-aes-key-wrap-accepts-short-oct-keys-zero-padded-empty-ke-15789|jwt-framework: AES key wrap accepts short oct keys zero-padded (empty key wraps every CEK)]]
- [[raw/c0dn.dev/off-the-curve-jwt-forgery-ctf-writeup-14022|Off the Curve: JWT forgery CTF writeup (kid=/ empty key)]]
- [[raw/pentesterlab.com/cve-2026-23993-jwt-authentication-bypass-in-harbourjwt-via-unknown-alg-4968|CVE-2026-23993: HarbourJwt empty-signature bypass]]