]> git.kaiwu.me - njs.git/commit
WebCrypto: reject out-of-range AES-CTR counter length master
authorbasavaraj-sm05 <basavaraj@digiscrypt.com>
Fri, 20 Nov 2026 16:57:11 +0000 (22:27 +0530)
committerDmitry Volyntsev <xeioexception@gmail.com>
Sat, 21 Nov 2026 23:49:08 +0000 (15:49 -0800)
commit997957b3dbc7716344b8c9747e96bd04f3102a30
treec8585604f06a2c351f9cc13ca61a3e556ec0a5a0
parent182051f2fa58fcd8ab4751ee5552235ba0b448a6
WebCrypto: reject out-of-range AES-CTR counter length

The AES-CTR counter length from algorithm.length was read as a signed
integer and only rejected when it was zero or above 128, so a negative
value passed the check.  It was then handed to njs_bn_counter128(),
whose bits parameter is njs_uint_t (uintptr_t on 64-bit builds), so a
negative length turned into a very large unsigned count.  The derived
byte count then drove a memcpy() into a 16-byte stack buffer with an
attacker-influenced size, overflowing it and reading past the counter
block.  The value reaches here directly from crypto.subtle.encrypt()
and decrypt() calls on both engines.

Reject any length below 1 as well, matching the 1 to 128 range the
error message already states and the WebCrypto specification requires.
external/njs_webcrypto_module.c
external/qjs_webcrypto_module.c
test/webcrypto/aes.t.mjs