Repository navigation
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). (cherry picked from commit 1411e4a)
…ut "aad" 4.3.0 deprecates building and decrypting a JSON "dir" JWE that has neither a protected header nor an "aad" member: its content is encrypted with an empty AAD, as AES-GCM key wrapping encrypts a CEK, so the encrypted key of an A*GCMKW token passes for such a content under the same key, and the other way round. 5.0.0 refuses it. The builder throws before encrypting the content. The decrypter refuses the token with every key, like a filled encrypted key in direct mode: the decryption fails and the reason goes to the error callback, and the loader keeps it as the previous exception. Reported by Anthropic's OSS Scanner (ANT-2026-35BMRM17).
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.
Summary
Follow-up of #796 for 5.0.0. 4.3.0 deprecates building and decrypting a JSON
dirJWE that has neither a protected header nor anaadmember (#760). Its content is encrypted with an empty AAD, like an AES-GCM key wrap: under a key that serves bothdirand an A*GCMKW algorithm, one passes for the other. This PR turns both deprecations into refusals.Draft until the merge-up of
4.3.xinto5.0.xis pushed, see "Branch layout".The change
JWEBuilder::build()throwsJose\Component\Core\Exception\InvalidArgumentExceptionbefore it encrypts the content:A "dir" JWE must have a protected header or additional authenticated data: set "alg" and "enc" in the shared protected header.JWEDecrypterrefuses such a JWE with every key. The check runs in the key loop, next to the other checks and before the CEK is obtained, as for a filled encrypted key in direct mode.decrypt()returns a failed result, the error callback receives theInvalidArgumentException(A "dir" JWE must have a protected header or additional authenticated data.) once per key, andJWELoader::loadAndDecrypt()keeps it as the previous exception of itsInvalidTokenException.aadmember, whatever the content encryption algorithm. An emptyprotectedmember is refused;e30({}) and anaadmember, even empty, are accepted. Compact JWEs always have a protected header and are not concerned.The two methods are private: no public or protected signature changes.
BC break
Announced by the 4.3.0 deprecations of #796.
dir, JSON, no protected header, noaad: builtInvalidArgumentExceptiondirwith a protected header (every compact JWE), or with anaadmember, even emptyProposed text for the 5.0 upgrade guide:
Branch layout
5.0.xdoes not contain #796 yet: the merge-up of4.3.xinto5.0.xis prepared but not pushed. Merging the 4.3.x commit of #796 here would also have brought the 37 commits of4.3.x(19 without the merges) between the last merge-up (7dfbe15f) and its base, with their conflicts. This branch therefore cherry-picks it (f4b6da51, from1411e4a7), then adds the refusal (54617b07). The diff of the second commit is what 5.0 changes compared to 4.3.Once the merge-up is pushed, merge
5.0.xinto this branch. Simulated with the prepared merge-up completed with the current4.3.x:JWEBuilder.phpandJWEDecrypter.php: two conflict blocks each, on the method. KeepcheckDirectEncryptionAADIsNotEmpty(). The call todeprecateDirectEncryptionWithEmptyAAD()merges without conflict in each file: remove it, or PHPStan reports a call to an undefined method.DirectEncryptionAdditionalAuthenticatedDataTest.php: add/add conflict, keep the version of this branch.KeyOperationsTest::aKeyWrappingKeyThatDecryptsDirectContentIsReported(fix(encryption): read "key_ops" according to the key management mode #797) arrives with the merge-up. It forges the token of Hardening: refuse a JSON "dir" JWE without protected header and "aad", whose content can be an A*GCMKW encrypted key #760 and expects its CEK, with two deprecations. Here the token is refused, so the 4.3 version of the test fails and must expect a failed decryption. fix(encryption): refuse "dir" keys without the content operation in "key_ops" #806, the 5.0 refusal of fix(encryption): read "key_ops" according to the key management mode #797, already turns it into a refusal test: fix(encryption): refuse "dir" keys without the content operation in "key_ops" #806 and this PR merge without conflict, and the encryption tests pass with both (358 tests).Verification
5.0.x(b81a608b) and on the cherry-picked deprecation (f4b6da51): all the refusal cases. The 12 that pass there are the layouts that stay accepted.dirJWE, is not decrypted, and the reason is the refusal (6 cases).algandencin the shared unprotected header, with an explicitly empty shared protected header, and withaadset back tonull(9 cases).aadare not decrypted, for the six content encryption algorithms and both JSON serializations (6 cases). An emptyprotectedmember and a shared unprotected header only are refused;e30, a protected header with a parameter, an emptyaadmember and anaadmember are not (7 cases).encprotected withalgin the recipient header, an empty or a non-emptyaad(6 cases); A128KW, and A128GCMKW with two recipients and an empty shared protected header (2 cases).5.0.x(b81a608b):src/(443 types), dumped by reflection, is identical;dirtokens of this layout, the 6 forged A*GCMKW tokens, which no longer return the CEK, and 5 builds. The 13 other cases of this layout usedirkeys longer than the CEK, which5.0.xalready refuses. No other case changes.phpunit-11inphpqa:8.4: 2,291 tests green (base: 2,253, 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.infection.json.dist, the CI run of this PR kills 4 and skips 18 as "required more time than configured".Refs #760, #796, #717
Found by the Anthropic OSS Scanner (ANT-2026-35BMRM17).