Skip to content

Commit

Permalink
crypto: fix input validation in crypto.hash
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
aduh95 authored and marco-ippolito committed May 3, 2024
1 parent e5521b5 commit a6eede3
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/internal/crypto/hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ const {
validateEncoding,
validateString,
validateUint32,
validateBuffer,
} = require('internal/validators');

const {
Expand Down Expand Up @@ -196,8 +195,8 @@ async function asyncDigest(algorithm, data) {

function hash(algorithm, input, outputEncoding = 'hex') {
validateString(algorithm, 'algorithm');
if (typeof input !== 'string') {
validateBuffer(input, 'input');
if (typeof input !== 'string' && !isArrayBufferView(input)) {
throw new ERR_INVALID_ARG_TYPE('input', ['Buffer', 'TypedArray', 'DataView', 'string'], input);
}
let normalized = outputEncoding;
// Fast case: if it's 'hex', we don't need to validate it further.
Expand Down

0 comments on commit a6eede3

Please sign in to comment.