AES Key Wrap based algorithms unwrap an encrypted key of any length before comparing it with the CEK size

Open
#771 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
php

Research direction

Read JWEDecrypter and locate checkCekSize(), then trace the four AES Key Wrap algorithm implementations named in the issue. Identify how each derives or determines the expected CEK size and where it performs key derivation, agreement, and unwrapping. Done means invalid encrypted key lengths are rejected before those costly operations; add tests for oversized keys and confirm valid JWEs still decrypt.

Written by the indexing model from the issue text.

Description

enhancement
Version(s) affected

All released versions (3.4.x, 4.0.x, 4.1.x, 4.2.x), and the 4.3.x and 5.0.x branches.

Description

A128KW/A192KW/A256KW, PBES2-+AKW, ECDH-ES+AKW and ECDH-SS+AKW pass the whole JWE Encrypted Key to spomky-labs/aes-key-wrap, which unwraps any number of 64-bit blocks (six AES calls per block, from PHP) before checking the integrity value. The only valid length is the CEK size plus 8 bytes. JWEDecrypter already knows the CEK size, but checks it only after the unwrapping (checkCekSize()).

A token with an oversized encrypted key is therefore rejected only after work and memory proportional to its size: about 1.5 s of CPU and 14 MB of memory per megabyte of encrypted key (4.2.x and 4.3.x), multiplied by the number of keys tried, against about 0.01 s for a valid token of the same size. Under memory_limit=128M, a token of about 9 MB ends in a fatal error instead of an exception.

The cost is linear in the token size. It matters for applications that accept JWEs in request bodies or fetch them (encrypted request objects, pushed authorization requests, request_uri), not for tokens carried in headers.

Possible Solution
  • Compare the encrypted key length with the expected size before the key derivation, the key agreement or the unwrapping, in the four algorithms.
  • Optionally, add a general bound on the encrypted key length in JWEDecrypter.
  • Meanwhile, applications can limit the size of the tokens they accept.
Additional Context

Found by the Anthropic OSS Scanner (ANT-2026-GFP863VS).

Dominant language
PHP
Stars
954
Forks
119
Avg merge
48m
Merged PRs (30d)
17

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from web-token/jwt-framework

All issues in web-token/jwt-framework

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.