Skip to main content
Menu
Advisories

Impact A128KW, A192KW, A256KW, A128GCMKW, A192GCMKW and A256GCMKW never compare the length of the oct key with the 128, 192 or 256 bits the algorithm needs

GHSA-4MXJ-75J2-J8HCPublished Updated GitHub

Description

Impact

A128KW, A192KW, A256KW, A128GCMKW, A192GCMKW and A256GCMKW never compare the length of the oct key with the 128, 192 or 256 bits the algorithm needs. AESKW::getKey() and AESGCMKW::getKey() return the decoded k as is, and PHP's OpenSSL extension does not refuse a key of another size: it pads a shorter key with zero bytes, without any warning. The experimental A128CTR, A192CTR, A256CTR and chacha20-poly1305 key encryption algorithms behave the same way.

  • An empty key ({"kty":"oct","k":""}, which JWKFactory::createFromSecret() returns for an empty string, for example an empty environment variable) wraps every content encryption key under an all-zero key: anyone can read the tokens the application issues and forge tokens it accepts. HS256 refuses the same key (Invalid key length.); the key wrapping algorithms did not.
  • A shorter key is completed with zero bytes and only keeps the strength of its own bytes, while the application believes it uses the algorithm's key size.
  • Nothing reports it: KeyChecker does not look at the length, and OctAnalyzer only flags keys under 128 bits.

An attacker cannot cause this: the key comes from the application. Keys of the exact size (JWKFactory::createOctKey(128) for A128KW, the key:generate:oct command) are not affected.

A longer key is cut to its first 16, 24 or 32 bytes. A random key loses nothing that way, but a text secret can lose most of its strength: with A128KW, a secret that starts with a known 16-character label is reduced to that label. This conforms to no specification either; patch releases keep accepting such keys, see Compatibility below.

Affected configurations

Applications that wrap content encryption keys with A128KW, A192KW, A256KW, A128GCMKW, A192GCMKW or A256GCMKW (or the experimental A128CTR, A192CTR, A256CTR or chacha20-poly1305 key encryption) and use an oct key shorter than 128, 192 or 256 bits (256 bits for chacha20-poly1305). The worst case is an empty key. When the key has no alg member, the alg of the token decides which key size applies, among the algorithms the application registers.

AESKW had a length check until ad03372e (2017-10-28), removed together with the one of spomky-labs/aes-key-wrap; AESGCMKW never had one. Every release is affected.

Patches

Fixed in 3.4.13, 4.0.9, 4.1.11 and 4.2.6. AESKW, AESGCMKW and the experimental AESCTR and Chacha20Poly1305 now refuse a key shorter than the key size of the algorithm with Invalid key length., the error the HMAC algorithms already raise for a short key. The check covers wrapping and unwrapping: JWEBuilder throws, while JWEDecrypter and JWELoader move on to the next key of the set.

3.4.13 is the last release of the 3.4 branch, which reaches its end of life with it: later fixes go to 4.x only.

Compatibility.

  • A key shorter than the key size of the algorithm no longer works with these algorithms. Tokens issued with such a key can be read again with the key padded with zero bytes to the key size, which is the key OpenSSL actually used; replace the key afterwards.
  • Keys of the exact size are not affected.
  • A longer key keeps working in these patch releases, through its first 16, 24 or 32 bytes as before. 4.3.0 deprecates it, and 5.0.0 refuses it: from then on, tokens issued with such a key are read with those first bytes.

Workarounds

Use keys of exactly the key size of the algorithm, generated at random (JWKFactory::createOctKey(128) for A128KW and A128GCMKW, 192 or 256 bits for the others), and set their alg member. Never build an oct key from a text secret or from an environment variable that may be empty. If an application has used an empty key, consider the content of its tokens as disclosed and the tokens it accepted as forgeable, and replace the key.

References

  • RFC 7518, sections 4.4 (Key Wrapping with AES Key Wrap) and 4.7 (Key Encryption with AES GCM)
  • RFC 3394, AES Key Wrap Algorithm
  • GHSA-jc6j-46g2-xwqc, the same OpenSSL behaviour on the key of direct encryption

Credits

Reported by Anthropic's OSS Scanner (ANT-2026-A3MHD339).

Affected versions

References

GitHub · web-token/jwt-framework