From 6f975db8af44f926a4e95165e265d2cf60dee998 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Wed, 4 Mar 2026 11:16:25 +0100 Subject: [PATCH] crypto: fix importKey required argument count check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/62099 Reviewed-By: Tobias Nießen Reviewed-By: Colin Ihrig --- lib/internal/crypto/webcrypto.js | 2 +- test/parallel/test-webcrypto-export-import.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/internal/crypto/webcrypto.js b/lib/internal/crypto/webcrypto.js index 0fba4e9108c..031bb9a3669 100644 --- a/lib/internal/crypto/webcrypto.js +++ b/lib/internal/crypto/webcrypto.js @@ -865,7 +865,7 @@ async function importKey( webidl ??= require('internal/crypto/webidl'); const prefix = "Failed to execute 'importKey' on 'SubtleCrypto'"; - webidl.requiredArguments(arguments.length, 4, { prefix }); + webidl.requiredArguments(arguments.length, 5, { prefix }); format = webidl.converters.KeyFormat(format, { prefix, context: '1st argument', diff --git a/test/parallel/test-webcrypto-export-import.js b/test/parallel/test-webcrypto-export-import.js index faf7aef01a1..6c8f36a62ec 100644 --- a/test/parallel/test-webcrypto-export-import.js +++ b/test/parallel/test-webcrypto-export-import.js @@ -435,3 +435,11 @@ if (!process.features.openssl_is_boringssl) { subtle.importKey('jwk', jwk, { name: 'HMAC', hash: 'SHA3-256' }, false, ['sign', 'verify']).then(common.mustCall()); } } + +{ + const keyData = new Uint8Array(32); + assert.rejects( + subtle.importKey('raw', keyData, { name: 'HMAC', hash: 'SHA-256' }, false), + { code: 'ERR_MISSING_ARGS' } + ).then(common.mustCall()); +}