bcrypt-ruby has an Integer Overflow that Causes Zero Key-Strengthening Iterations at Cost=31 on JRuby
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.
- Products
- Not specified
- Affected versions
- Not specified
- Fixed versions
- Not specified
- CVEs
- CVE-2026-33306
- Confirmed fixed CVEs
- Not specified
- Updated in this feed
- 4 Nov 2026, 02:01 UTC · Revision 1
Source evidence
bcrypt-ruby has an Integer Overflow that Causes Zero Key-Strengthening Iterations at Cost=31 on JRuby
core-osv · Original sourcePublished 24 Mar 2026, 00:08 UTC
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.
osv:CVE-2026-33306
Complete source record
{
"id": "3f9d4031a6e4948ac20223d947732c45e2938aa5a60ae5bcc6cba3f68166943c",
"url": "https://osv.dev/vulnerability/CVE-2026-33306",
"method": "structured",
"payload": {
"kind": "advisory",
"title": "bcrypt-ruby has an Integer Overflow that Causes Zero Key-Strengthening Iterations at Cost=31 on JRuby",
"summary": "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.",
"evidence": "osv:CVE-2026-33306",
"products": [],
"severity": "medium",
"structured": {
"id": "CVE-2026-33306",
"aliases": [
"CVE-2026-33306",
"GHSA-f27w-vcwj-c954"
],
"metrics": [
{
"type": "CVSS_V4",
"score": "CVSS:4.0/AV:L/AC:H/AT:P/PR:N/UI:N/VC:H/VI:H/VA:N/SC:N/SI:N/SA:N/E:U"
}
],
"affected": [
{
"ranges": [
{
"repo": "https://github.com/bcrypt-ruby/bcrypt-ruby",
"type": "GIT",
"events": [
{
"introduced": "0"
},
{
"fixed": "831ce64cb0a9502130fa93a28bfd9527a5fa45c4"
}
],
"database_specific": {
"extracted_events": [
{
"range": [
{
"introduced": "0"
},
{
"fixed": "3.1.22"
}
],
"source": "AFFECTED_FIELD",
"strategy": "StringRangeExpression"
},
{
"range": [
{
"fixed": "831ce64cb0a9502130fa93a28bfd9527a5fa45c4"
}
],
"source": "REFERENCES_COMMIT"
},
{
"range": [
{
"fixed": "831ce64cb0a9502130fa93a28bfd9527a5fa45c4"
}
],
"source": "REFERENCES_TAG",
"original_tag": "v3.1.22"
},
{
"cpe": "cpe:2.3:a:bcrypt-ruby_project:bcrypt-ruby:*:*:*:*:*:ruby:*:*",
"range": [
{
"introduced": "0"
},
{
"fixed": "3.1.22"
}
],
"source": "CPE_RANGE"
}
]
}
}
],
"versions": [
"v3.1.21",
"v3.1.20",
"v3.1.19",
"v3.1.18",
"v3.1.17",
"v3.1.16",
"v3.1.15",
"v3.1.14",
"v3.1.13",
"v3.1.12",
"v3.1.11",
"v3.1.10",
"v3.1.9",
"v3.1.8",
"v3.1.7",
"v3.1.6",
"v3.1.3",
"v3.1.1",
"v3.0.1",
"v3.0.0",
"rel_2_1_2",
"rel_2_1_1",
"rel_2_1_0",
"rel_2_0_5",
"rel_2_0_4",
"rel_2_0_3"
],
"database_specific": {
"source": "https://storage.googleapis.com/cve-osv-conversion/osv-output/CVE-2026-33306.json"
}
}
],
"modified": "2026-10-28T02:30:32.550283115Z",
"provider": "osv",
"references": [
"https://github.com/bcrypt-ruby/bcrypt-ruby/releases/tag/v3.1.22",
"https://github.com/CVEProject/cvelistV5/tree/main/cves/2026/33xxx/CVE-2026-33306.json",
"https://github.com/bcrypt-ruby/bcrypt-ruby/security/advisories/GHSA-f27w-vcwj-c954",
"https://nvd.nist.gov/vuln/detail/CVE-2026-33306",
"https://github.com/bcrypt-ruby/bcrypt-ruby/commit/831ce64cb0a9502130fa93a28bfd9527a5fa45c4"
],
"provider_metadata": {
"cwe_ids": [
"CWE-190"
],
"cna_assigner": "GitHub_M",
"osv_generated_from": "https://github.com/CVEProject/cvelistV5/tree/main/cves/2026/33xxx/CVE-2026-33306.json"
}
},
"related_cves": [
{
"value": "CVE-2026-33306",
"evidence": "/id"
}
],
"security_relevant": true,
"severity_evidence": "/severity/0/score"
},
"source_id": "core-osv",
"document_id": 499527,
"published_at": "2026-03-24T00:08:00.451+00:00"
}