Commit 108400a
fix(encryption): enforce the disjoint header requirement of RFC 7516
JWEDecrypter built the complete header with array_merge($sharedProtectedHeader,
$sharedHeader, $recipientHeader). Because of the last-wins behaviour of array_merge,
an unprotected header parameter was able to override an integrity protected one, "alg"
and "enc" included: the HeaderCheckerManager validated the protected values while the
decryption used the unprotected ones.
RFC 7516 section 7.2.1 requires that "the Header Parameter names in the three locations
MUST be disjoint". That requirement is now enforced when the token is read, as it already
was when it is written, and the merge order is reversed so that the protected header wins.
"alg" and "enc" are also no longer read from the shared unprotected header. The RFC puts
no location constraint on them, but that header is not covered by the AAD and, unlike the
per-recipient header, nothing requires those parameters to be located there. As a
consequence the RFC 7520 sections 5.11 and 5.12 vectors are still parsed but are no longer
decrypted; the corresponding tests now assert the refusal.
JWEBuilder could produce a token violating the disjoint requirement: with several
recipients, the header parameters computed by the key encryption algorithm are added to
the per-recipient header without looking at the shared headers. A PBES2 token carrying
"p2c" in the shared protected header ended up with "p2c" in both places, and was already
rejected by the HeaderCheckerManager. Those parameters are now filtered, which is the
behaviour of the single recipient path.
Also adds non-empty string guards on "alg" and "enc" and fixes the error message of
getContentEncryptionAlgorithm which mentioned the key encryption algorithm.
Co-authored-by: Ross Addison <rossaddison@users.noreply.github.com>1 parent 8a33a6e commit 108400a
5 files changed
Lines changed: 407 additions & 54 deletions
File tree
- src/Library/Encryption
- tests/Component/Encryption
- RFC7520
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
260 | 266 | | |
261 | 267 | | |
262 | 268 | | |
| |||
274 | 280 | | |
275 | 281 | | |
276 | 282 | | |
| 283 | + | |
277 | 284 | | |
278 | 285 | | |
279 | 286 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
112 | 122 | | |
113 | 123 | | |
114 | 124 | | |
| |||
117 | 127 | | |
118 | 128 | | |
119 | 129 | | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
125 | 139 | | |
126 | 140 | | |
127 | | - | |
128 | | - | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
129 | 144 | | |
130 | 145 | | |
131 | 146 | | |
| |||
253 | 268 | | |
254 | 269 | | |
255 | 270 | | |
256 | | - | |
| 271 | + | |
257 | 272 | | |
258 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
259 | 280 | | |
260 | 281 | | |
261 | 282 | | |
262 | | - | |
| 283 | + | |
263 | 284 | | |
264 | 285 | | |
265 | 286 | | |
266 | 287 | | |
267 | 288 | | |
268 | 289 | | |
269 | | - | |
| 290 | + | |
270 | 291 | | |
271 | | - | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
272 | 299 | | |
273 | 300 | | |
274 | | - | |
275 | | - | |
| 301 | + | |
| 302 | + | |
276 | 303 | | |
277 | 304 | | |
278 | 305 | | |
279 | 306 | | |
280 | 307 | | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
281 | 319 | | |
0 commit comments