node/lib/internal/crypto
Jordan Harband d0f65e3579
crypto: coerce -0 keylen to +0 in pbkdf2 and scrypt
`validateInt32(keylen, 'keylen', 0)` lets `-0` through: `typeof -0` is
`'number'`, `Number.isInteger(-0)` is `true`, and `-0 < 0` is `false`.
The value then reaches the PBKDF2Job binding, whose `IsInt32()` check
fails (V8 boxes `-0` as a HeapNumber rather than a tagged SMI) and
aborts the process with SIGABRT.
Coerce `keylen` to `+0`
after validation so the binding sees a true Int32.

Reachable from any caller that forwards a JSON-parsed value,
since `JSON.parse('{"keylen":-0}').keylen` preserves the sign.

Mirror of the prior pbkdf2 fix. `validateInt32(keylen, 'keylen', 0)`
lets `-0` through (since `-0 < 0` is `false`), and the ScryptJob
binding's `IsInt32()` check at `crypto_scrypt.cc` aborts the process
with SIGABRT because V8 boxes `-0` as a HeapNumber rather than a
tagged SMI. Coerce `keylen` to `+0` after validation.

Signed-off-by: Jordan Harband <ljharb@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/63531
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2026-05-27 11:35:49 +02:00
..
aes.js doc,lib: align WebCrypto names with spec 2026-05-27 11:35:48 +02:00
argon2.js crypto: pass CryptoKey handles to KDF jobs 2026-05-27 11:35:45 +02:00
certificate.js
cfrg.js doc,lib: align WebCrypto names with spec 2026-05-27 11:35:48 +02:00
chacha20_poly1305.js doc,lib: align WebCrypto names with spec 2026-05-27 11:35:48 +02:00
cipher.js crypto: align key argument names in docs and error messages 2026-05-05 16:19:21 +02:00
diffiehellman.js crypto: harden WebCrypto against prototype pollution 2026-05-27 11:35:45 +02:00
ec.js doc,lib: align WebCrypto names with spec 2026-05-27 11:35:48 +02:00
hash.js crypto: add WebCrypto CryptoJob mode 2026-05-27 11:35:45 +02:00
hashnames.js crypto: add SHA-3 Web Cryptography digest algorithms 2025-08-19 15:55:57 +02:00
hkdf.js crypto: pass CryptoKey handles to KDF jobs 2026-05-27 11:35:45 +02:00
kem.js crypto: unify asymmetric key import through KeyObjectHandle::Init 2026-04-14 11:00:12 +01:00
keygen.js crypto: reject inherited key type names 2026-05-05 16:19:36 +02:00
keys.js crypto: harden CryptoKey algorithm slots 2026-05-19 14:08:17 +02:00
mac.js doc,lib: align WebCrypto names with spec 2026-05-27 11:35:48 +02:00
ml_dsa.js doc,lib: align WebCrypto names with spec 2026-05-27 11:35:48 +02:00
ml_kem.js doc,lib: align WebCrypto names with spec 2026-05-27 11:35:48 +02:00
pbkdf2.js crypto: coerce -0 keylen to +0 in pbkdf2 and scrypt 2026-05-27 11:35:49 +02:00
random.js crypto: implement randomUUIDv7() 2026-05-05 16:19:18 +02:00
rsa.js doc,lib: align WebCrypto names with spec 2026-05-27 11:35:48 +02:00
scrypt.js crypto: coerce -0 keylen to +0 in pbkdf2 and scrypt 2026-05-27 11:35:49 +02:00
sig.js crypto: align verifyOneShot accepted types 2026-05-19 21:55:37 +02:00
util.js test: cover webcrypto prototype pollution systematically 2026-05-27 11:35:49 +02:00
webcrypto.js doc,lib: align WebCrypto names with spec 2026-05-27 11:35:48 +02:00
webcrypto_util.js src: decouple KeyObject and CryptoKey and move CryptoKey to src 2026-05-05 16:21:26 +02:00
webidl.js crypto: wire ML-DSA and ML-KEM for use when using BoringSSL 2026-05-19 14:08:25 +02:00
x509.js crypto: harden KeyObject internal slots 2026-05-19 14:08:17 +02:00