]> git.kaiwu.me - njs.git/commitdiff
WebCrypto: reject HKDF output length mismatch
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 17 Nov 2026 01:09:28 +0000 (17:09 -0800)
committerDmitry Volyntsev <xeioexception@gmail.com>
Tue, 17 Nov 2026 22:09:33 +0000 (14:09 -0800)
Previously, when EVP_PKEY_derive() succeeded but returned fewer bytes
than requested, HKDF deriveBits() and deriveKey() set an exception but
the shared cleanup only checked the positive OpenSSL return value.
The operation then resolved with partially initialized output.

Mark the result as failed before jumping to the cleanup.

The issue was introduced in 7b2b7612 (0.7.0) and copied to QuickJS
in 75ca26f8 (0.8.10).

external/njs_webcrypto_module.c
external/qjs_webcrypto_module.c

index 45ddb4875989f1a1c4685e66422e5970d6232c1f..8d3fc5ee703bc6f9a9abf9302f55e68e53c01c06 100644 (file)
@@ -2087,6 +2087,7 @@ njs_ext_derive(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
         ret = EVP_PKEY_derive(pctx, k, &olen);
         if (njs_slow_path(ret <= 0 || olen != (size_t) length)) {
             njs_webcrypto_error(vm, "EVP_PKEY_derive() failed");
+            ret = NJS_ERROR;
             goto free;
         }
 
index 97108232cf5f552d179ab0ef5a591547e274dfc6..eb707c59011369848111bcf5e8027d25270dca4d 100644 (file)
@@ -2424,6 +2424,7 @@ qjs_webcrypto_derive(JSContext *cx, JSValueConst this_val, int argc,
         rc = EVP_PKEY_derive(pctx, k, &olen);
         if (rc <= 0 || olen != (size_t) length) {
             qjs_webcrypto_error(cx, "EVP_PKEY_derive() failed");
+            rc = -1;
             goto free;
         }