Repository navigation
fix(encryption): deprecate "dir" JWEs without protected header and without "aad" - #796
Merged
Merged
Conversation
…thout "aad" AES-GCM key wrapping encrypts the CEK with AES-GCM and an empty AAD. A JSON "dir" JWE that has neither a protected header nor an "aad" member encrypts its content the same way. Under a key without "alg" that a decrypter accepts for "dir" and for an A*GCMKW algorithm, the encrypted key of an A*GCMKW token, presented as the content of such a JWE, is decrypted to the CEK of that token. Conversely, the content of such a JWE is a valid A*GCMKW encrypted key of its payload. Refusing this shape would break tokens that the JSON serializations allow, so 4.3.0 deprecates it on both sides. The decrypter triggers a deprecation when it decrypts such a JWE, for the key that decrypted it only, and the builder when it builds one. Both still work; they will be refused in 5.0.0. Compact JWEs always have a protected header and are not concerned. Reported by Anthropic's OSS Scanner (ANT-2026-35BMRM17).
#797 added its own deprecation call after deprecateLongerDirectKey() in JWEDecrypter::decryptRecipientKey(), on the line this branch also extends. Both calls are kept, the one of 4.3.x first. * origin/4.3.x: Place the wrapped key size check next to the CEK size check fix(encryption): check the size of an AES key wrapped key before unwrapping it feat(key-mgmt): let JKUFactory and X5UFactory refuse HTTP redirects fix(sd-jwt): refuse the reserved claim names in the objects of the claims fix(sd-jwt): bound the depth of the processed payload fix(encryption): read "key_ops" according to the key management mode fix(nested-token): deprecate a "cty" outside the protected header of the JWE fix(sd-jwt): keep only the verified signature in the verified Issuer-signed JWT # Conflicts: # src/Library/Encryption/JWEDecrypter.php
The token that KeyOperationsTest forges from an A128GCMKW encrypted key is a JSON "dir" JWE that has neither a protected header nor an "aad" member, the shape this branch deprecates. Decrypting it now triggers the "key_ops" deprecation of #797, then the empty AAD one.
Spomky
added a commit
that referenced
this pull request
Nov 29, 2026
5.0.x now holds #797 (c82460f) through the merge-up of 4.3.x, so this branch is rebuilt as its description plans, through a merge instead of a new history: the cherry-pick of #797 (8404b4e) gives way to the code of 5.0.x, and the refusal (c819887) is kept. - JWEDecrypter: the deprecation of a "dir" key without "decrypt" goes with the refusal; the deprecation of a "dir" JWE with an empty AAD, from #796, stays. - KeyOperationsTest: the refusal versions of the tests are kept, and the static key agreement test decrypts the token again, as 5.0.x can now decrypt it; the constant of the empty AAD deprecation is no longer used and goes.
Spomky
added a commit
that referenced
this pull request
Nov 29, 2026
5.0.x now holds #796 (1d88a1a) through the merge-up of 4.3.x, so 5.0.x is merged into this branch as its description plans. The cherry-pick of #796 (f4b6da5) gives way to the code of 5.0.x, and the refusal (54617b0) is kept: - JWEBuilder and JWEDecrypter keep checkDirectEncryptionAADIsNotEmpty(), and the call to deprecateDirectEncryptionWithEmptyAAD() goes; the deprecation of a "dir" key without "decrypt" (#797) stays, #806 turns it into a refusal; - DirectEncryptionAdditionalAuthenticatedDataTest is the version of this branch; - KeyOperationsTest::aKeyWrappingKeyThatDecryptsDirectContentIsReported (#797) forges the token of #760 and expected its CEK: the token is now refused, so the test, renamed aKeyWrappingKeyCannotDecryptDirectContent as in #806, expects a failed decryption without deprecation.
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.
The issue
AES-GCM key wrapping (A128GCMKW, A192GCMKW, A256GCMKW) encrypts the CEK with AES-GCM under the key and an empty AAD. In the JSON serializations,
algandencmay sit in the per-recipient header. AdirJWE that has neither a protected header nor anaadmember then has its content encrypted with an empty AAD too, which is the same computation.With a decrypter that registers
dir, an AGCMKW algorithm and the AGCM algorithm of the same size, and a key without analgparameter:ivandtagof its header, presented as the content of such adirJWE, is decrypted to the CEK of that token. If the application shows decrypted payloads to the sender, that CEK opens the original token;dirJWE built that way is a valid A*GCMKW encrypted key of its payload.Compact JWEs, hence JWTs, always have a protected header and cannot take this shape.
The change
Refusing the shape would break tokens that the JSON serializations allow, so this PR only deprecates it:
JWEDecryptertriggers a deprecation when it decrypts adirJWE whose encoded protected header is empty and that has noaadmember. Only the key that decrypted the token reports it, as for the longerdirkeys: a token that no key decrypts triggers nothing.JWEBuildertriggers a deprecation when it builds such a JWE.Both still work. Both will be refused in 5.0.0; the
trigger_deprecationgrep of #717 covers that. The two new methods are private, and no signature changes.The rule follows the AAD of the content, not the decoded header: an empty
protectedmember is reported, ane30({}) one is not; an emptyaadmember is enough, because the AAD then ends with a period. It applies whatever the content encryption algorithm. Only AES-GCM collides with a key wrapping algorithm of the library today, but the same collision would come back with any AEAD offered for both uses, such as a ChaCha20-Poly1305 content encryption next to the experimentalchacha20-poly1305key encryption, which also uses an empty AAD.Behaviour changes
dir, JSON, no protected header, noaad: builtdirwith a protected header (every compact JWE), or with anaadmember, even emptyUpgrade note
Proposed text for the "From v4.2 to v4.3" guide:
And for the key management pages, as the issue asks:
Mitigations available today
algparameter on every key.AlgorithmCheckercreated withprotectedHeader: true, so thatalgis read from the protected header only.dirnext to key wrapping algorithms in the same decrypter.Verification
DirectEncryptionAdditionalAuthenticatedDataTest, 31 cases. 19 fail on the base branch, each on its deprecation assertion. The assertions before it pass there, which confirms the issue:dirJWE, is decrypted with the same key (noalg) to the CEK of that token, and that CEK decrypts the original content. One deprecation now (6 cases);dirJWE built without protected header and withoutaad: its content, IV and tag unwrap with A*GCMKW to its payload. One deprecation at build time now (3 cases); decrypting it, flattened and general, for the six content encryption algorithms, gives one deprecation per decryption (6 cases);protectedmember and a shared unprotected header only are reported;protectedset toe30, a protected header with a parameter, an emptyaadmember and anaadmember are not (7 cases);dirwith a protected header (compact and JSON), withencprotected andalgin the recipient header, with an empty or a non-emptyaad(6 cases); A128KW, and A128GCMKW with two recipients and an empty shared protected header (2 cases).ae49782e, which includes fix(nested-token): deprecate a "cty" outside the protected header of the JWE #794, fix(encryption): read "key_ops" according to the key management mode #797, fix(encryption): check the size of an AES key wrapped key before unwrapping it #799 and feat(key-mgmt): let JKUFactory and X5UFactory refuse HTTP redirects #800):src/(445 types), dumped by reflection, is identical;dirwith each content encryption algorithm and header layout, longer keys, a filled encrypted key, editedprotectedmembers, the forged AGCMKW tokens, A128KW, AGCMKW with two recipients, ECDH-ES and RSA-OAEP-256. All 208 cases have the same outcome and exception class. 72 of them gain exactly one of the two new deprecations (66 decryptions, 6 builds), and none loses one;trigger_deprecation()shows that only the new test class (9 builds, 22 decryptions) andKeyOperationsTest::aKeyWrappingKeyThatDecryptsDirectContentIsReported(1 decryption, see below) trigger the new deprecations. No other test, bundle path or nested token builds or decrypts this shape.phpunit-11inphpqa:8.4: 2,688 tests green (base: 2,657, the difference is the new class), with the same 3 skipped and 2 incomplete. ECS, Rector, PHPStan, Deptrac, the license check, the lint andcomposer validate --strictare clean with the current image.infection.json.dist, the CI run of this PR kills 4 and skips 18 as "required more time than configured": they are not escaped, the covering test files are just slow.4.3.xis merged into this branch; the commit of the fix is unchanged (no rebase). fix(encryption): read "key_ops" according to the key management mode #797 (for KeyChecker: "key_ops" does not tell content decryption from key unwrapping, and "deriveKey"/"deriveBits" are not accepted on both sides #761) had added its own deprecation call on the line ofJWEDecrypter::decryptRecipientKey()that this PR extends: both calls are kept, the one of fix(encryption): read "key_ops" according to the key management mode #797 first. fix(encryption): read "key_ops" according to the key management mode #797 also addedKeyOperationsTest::aKeyWrappingKeyThatDecryptsDirectContentIsReported, which forges the token of this issue and decrypts it with a key restricted towrapKeyandunwrapKey. That token has the deprecated shape, so the test now expects both deprecations, thekey_opsone first (separate commit).5.0.x: since fix(encryption): read "key_ops" according to the key management mode #797, merging4.3.xinto5.0.xalready conflicts inJWEDecrypter.php, on the calls afterdeprecateLongerDirectKey()(removed in5.0.x) and on the deprecation methods, and in the four loader factories. This PR adds no conflict block: its call joins the first one (keep the4.3.xcalls exceptdeprecateLongerDirectKey()), and its method, placed next tocheckEncryptedKeyIsEmpty(), which5.0.xdid not change, merges cleanly. The HPKE draft feat(encryption): HPKE for JWE — Integrated Encryption and Key Encryption (draft-ietf-jose-hpke-encrypt) #740 conflicts with4.3.xin one block ofJWEDecrypter.php, with or without this PR.Related: #761, fixed by #797 (
key_opsread according to the key management mode); this PR does not touchKeyChecker.Closes #760
Found by the Anthropic OSS Scanner (ANT-2026-35BMRM17).