bcrypt-ruby has an Integer Overflow that Causes Zero Key-Strengthening Iterations at Cost=31 on JRuby
Moderate severity
GitHub Reviewed
Published
Mar 18, 2026
in
bcrypt-ruby/bcrypt-ruby
•
Updated Mar 25, 2026
Description
Published to the GitHub Advisory Database
Mar 19, 2026
Reviewed
Mar 19, 2026
Published by the National Vulnerability Database
Mar 24, 2026
Last updated
Mar 25, 2026
Impact
An integer overflow in the Java BCrypt implementation for JRuby can cause zero iterations in the strengthening loop. Impacted applications must be setting the cost to 31 to see this happen.
The JRuby implementation of bcrypt-ruby (
BCrypt.java) computes the key-strengthening round count as a signed 32-bit integer. Whencost=31(the maximum allowed by the gem), signed integer overflow causes the round count to become negative, and the strengthening loop executes zero iterations. This collapses bcrypt from 2^31 rounds of exponential key-strengthening to effectively constant-time computation — only the initial EksBlowfish key setup and final 64x encryption phase remain.The resulting hash looks valid (
$2a$31$...) and verifies correctly viacheckpw, making the weakness invisible to the application. This issue is triggered only when cost=31 is used or when verifying a$2a$31$hash.Patches
This problem has been fixed in version 3.1.22
Workarounds
Set the cost to something less than 31.
References