From c4ca303b366cd8fe67374dec2ad6667830cc466f Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Thu, 23 Apr 2026 20:19:31 +0200 Subject: [PATCH] lib: harden kKeyOps lookup with null prototype 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/62877 Reviewed-By: René Reviewed-By: Jordan Harband Reviewed-By: Tobias Nießen --- lib/internal/crypto/util.js | 1 + test/parallel/test-webcrypto-util.js | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/internal/crypto/util.js b/lib/internal/crypto/util.js index 70e10279461..ef0506f3034 100644 --- a/lib/internal/crypto/util.js +++ b/lib/internal/crypto/util.js @@ -764,6 +764,7 @@ function getDigestSizeInBytes(name) { } const kKeyOps = { + __proto__: null, sign: 1, verify: 2, encrypt: 3, diff --git a/test/parallel/test-webcrypto-util.js b/test/parallel/test-webcrypto-util.js index 89d8575e20d..8e139f4d5a8 100644 --- a/test/parallel/test-webcrypto-util.js +++ b/test/parallel/test-webcrypto-util.js @@ -9,6 +9,7 @@ const assert = require('assert'); const { normalizeAlgorithm, + validateKeyOps, } = require('internal/crypto/util'); { @@ -49,3 +50,12 @@ const { assert.strictEqual(normalized.name, 'ECDSA'); assert.strictEqual(nameReadCount, 1); } + +{ + for (const ops of [ + ['sign', 'toString', 'constructor'], + ['sign', '__proto__', 'constructor'], + ]) { + validateKeyOps(ops); + } +}