Skip to content

Commit ff9ec52

Browse files
committed
magento2#32636: Improved JWK check in the JwsManager class to account for cases when the algorithm is set directly in headers
1 parent 15bb2e4 commit ff9ec52

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

app/code/Magento/JwtFrameworkAdapter/Model/JwsManager.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,17 @@ public function build(JwsInterface $jws, EncryptionSettingsInterface $encryption
9393
$builder = $builder->withPayload($jws->getPayload()->getContent());
9494
for ($i = 0; $i < $signaturesCount; $i++) {
9595
$jwk = $encryptionSettings->getJwkSet()->getKeys()[$i];
96-
$alg = $jwk->getAlgorithm();
97-
if (!$alg) {
98-
throw new EncryptionException('Algorithm is required for JWKs');
99-
}
10096
$protected = [];
10197
if ($jws->getPayload()->getContentType()) {
10298
$protected['cty'] = $jws->getPayload()->getContentType();
10399
}
104100
if ($jws->getProtectedHeaders()) {
105101
$protected = $this->extractHeaderData($jws->getProtectedHeaders()[$i]);
106102
}
107-
$protected['alg'] = $alg;
103+
$protected['alg'] = $protected['alg'] ?? $jwk->getAlgorithm();
104+
if (!$protected['alg']) {
105+
throw new EncryptionException('Algorithm is required for JWKs');
106+
}
108107
$unprotected = [];
109108
if ($jws->getUnprotectedHeaders()) {
110109
$unprotected = $this->extractHeaderData($jws->getUnprotectedHeaders()[$i]);

0 commit comments

Comments
 (0)