Repository navigation
fix(encryption): deprecate deriving the passwords of a key set beyond the PBES2 cap - #831
Merged
Merged
Conversation
… the PBES2 cap JWEDecrypter tries the keys of a key set one after the other and derives each password with the iteration count of the token. The PBES2 cap bounds one derivation, and since the recipients of a token share it, one recipient tried with one key: a recipient at the cap tried with a key set holding N passwords costs N derivations at the cap. Deriving more iterations in total than the share of a recipient with the keys of a key set is now deprecated. From 5.0.0, the passwords tried for a recipient share that part of the cap, and the ones beyond it are not tried. Only the keys that are derived count: keys of another type, and keys rejected for their usage or their algorithm, are left out, so a key set holding one password next to other keys keeps the whole share. Nothing is rejected: the tokens decrypted before are still decrypted. Reported by inanna-malick, as a follow-up of ANT-2026-P0RDGIIJ.
Spomky
force-pushed
the
fix/pbes2-key-set-iterations
branch
from
November 29, 2026 09:46
b6d2427 to
144a8e7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up of GHSA-3vqw-452c-g726, reported by inanna-malick.
The defect
JWEDecryptertries the keys of a key set one after the other, and derives each PBES2 password with the iteration count of the token. Since GHSA-3vqw, the recipients of a token share the cap: each one may request at mostmax_count / Niterations. One recipient tried with a key set of K passwords still costs K derivations at that share.A compact token at the default cap (1,000,000), with a password that is not in the key set:
The application chooses the key set, so a sender cannot push the cost beyond what the application configured: K tokens sent to an application holding one password cost the same. But
max_countreads like a bound per token, and it is one only with a single password.The fix
JWEDecryptercounts the iterations derived for one recipient over the keys it tries. When the next derivation would take the total past the share of the recipient, it triggers a deprecation, once, and carries on:Only the keys that are derived count. Keys of another type do not count, and neither do keys rejected for their usage or their algorithm (
alg,use,key_ops). So a key set holding one password next to signature keys or RSA keys keeps the whole share. Nothing is rejected in 4.3.For 5.0, the rule announced is a budget over the keys actually tried, rather than a division of the cap by the number of keys. Both bound a token to
max_count. The division would reject, upfront, tokens that are decrypted today with a single derivation. With the default cap:count()p2c= 600,000p2c= 600,000max_countis raisedp2c= 300,000p2c= 300,000octkeys for HS256, A128KW oruse: sig+ 1 password600,000 is the iteration count OWASP recommends for PBKDF2-HMAC-SHA256, so the first two rows are ordinary key rotations.
Behaviour changes
No token changes outcome, and no failure changes: the only difference is the new deprecation. The default
JWEBuildercount (4,096) stays below it for up to 244 passwords at the default cap.Verification
PBES2IterationCountTest::thePasswordsOfAKeySetTriedBeyondTheCapAreDeprecatedhas 9 cases. They cover one and two recipients, passwords within the share, past it, and exactly at it before another one, the right password first, and keys that are not derived. The 4 cases past the share fail on 4.3.x. The other 5 check that the token is decrypted without a deprecation, before and after.phpqa:8.4after a cleancomposer install: 3046 tests on 4.3.x, 3055 here, all green.php -linphpqa:8.2.JWEDecrypteragainst this one, on 588 PBES2 tokens. They combine PBES2-HS256 and HS512, 7 iteration counts, compact and JSON General with up to 3 recipients, ap2cof 0, −5 or a string, and 7 key sets. Calls go throughdecrypt()for each recipient and throughJWELoader::loadAndDecrypt().decrypt()cases, all of them past the share. It never appears with a single password, and never because of keys that are not derived.Not in this PR
max_count.