dir, ECDH-ES and ECDH-SS accept a non-empty JWE Encrypted Key, so token strings are malleable
Description
Impact
With the dir, ECDH-ES and ECDH-SS key management algorithms, no key travels in the token, and the JWE Encrypted Key must be the empty octet sequence (RFC 7516, section 5.2, step 10). JWEDecrypter never looked at it in those modes, and the authentication tag does not cover it. A token whose encrypted key was filled with arbitrary bytes after it was issued therefore still decrypted, to the same protected header and the same plaintext, in the compact, JSON flattened and JSON general serializations. The bytes were handed to the application through Recipient::getEncryptedKey().
Anyone holding one such token can derive, without any key, as many other token strings as they want, and the application accepts all of them. Nothing is disclosed and the content cannot be changed. The impact is on applications that recognise a token by its serialized string or a hash of it: a replay cache, a single-use registry or a deny-list of revoked tokens treats each variant as a new token. In the compact serialization, the token string is otherwise fixed.
Affected configurations
Applications that decrypt JWEs whose alg is dir, ECDH-ES or ECDH-SS, whatever the content encryption algorithm and the serialization, and that identify accepted tokens by their string rather than by a claim such as jti. dir and ECDH-ES are reached through JWELoader, NestedTokenLoader and the bundle's decrypter services. The non-registered ECDH-SS algorithm is reached only through JWEDecrypter called with a sender key.
Not affected: the key encryption and key wrapping algorithms (RSA-OAEP, RSA-OAEP-256, RSA1_5, A128KW to A256KW, A128GCMKW to A256GCMKW, PBES2-*, ECDH-ES+A*KW, ECDH-SS+A*KW): another encrypted key gives another content encryption key, and the token is rejected. JWEBuilder never produces a non-empty encrypted key with a direct algorithm.
The missing check dates from the first release of the library.
Patches
JWEDecrypter now rejects a token whose encrypted key is not empty when the key management algorithm is a direct encryption or a direct key agreement. The check runs with the other checks made for each key, so such a token is rejected like any token that cannot be decrypted: decryptUsingKey() and decryptUsingKeySet() return false, and JWELoader throws its usual exception.
Fixed in 3.4.13, 4.0.9, 4.1.11 and 4.2.6. 3.4.13 is the last release of the 3.4 line, which reaches its end of life with it: upgrade to 4.x to keep receiving fixes.
Compatibility. Tokens produced by the library are unchanged and still accepted. In the JSON serializations, an encrypted_key member equal to "" is still accepted, since it decodes to the empty octet sequence. A direct-mode token whose encrypted key was filled by another producer is now rejected; conforming producers leave it empty.
Workarounds
The confidentiality and the integrity of the content are not at stake. Until you upgrade, identify tokens by a claim such as jti in a replay cache, a single-use registry or a deny-list, rather than by the token string. Alternatively, after unserializing a token and before decrypting it, reject it when alg is dir, ECDH-ES or ECDH-SS and getRecipient($index)->getEncryptedKey() is neither null nor ''.
References
- RFC 7516, section 5.2, step 10 (JWE decryption) and section 7.2.1 (the
encrypted_keymember) - RFC 7518, sections 4.5 (Direct Encryption with a Shared Symmetric Key) and 4.6 (ECDH-ES)
Credits
Reported by Anthropic's OSS Scanner (ANT-2026-TJB4VSPK).
Affected versions
- web-token/jwt-libraryfixed in 3.4.13
- web-token/jwt-libraryFrom 4.0.0 · fixed in 4.0.9
- web-token/jwt-libraryFrom 4.1.0 · fixed in 4.1.11
- web-token/jwt-libraryFrom 4.2.0 · fixed in 4.2.6
- web-token/jwt-frameworkfixed in 3.4.13
- web-token/jwt-frameworkFrom 4.0.0 · fixed in 4.0.9
- web-token/jwt-frameworkFrom 4.1.0 · fixed in 4.1.11
- web-token/jwt-frameworkFrom 4.2.0 · fixed in 4.2.6
- web-token/jwt-encryptionthrough 3.2.10