| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
These tests currently FAIL, exposing a potential vulnerability where non-numeric round values in salt strings bypass bcrypt's work factor. The vulnerability: - Salt like "$2b$xx$..." causes parseInt to return NaN - NaN bypasses rounds validation (NaN < 4 and NaN > 31 are both false) - 1 << NaN becomes 1 << 0 = 1, reducing bcrypt to a single round - This makes the resulting hash trivially crackable Red Tests added: - invalidRoundsNaNProducesWeakHash: hash contains "$NaN$" - invalidRoundsNaN: fully non-numeric rounds "xx" - invalidRoundsNaNAsync: async version via callback - invalidRoundsPartialNaN: partial non-numeric "1x" **Severity: LOW** In most real-world scenarios, salts come from genSalt() which always produces valid output. The malformed salt would have to come from: - A buggy application - Corrupted data - Deliberately malicious input to compare()
The fix validates that rounds contains exactly 2 digits before parsing, rejecting malformed salts with a clear error message. Red tests are now green: - invalidRoundsNaN: fully non-numeric rounds "xx" - invalidRoundsNaNAsync: async version via callback - invalidRoundsPartialNaN: partial non-numeric "1x" - validRoundsLeadingZero: rounds can start with 0 - invalidRoundsZero: 0 rounds are rejected - invalidRounds32: 32 rounds are rejected Updated tests: - invalidRoundsNaNProducesWeakHash: invalid rounds throw
| Back | FazBrowse Home | New Git URL |
Non-numeric characters in the rounds position (e.g., $2b$xx$...) causes parseInt to return NaN, which bypasses security validation and reduced bcrypt to a single round.
Fixes #167
Location
index.js lines 1078-1080:
The Bug
When non-numeric characters are in the rounds position, parseInt returns NaN:
Red tests added to demonstrate issue:
The Fix
The fix validates that rounds contains exactly 2 digits before parsing, rejecting malformed salts with a clear error message.
Severity: LOW
In most real-world scenarios, salts come from genSalt() which always produces valid output. The malformed salt would have to come from:
The real value of this fix is: