You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First, the illegitimate value NaN for the salt rounds parameter makes its way through the hashSync method because it has type 'number'.
Then the genSaltSync method is called and passed the salt rounds parameter NaN, where it is silently replaced by the default value, 10, because NaN is falsy.
This could be a problem if, for example, the value NaN was the result of a missing environment variable that had been coerced to a number from a string. I would expect there to be a warning, if not an error, since an error is thrown when 'undefined' or some other illegitimate value for the salt rounds parameter is passed to the hashSync method.
The end result is the number of salt rounds actually being used may be completely different from what was intended, but no warning is raised.
The text was updated successfully, but these errors were encountered:
p-brubaker
changed the title
hashSync method silently replaces NaN salt rounds value with 10
hashSync method silently replaces NaN salt rounds value with default value
Nov 13, 2021
First, the illegitimate value NaN for the salt rounds parameter makes its way through the hashSync method because it has type 'number'.
Then the genSaltSync method is called and passed the salt rounds parameter NaN, where it is silently replaced by the default value, 10, because NaN is falsy.
This could be a problem if, for example, the value NaN was the result of a missing environment variable that had been coerced to a number from a string. I would expect there to be a warning, if not an error, since an error is thrown when 'undefined' or some other illegitimate value for the salt rounds parameter is passed to the hashSync method.
The end result is the number of salt rounds actually being used may be completely different from what was intended, but no warning is raised.
Brief example code:
console output:
// node version: 16.9.1
// OS: Ubuntu 20.04.1 LTS (fossa-bulbasaur X54) 64-bit
The text was updated successfully, but these errors were encountered: