The vulnerability lies in the joserfc library's handling of the 'p2c' (PBES2 Count) parameter within a JWE protected header for PBES2-based encryption algorithms. The root cause is the lack of validation for this parameter, which specifies the iteration count for the PBKDF2 key derivation function.
An attacker can craft a JWE token with an extremely large 'p2c' value. When the application attempts to decrypt this token, the PBES2HSAlgKeyEncryption.decrypt_cek function reads this value and passes it to PBES2HSAlgKeyEncryption.compute_derived_key. This second function then uses the large value as the iterations parameter for cryptography.hazmat.primitives.kdf.pbkdf2.PBKDF2HMAC. This triggers a computationally expensive operation that can lock up a CPU core for an extended period, leading to a Denial of Service.
The patch, identified in commit 696a961, introduces a validate_p2c function that sets a reasonable upper limit (300,000) for the p2c value. This validator is then registered for the 'p2c' header parameter in the PBES2HSAlgKeyEncryption class, ensuring that any attempt to use an excessively large iteration count is rejected before the expensive computation is performed.