Skip to content

Commit 800f582

Browse files
crypto: reject inherited key type names
Use an own-property check when dispatching generateKeyPair's NID-only algorithm table Fixes: #62874 Signed-off-by: Jonathan Lopes <[email protected]> PR-URL: #62875 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Filip Skokan <[email protected]>
1 parent 5f92b6d commit 800f582

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

lib/internal/crypto/keygen.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ function parseKeyEncoding(keyType, options = kEmptyObject) {
181181
}
182182

183183
const nidOnlyKeyPairs = {
184+
'__proto__': null,
184185
'ed25519': EVP_PKEY_ED25519,
185186
'ed448': EVP_PKEY_ED448,
186187
'x25519': EVP_PKEY_X25519,

test/parallel/test-crypto-keygen.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ const { hasOpenSSL3 } = require('../common/crypto');
5555
code: 'ERR_INVALID_ARG_VALUE',
5656
message: "The argument 'type' must be a supported key type. Received 'rsa2'"
5757
});
58+
59+
for (const type of ['toString', 'constructor']) {
60+
assert.throws(() => generateKeyPairSync(type, {}), {
61+
name: 'TypeError',
62+
code: 'ERR_INVALID_ARG_VALUE',
63+
message: `The argument 'type' must be a supported key type. Received '${type}'`
64+
});
65+
66+
assert.throws(() => generateKeyPair(type, {}, common.mustNotCall()), {
67+
name: 'TypeError',
68+
code: 'ERR_INVALID_ARG_VALUE',
69+
message: `The argument 'type' must be a supported key type. Received '${type}'`
70+
});
71+
}
5872
}
5973

6074
{

0 commit comments

Comments
 (0)