AESKW and AESGCMKW (A128KW, A192KW, A256KW, A128GCMKW, A192GCMKW and
A256GCMKW) handed the decoded "k" of the oct key to OpenSSL without
comparing its length with the key size of the algorithm. PHP's OpenSSL
extension does not reject a key of another size: it pads a shorter key
with zero bytes and only uses the first 16, 24 or 32 bytes of a longer
one. An empty key, which JWKFactory::createFromSecret() returns for an
empty string, wrapped every CEK under an all-zero key: anyone could read
the tokens the application issued and forge tokens it accepted, and a
shorter key was completed with zero bytes. The experimental A128CTR,
A192CTR, A256CTR and chacha20-poly1305 key encryption algorithms had the
same flaw.
A key shorter than the key size of the algorithm is now refused with
"Invalid key length.", as HS256, HS384 and HS512 already do: the builder
throws and the decrypter moves on to the next key of the set. An AESKW
subclass with a wrapper of another library, or an AESCTR subclass with
another cipher, is not checked.
A key of the key size or longer is used as before, so tokens issued with
such keys are not affected. Tokens issued with a shorter key can be read
again with that key padded with zero bytes to the key size of the
algorithm.
Reported by Anthropic's OSS Scanner (ANT-2026-A3MHD339).