🚀 New: chi (χ) — an open-source autoresearch harness for fleets of LLM coding agents. Read the announcement.

Your Crypt::JWT HS256 Verifier Also Decrypts PBES2 Tokens, and the Fix Still Lets One Cost Five Seconds

CVE-2026-136796: Crypt::JWT's decode_jwt picks JWS or JWE from the token's shape, so an app that only verifies HS256 will run PBKDF2 with an attacker-chosen iteration count. Measured: 0.038's 3,000,000 cap still costs about 5 seconds of CPU per forged token. Pinning accepted_alg drops it to zero, on old versions too.

Contents

The CPAN Security Group published four CVEs for Crypt::JWT on November 25. One of them, CVE-2026-136796, applies to applications that never chose to use encryption at all. If your Perl service checks HS256 tokens with decode_jwt(token => $t, key => $secret), it will also accept an encrypted token, read a PBKDF2 iteration count from that token’s header, and run the key derivation before anything about the token has been authenticated.

The fixed release, 0.038, caps that count at 3,000,000. I measured what a token at the cap costs: about five seconds of CPU on one core. The upgrade turns an unbounded cost into a large bounded one. One argument to decode_jwt turns it into nothing, and that argument already works on the old versions.

The token chooses the code path

Crypt::JWT has a single decoder for both signed (JWS) and encrypted (JWE) tokens. It tells them apart by counting segments. From lib/Crypt/JWT.pm at v0.038:

if ($args{token} =~ $token_re) {
  if (defined($5) && length($5) > 0) {
      # JWE token (5 segments)
      ($header, $payload) = _decode_jwe($1, $2, $3, $4, $5, undef, {}, {}, %args);
  }
  else {
      # JWS token (3 segments)
      ($header, $payload) = _decode_jws($1, $2, $3, {}, %args);
  }
}

A three-segment HS256 token goes to signature verification, as you’d expect. A five-segment token goes to decryption, using the same key you passed for HMAC. A plain string key is valid for the PBES2 key-management algorithms (PBES2-HS256+A128KW and its siblings), because PBES2 is password-based encryption: it runs PBKDF2 over the key to derive an AES key-wrapping key. The advisory says it directly: “Unless accepted_alg rules it out, a token can select PBES2 whenever decode_jwt is given a symmetric key.”

PBES2 takes two parameters from the JOSE header: p2s, the salt, and p2c, the iteration count. Before 0.038, p2c went into PBKDF2 unchecked:

return pbes2_key_unwrap(_prepare_oct_key($key), $ecek, $alg, decode_b64u($hdr->{p2s}), $hdr->{p2c});

The integrity check comes later. The derived key unwraps the content encryption key, and only then does AES key unwrap or the GCM tag reject a forged token. So the attacker doesn’t need your secret. They need a header with a large number in it and four segments of random bytes.

What the cap still allows

0.038 adds a range check:

our $MAX_PBES2_ITER     = 3_000_000;         # max accepted PBES2 'p2c' (iteration count)
...
croak "JWE: invalid p2c" unless looks_like_number($p2c) && $p2c >= 1 && $p2c <= $MAX_PBES2_ITER;

To see what that limit means in practice, I built forged tokens (a valid-looking header, random encrypted key, IV, ciphertext and tag) and passed them to decode_jwt with a 32-byte HMAC secret, the way an HS256-only service would. The machine was an Ubuntu 24.04 cloud VM on an Intel Xeon at 2.10 GHz, with CryptX 0.080 from the Ubuntu archive. Each row is one call, timed with Time::HiRes:

Crypt::JWTalg in forged headerp2caccepted_algTimeError
0.038PBES2-HS256+A128KW1,000not set0.004 saes_key_unwrap: unexpected IV
0.038PBES2-HS256+A128KW3,000,000not set3.64 saes_key_unwrap: unexpected IV
0.038PBES2-HS512+A256KW3,000,000not set5.16 saes_key_unwrap: unexpected IV
0.038PBES2-HS512+A256KW3,000,001not set<0.001 sJWE: invalid p2c
0.038PBES2-HS512+A256KW3,000,000'HS256'<0.001 salg ... not accepted_alg
0.037PBES2-HS512+A256KW3,000,000not set5.03 saes_key_unwrap: unexpected data
0.037PBES2-HS512+A256KW10,000,000not set16.42 saes_key_unwrap: unexpected data
0.037PBES2-HS512+A256KW10,000,000'HS256'<0.001 salg ... not in accepted_alg

