diff --git a/lib/internal/crypto/keygen.js b/lib/internal/crypto/keygen.js index d1c14e547fd640..e6e787c39f512a 100644 --- a/lib/internal/crypto/keygen.js +++ b/lib/internal/crypto/keygen.js @@ -181,6 +181,7 @@ function parseKeyEncoding(keyType, options = kEmptyObject) { } const nidOnlyKeyPairs = { + '__proto__': null, 'ed25519': EVP_PKEY_ED25519, 'ed448': EVP_PKEY_ED448, 'x25519': EVP_PKEY_X25519, diff --git a/test/parallel/test-crypto-keygen.js b/test/parallel/test-crypto-keygen.js index e0515c15776fc6..7911520af34481 100644 --- a/test/parallel/test-crypto-keygen.js +++ b/test/parallel/test-crypto-keygen.js @@ -55,6 +55,20 @@ const { hasOpenSSL3 } = require('../common/crypto'); code: 'ERR_INVALID_ARG_VALUE', message: "The argument 'type' must be a supported key type. Received 'rsa2'" }); + + for (const type of ['toString', 'constructor']) { + assert.throws(() => generateKeyPairSync(type, {}), { + name: 'TypeError', + code: 'ERR_INVALID_ARG_VALUE', + message: `The argument 'type' must be a supported key type. Received '${type}'` + }); + + assert.throws(() => generateKeyPair(type, {}, common.mustNotCall()), { + name: 'TypeError', + code: 'ERR_INVALID_ARG_VALUE', + message: `The argument 'type' must be a supported key type. Received '${type}'` + }); + } } {