JWE and JWS loaders try every recipient or signature of a token, so a small token multiplies the PBES2 iteration cap (denial of service)
Description
Impact
JWELoader and JWSLoader try every recipient of a JWE, or every signature of a JWS, until one succeeds, and the token decides how many there are. In the JSON General serialization a recipient can be the three bytes {},: it inherits alg, enc and the key management parameters (p2c, p2s, epk…) from the shared headers. Each recipient therefore costs one key management operation per key of the key set, as many times as the sender wants.
PBES2 is the worst case. The p2c cap added for GHSA-3prj-6hqw-cm82 bounds one key derivation, not one token. A JWE of about 300 bytes with 30 empty recipients and p2c at the cap in its protected header costs 30 derivations of 1,000,000 iterations: 8.7 s in the reporter's measurement, about 50 s on a slower machine. The cost grows linearly with the number of recipients. No key, password or valid token is needed, and every such token is rejected.
The same loop multiplies the other costs of one attempt, with larger tokens:
- an ECDH-ES key agreement or an RSA private key operation per recipient: 60 KB tokens cost 2 to 12 s;
- for a JWS, the verification of the whole payload per signature: about 4 s for 1 MB with HS256;
- the processing of the shared headers.
The effect is a denial of service of the workers. Nothing is disclosed and no token is accepted.
Affected configurations
Applications that receive tokens from untrusted senders through a JWELoader or JWSLoader that registers the JSON General serializer (jwe_json_general or jws_json_general), directly or through the bundle. NestedTokenLoader and the bundle loaders go through the same loops. The small-token case needs a PBES2 algorithm (PBES2-HS256+A128KW, PBES2-HS384+A192KW or PBES2-HS512+A256KW) to be registered.
Loaders that only register the compact or flattened serializers are not affected: those serializations carry exactly one recipient or signature. Applications that unserialize a token themselves and call the decrypter or the verifier for each recipient or signature have the same loop in their own code.
The loop has been there since v0.5.0, when the loaders were added.
Patches
JWEDecryptershares the PBES2 iteration cap between the recipients of a token: a PBES2 recipient of a token with N recipients may request at mostmax_count / Niterations. One token can no longer request more derivation work than a single recipient at the cap, whatever its number of recipients. The check runs before the derivation.PBES2AESKW::getMaxCount()exposes the cap.JWELoaderandJWSLoaderaccept a maximum number of recipients or signatures: a token with more is rejected before any of them is processed. In the patch releases (3.4.13, 4.0.9, 4.1.11 and 4.2.6) this limit is optional and has no default value, so that every token accepted before is still loaded. It is the fourth argument of the constructor, for examplenew JWELoader($serializerManager, $jweDecrypter, $headerCheckerManager, 10). We recommend setting it, 10 is enough in practice, when the JSON General serialization is accepted from untrusted senders: it bounds the ECDH-ES, RSA and JWS cases.- From 4.3, loading a token with more than 10 recipients or signatures without a limit is deprecated, and the bundle loaders accept
max_recipientsandmax_signaturesoptions. From 5.0, the limit is 10 by default.
3.4.13 is the last release of the 3.4 line.
Compatibility. Without the new argument, the loaders behave as before. One edge case changes: a PBES2 recipient that requests more iterations than its share is no longer decrypted, for example a recipient at 600,000 iterations next to one other recipient (share: 500,000). Raising max_count in the constructor of the PBES2 algorithm restores it. Tokens with a single recipient are not affected, nor are tokens built by JWEBuilder with its default of 4,096 iterations. Called directly, JWEDecrypter::decryptUsingKey() and decryptUsingKeySet() return false for such a recipient; they do not throw.
Workarounds
Until you upgrade:
- do not register the JSON General serializers in loaders that process tokens from untrusted senders;
- or unserialize the token first and reject it when
countRecipients()orcountSignatures()is above what you expect, before handing it to the loader or the decrypter; - do not accept PBES2 from untrusted senders, or lower the
max_countargument of the PBES2 algorithms.
A limit on the size of request bodies reduces the ECDH-ES, RSA and JWS cases, but not the PBES2 one: a few hundred bytes are enough.
References
- GHSA-3prj-6hqw-cm82 (unbounded PBES2
p2c) - RFC 7516, section 7.2 (JWE JSON Serialization)
- RFC 7515, section 7.2 (JWS JSON Serialization)
- RFC 7518, section 4.8 (PBES2)
Credits
Reported by Anthropic's OSS Scanner (ANT-2026-P0RDGIIJ).
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-frameworkFrom 0.5.0 · fixed 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-encryptionFrom 0.5.0 · through 3.2.10
- web-token/jwt-signatureFrom 0.5.0 · through 3.2.10