Skip to content

Commit a6eede3

Browse files
aduh95marco-ippolito
authored andcommitted
crypto: fix input validation in crypto.hash
PR-URL: #52070 Refs: https://github.com/nodejs/node/pull/51044/files#r1522362983 Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent e5521b5 commit a6eede3

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

lib/internal/crypto/hash.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ const {
5252
validateEncoding,
5353
validateString,
5454
validateUint32,
55-
validateBuffer,
5655
} = require('internal/validators');
5756

5857
const {
@@ -196,8 +195,8 @@ async function asyncDigest(algorithm, data) {
196195

197196
function hash(algorithm, input, outputEncoding = 'hex') {
198197
validateString(algorithm, 'algorithm');
199-
if (typeof input !== 'string') {
200-
validateBuffer(input, 'input');
198+
if (typeof input !== 'string' && !isArrayBufferView(input)) {
199+
throw new ERR_INVALID_ARG_TYPE('input', ['Buffer', 'TypedArray', 'DataView', 'string'], input);
201200
}
202201
let normalized = outputEncoding;
203202
// Fast case: if it's 'hex', we don't need to validate it further.

0 commit comments

Comments
 (0)