diff options
author | Tobias Nießen <tniessen@tnie.de> | 2019-07-23 15:12:32 +0200 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2019-07-26 10:19:28 -0700 |
commit | 499533f72a2dce111d6fde9c21b90b51fff35ab6 (patch) | |
tree | 158578631061383799317944243c883867758f72 /test | |
parent | 31d9b2f14fe9851b530c213b92e14b4646f6d131 (diff) | |
download | android-node-v8-499533f72a2dce111d6fde9c21b90b51fff35ab6.tar.gz android-node-v8-499533f72a2dce111d6fde9c21b90b51fff35ab6.tar.bz2 android-node-v8-499533f72a2dce111d6fde9c21b90b51fff35ab6.zip |
crypto: fix handling of malicious getters (scrypt)
It is possible to bypass parameter validation in crypto.scrypt and
crypto.scryptSync by crafting option objects with malicious getters as
demonstrated in the regression test. After bypassing validation, any
value can be passed to the C++ layer, causing an assertion to crash
the process.
Fixes: https://github.com/nodejs/node/issues/28836
PR-URL: https://github.com/nodejs/node/pull/28838
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-crypto-scrypt.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/test/parallel/test-crypto-scrypt.js b/test/parallel/test-crypto-scrypt.js index 63ddcdfb42..b5d6cbb4a8 100644 --- a/test/parallel/test-crypto-scrypt.js +++ b/test/parallel/test-crypto-scrypt.js @@ -235,3 +235,38 @@ for (const { args, expected } of badargs) { code: 'ERR_OUT_OF_RANGE' }); } + +{ + // Regression test for https://github.com/nodejs/node/issues/28836. + + function testParameter(name, value) { + let accessCount = 0; + + // Find out how often the value is accessed. + crypto.scryptSync('', '', 1, { + get [name]() { + accessCount++; + return value; + } + }); + + // Try to crash the process on the last access. + common.expectsError(() => { + crypto.scryptSync('', '', 1, { + get [name]() { + if (--accessCount === 0) + return ''; + return value; + } + }); + }, { + code: 'ERR_INVALID_ARG_TYPE' + }); + } + + [ + ['N', 16384], ['cost', 16384], + ['r', 8], ['blockSize', 8], + ['p', 1], ['parallelization', 1] + ].forEach((arg) => testParameter(...arg)); +} |