From 6eea52426f7d74d64fc4d3bdfe03b19c3d5b834f Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Sat, 25 Apr 2026 09:14:57 +0200 Subject: [PATCH] crypto: reject duplicate ML-KEM JWK key_ops MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filip Skokan PR-URL: https://github.com/nodejs/node/pull/62905 Reviewed-By: Yagiz Nizipli Reviewed-By: Сковорода Никита Андреевич --- lib/internal/crypto/util.js | 4 ++++ .../parallel/test-webcrypto-export-import-ml-kem.js | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/internal/crypto/util.js b/lib/internal/crypto/util.js index d890e8ed3f1..181d07a07cf 100644 --- a/lib/internal/crypto/util.js +++ b/lib/internal/crypto/util.js @@ -801,6 +801,10 @@ const kKeyOps = { unwrapKey: 6, deriveKey: 7, deriveBits: 8, + encapsulateKey: 9, + encapsulateBits: 10, + decapsulateKey: 11, + decapsulateBits: 12, }; function validateKeyOps(keyOps, usagesSet) { diff --git a/test/parallel/test-webcrypto-export-import-ml-kem.js b/test/parallel/test-webcrypto-export-import-ml-kem.js index 50f3444ce87..8b94f26e6f8 100644 --- a/test/parallel/test-webcrypto-export-import-ml-kem.js +++ b/test/parallel/test-webcrypto-export-import-ml-kem.js @@ -321,3 +321,16 @@ async function testImportRawSeed({ name, privateUsages }, extractable) { }); } })().then(common.mustCall()); + +// Regression test: JWK `key_ops` validation must recognize ML-KEM operations +// (encapsulateKey, encapsulateBits, decapsulateKey, decapsulateBits) so that +// duplicate entries are rejected +(async function() { + for (const op of ['encapsulateKey', 'encapsulateBits', + 'decapsulateKey', 'decapsulateBits']) { + const jwk = { ...keyData['ML-KEM-768'].jwk, key_ops: [op, op] }; + await assert.rejects( + subtle.importKey('jwk', jwk, { name: 'ML-KEM-768' }, true, [op]), + { name: 'DataError', message: /Duplicate key operation/ }); + } +})().then(common.mustCall());