]> git.kaiwu.me - njs.git/commit
WebCrypto: fix crypto.getRandomValues() with non-buffer arguments
authorDmitry Volyntsev <xeioex@nginx.com>
Fri, 30 Oct 2026 02:10:44 +0000 (19:10 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Mon, 2 Nov 2026 14:42:35 +0000 (06:42 -0800)
commit76b231ac95dca479c7b4312ccfc0167f3609e526
tree5a4700a31841f677b6d263c3238f68e7b7339955
parent45fd801fce15afb43a2ef0c586e39126b997fcd8
WebCrypto: fix crypto.getRandomValues() with non-buffer arguments

Previously, crypto.getRandomValues() obtained the destination bytes
with njs_vm_value_to_bytes(), which also accepts strings and does not
make a private copy of shared data.  As a result:

  - for a string argument the random bytes were written into the
    string data, which may be shared with other strings, including
    literals in the script;
  - for r.requestBuffer in nginx the request body seen by subsequent
    reads was modified.

Now, only typed arrays and DataView objects are accepted, and the
buffer is made writable before the write.

The issue was introduced in 7b2b7612 (0.7.0).
external/njs_webcrypto_module.c
src/test/njs_unit_test.c