GHSA-f27w-vcwj-c954

Suggest an improvement
Source
https://github.com/advisories/GHSA-f27w-vcwj-c954
Import Source
https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/03/GHSA-f27w-vcwj-c954/GHSA-f27w-vcwj-c954.json
JSON Data
https://api.osv.dev/v1/vulns/GHSA-f27w-vcwj-c954
Aliases
Downstream
CGA (40)
Published
2026-03-19T17:54:17Z
Modified
2026-03-25T21:48:59Z
Severity
  • 4.5 (Medium) CVSS_V4 - 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 CVSS Calculator
Summary
bcrypt-ruby has an Integer Overflow that Causes Zero Key-Strengthening Iterations at Cost=31 on JRuby
Details

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. 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.

Patches

This problem has been fixed in version 3.1.22

Workarounds

Set the cost to something less than 31.

Database specific
{
    "cwe_ids":  [
        "CWE-190"
    ],
    "github_reviewed":  true,
    "github_reviewed_at":  "2026-03-19T17:54:17Z",
    "nvd_published_at":  "2026-03-24T01:17:02Z",
    "severity":  "MODERATE"
}
References

Affected packages

RubyGems / bcrypt

Package

Name
bcrypt
Purl
pkg:gem/bcrypt

Affected ranges

Type
ECOSYSTEM
Events
Introduced
0 Unknown introduced version / All previous versions are affected
Fixed
3.1.22

Affected versions

3.*
3.1.3
3.1.6
3.1.7
3.1.8
3.1.9
3.1.10
3.1.11
3.1.12.rc1
3.1.12
3.1.13
3.1.14
3.1.15
3.1.16
3.1.17
3.1.18
3.1.19
3.1.20
3.1.21

Database specific

last_known_affected_version_range
"<= 3.1.21"
source
"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/03/GHSA-f27w-vcwj-c954/GHSA-f27w-vcwj-c954.json"