]> git.kaiwu.me - njs.git/commitdiff
WebCrypto: free RSA modulus when exponent import fails in njs
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 17 Nov 2026 20:35:56 +0000 (12:35 -0800)
committerDmitry Volyntsev <xeioexception@gmail.com>
Tue, 17 Nov 2026 22:09:33 +0000 (14:09 -0800)
Previously, importing an RSA JWK key leaked the already decoded
modulus when decoding the exponent failed, for example when "e" was
longer than 512 bytes.

Free it, as the QuickJS implementation does.

The issue was introduced in 50e7c9b2 (0.7.10).

external/njs_webcrypto_module.c

index 23d0b96dd60773418a7a2f260de3743ff1ca8865..1df19647f38f6376deea1cc3c5f013f4c2827dd0 100644 (file)
@@ -3363,6 +3363,7 @@ fail0:
 
     e_bn = njs_import_base64url_bignum(vm, &e);
     if (njs_slow_path(e_bn == NULL)) {
+        BN_free(n_bn);
         goto fail;
     }