Every forged token fails, which is the point: the failure comes after the work. These are single runs on one machine, so read them as orders of magnitude. The 0.037 rows grow linearly with p2c, and there’s no upper limit there. On 0.038 the worst case is fixed, but five seconds of a core per unauthenticated request is still a denial of service. A four-core box is saturated by fewer than one such request per second.

Three million is generous next to other JOSE libraries:

LibraryDefault max p2c on decrypt
jwcrypto (Python)16,384 (default_max_pbkdf2_iterations)
panva/jose (JS)10,000 (maxPBES2Count)
go-jose (Go)1,000,000, hard-coded
Crypt::JWT 0.0383,000,000 ($Crypt::JWT::MAX_PBES2_ITER)

The JOSE libraries don’t agree on a number, but Crypt::JWT is the only one of these four whose default is in the millions.

The structural fix is pinning the algorithm

The accepted_alg rows are the part I’d act on first. The check runs before key derivation in both versions, and 0.037 already supported it. If you can’t upgrade today, this fixes the CPU problem today:

my $claims = decode_jwt(
    token        => $token,
    key          => $secret,
    accepted_alg => 'HS256',
);

With that set, a five-segment token is rejected on its alg before PBKDF2 runs. It also closes the older problem the module’s own documentation warns about, where a public key passed as a plain string becomes an HMAC secret if the attacker switches alg to HS256. The 0.038 documentation now marks accepted_alg as “strongly recommended”. It still isn’t the default. undef still means “accept all alg algorithms except none”, which is the configuration in my measurements.

Other libraries avoid this by not offering a single decoder. panva/jose exports jwtVerify and jwtDecrypt as separate functions, so code that calls jwtVerify can’t be redirected into decryption. go-jose’s ParseSigned and ParseEncrypted take the allowed algorithms as required, non-empty arguments. jwcrypto’s JWT class does dispatch on segment count the same way Crypt::JWT does, so the low cap matters there. If you maintain a wrapper around any JOSE library, make the caller say whether it expects a signature or a ciphertext, and with which algorithm.

Decrypting does not mean someone you trust sent it

CVE-2026-136795 is the zip bomb. With "zip": "DEF" in the header, decode_jwt inflated the payload with no size limit. For signed tokens that happens after the signature verifies, so it needs a key holder. For encrypted tokens it happens after decryption, and the advisory points out that with RSA-OAEP or ECDH-ES key management, “anyone who holds the recipient’s public key can produce a token that decrypts.”

That’s how public-key JWE is meant to work. Encryption to your public key gives confidentiality, not sender authentication. A token that decrypts cleanly proves only that someone had your public key, and your public key is public. 0.038 caps inflated output at 10 MiB ($MAX_INFLATED_SIZE). panva/jose defaults to 250,000 bytes, and its maxDecompressedLength: 0 rejects compressed JWEs entirely. If your tokens never use zip, the safe limit is zero.

The other two CVEs are quicker. CVE-2026-8748: before 0.038, HMAC signatures and CBC-HMAC tags were compared with Perl’s eq, whose run time the advisory says “depends on the number of matching leading bytes”, and 0.038 switches to a constant-time compare. CVE-2018-25445 is a 2018 bug that got its CVE this week: before 0.024, verify_aud => 'myapp' was silently ignored because only Regexp or CODE values were honored, and the iss, sub, aud and jti checks were skipped when the claim was missing.

What to change

  • Add accepted_alg (and accepted_enc if you really use JWE) to every decode_jwt call. This works on any version you’re running.
  • Upgrade to Crypt-JWT 0.038, released in May. Check where your copy comes from: Ubuntu 24.04’s libcrypt-jwt-perl package is 0.035-1, which has all of these bugs except the 2018 one.
  • If you do accept PBES2, lower $Crypt::JWT::MAX_PBES2_ITER to what your own issuers actually send. Set it in a BEGIN block, as the module’s documentation says.
  • Read the 0.038 changelog before deploying. It also adds a 4-byte minimum HMAC key and a 2048-bit minimum RSA key, both of which can reject tokens that verified yesterday, and it changes the ConcatKDF output for ECDH-ES with A192CBC-HS384 and A256CBC-HS512, which the changelog calls an “INTEROP BREAK” with 0.037 and earlier.

I wrote about the basics of JWT security earlier in What are JWTs and how secure are they?. This CVE shows the other half: which algorithm runs is decided by the token’s header, unless your code decides first.

Sources