crypto: handle PBKDF2 iteration limits · nodejs/node@d54a2b2 · GitHub
Skip to content

Commit d54a2b2

Browse files
panvaaduh95
authored andcommitted
crypto: handle PBKDF2 iteration limits
Report OperationError for unsupported iteration counts and return an empty result before invoking the backend when no output is requested. Signed-off-by: Filip Skokan <panva.ip@gmail.com> Assisted-by: Codex PR-URL: #66237 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Aviv Keller <me@aviv.sh>
1 parent 2ef6046 commit d54a2b2

5 files changed

Lines changed: 33 additions & 15 deletions

File tree

‎lib/internal/crypto/pbkdf2.js‎

Lines changed: 10 additions & 3 deletions

‎lib/internal/crypto/webcrypto.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1937,7 +1937,7 @@ function check(op, alg, length) {
19371937
}
19381938

19391939
if (normalizedAlgorithm.name === 'PBKDF2') {
1940-
require('internal/crypto/pbkdf2').validatePbkdf2DeriveBitsLength(length);
1940+
require('internal/crypto/pbkdf2').validatePbkdf2DeriveBits(normalizedAlgorithm, length);
19411941
}
19421942

19431943
if (StringPrototypeStartsWith(normalizedAlgorithm.name, 'Argon2')) {

‎lib/internal/crypto/webidl.js‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const {
1515
kEmptyObject,
1616
} = require('internal/util');
1717
const {
18-
isInt32,
1918
isUint32,
2019
} = require('internal/validators');
2120
const {
@@ -492,15 +491,6 @@ converters.Pbkdf2Params = createDictionaryConverter(
492491
key: 'iterations',
493492
converter: (V, opts) =>
494493
converters['unsigned long'](V, enforceRangeOptions(opts)),
495-
validator: (V, dict) => {
496-
if (V === 0)
497-
throw lazyDOMException('iterations cannot be zero', 'OperationError');
498-
if (!isInt32(V)) {
499-
throw lazyDOMException(
500-
'iterations exceeds the implementation limit',
501-
'NotSupportedError');
502-
}
503-
},
504494
required: true,
505495
},
506496
{

‎test/parallel/test-webcrypto-derivebits.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ const rejectsXCurves = hasFIPS(3, 5);
136136
salt: new Uint8Array([2]),
137137
iterations: 2 ** 31,
138138
}, key, 8),
139-
{ name: 'NotSupportedError' });
139+
{ name: 'OperationError' });
140140
}
141141

142142
test().then(common.mustCall());
Lines changed: 21 additions & 0 deletions

0 commit comments

Comments
 (0)