Skip to content

Commit f29ef73

Browse files
authored
Merge pull request jsonwebtoken#402 from panva/filter-unsupported-keys
fix: ignore node-jose unsupported key types and EC curves
2 parents 4a405e0 + 58a34e4 commit f29ef73

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/editor/public-key-download.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ function getKeyFromJwkKeySetUrl(kid, url) {
5252
});
5353
}
5454

55+
function supportedJwk({ kty, crv }) {
56+
switch (kty) {
57+
case 'RSA':
58+
return true;
59+
case 'EC':
60+
return ['P-256', 'P-384', 'P-521'].includes(crv)
61+
// node-jose does not support e.g. OKP keys or non-registered curves such as P-256K
62+
// we also don't populate the HMAC secret
63+
default:
64+
return false;
65+
}
66+
}
67+
5568
export function downloadPublicKeyIfPossible(decodedToken) {
5669
return new Promise((resolve, reject) => {
5770
const header = decodedToken.header;
@@ -80,9 +93,9 @@ export function downloadPublicKeyIfPossible(decodedToken) {
8093

8194
return httpGet(data.jwks_uri)
8295
}).then(data => {
83-
data = JSON.parse(data);
96+
const { keys } = JSON.parse(data);
8497

85-
return jose.JWK.asKeyStore(data);
98+
return jose.JWK.asKeyStore({ keys: keys.filter(supportedJwk) });
8699
}).then(jwks => {
87100

88101
const keys = jwks.all({ alg: header.alg, kid: header.kid, use: 'sig' })

0 commit comments

Comments
 (0)