CVE-2026-33306
Received Received - Intake
Integer Overflow in bcrypt-ruby JRuby Causes Zero Iterations

Publication date: 2026-03-24

Last updated on: 2026-03-30

Assigner: GitHub, Inc.

Description
bcrypt-ruby is a Ruby binding for the OpenBSD bcrypt() password hashing algorithm. Prior to version 3.1.22, 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. When `cost=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 via `checkpw`, making the weakness invisible to the application. This issue is triggered only when cost=31 is used or when verifying a `$2a$31$` hash. This problem has been fixed in version 3.1.22. As a workaround, set the cost to something less than 31.
CVSS Scores
EPSS Scores
Probability:
Percentile:
Meta Information
Published
2026-03-24
Last Modified
2026-03-30
Generated
2026-05-07
AI Q&A
2026-03-24
EPSS Evaluated
2026-05-05
NVD
Affected Vendors & Products
Showing 1 associated CPE
Vendor Product Version / Range
bcrypt-ruby_project bcrypt-ruby to 3.1.22 (exc)
Helpful Resources
Exploitability
CWE
CWE Icon
KEV
KEV Icon
CWE ID Description
CWE-190 The product performs a calculation that can produce an integer overflow or wraparound when the logic assumes that the resulting value will always be larger than the original value. This occurs when an integer value is incremented to a value that is too large to store in the associated representation. When this occurs, the value may become a very small or negative number.
Attack-Flow Graph
AI Powered Q&A
Can you explain this vulnerability to me?

CVE-2026-33306 is an integer overflow vulnerability in the Java BCrypt implementation used by the JRuby bcrypt-ruby gem versions up to 3.1.21. When the cost parameter is set to 31, the maximum allowed, the calculation of the key-strengthening round count overflows a signed 32-bit integer, resulting in a negative value.

This causes the key-strengthening loop to execute zero iterations instead of the intended 2^31 rounds, effectively reducing the computational cost from exponential to near constant time. Despite this, the generated hash retains a valid format and passes verification, making the vulnerability difficult to detect during normal use.

The issue only occurs when the cost is exactly 31 or when verifying hashes with cost 31. It was fixed in version 3.1.22 of bcrypt-ruby. A workaround is to use a cost value less than 31.


How can this vulnerability impact me? :

This vulnerability can significantly weaken the security of password hashing when the cost parameter is set to 31. Instead of performing the intended exponential number of key-strengthening rounds, the hashing process executes zero strengthening iterations, making it much faster and easier for attackers to perform brute-force or dictionary attacks.

Because the resulting hash appears valid and verifies correctly, applications may not detect the weakened hashing, potentially exposing user passwords to compromise.


How does this vulnerability affect compliance with common standards and regulations (like GDPR, HIPAA)?:

I don't know


How can this vulnerability be detected on my network or system? Can you suggest some commands?

[{'type': 'paragraph', 'content': 'This vulnerability occurs only when the bcrypt-ruby gem is used with the cost parameter set to 31, or when verifying hashes with cost 31 (formatted as $2a$31$...). The resulting hash looks valid and verifies correctly, making the weakness invisible during normal operation.'}, {'type': 'paragraph', 'content': 'To detect this vulnerability on your system, you should check if any bcrypt hashes use the cost factor 31. This can be done by searching for bcrypt hashes starting with "$2a$31$" in your stored password hashes or logs.'}, {'type': 'paragraph', 'content': 'Example command to find such hashes in a file containing password hashes:'}, {'type': 'list_item', 'content': "grep '^\\$2a\\$31\\$' /path/to/password_hashes_file"}, {'type': 'paragraph', 'content': 'If you find hashes with cost 31, your system may be affected if it uses the vulnerable bcrypt-ruby version (≀ 3.1.21) on JRuby.'}] [1]


What immediate steps should I take to mitigate this vulnerability?

The vulnerability has been fixed in bcrypt-ruby version 3.1.22. The immediate mitigation steps are:

  • Upgrade the bcrypt-ruby gem to version 3.1.22 or later.
  • If upgrading immediately is not possible, configure your application to use a cost parameter less than 31 when generating or verifying bcrypt hashes.

These steps prevent the integer overflow that causes the key-strengthening loop to execute zero iterations, restoring the intended security level of bcrypt.


Ask Our AI Assistant
Need more information? Ask your question to get an AI reply (Powered by our expertise)
0/70
EPSS Chart