CVE-2026-33306: Bcrypt Bcrypt-ruby Has An Integer Overflow Vulnerability

MODERATE
Advisory Identifier: GHSA-f27w-vcwj-c954
CWE-190
Published
Advisory Summary

CVE-2026-33306 is a MODERATE bcrypt-ruby has an integer overflow vulnerability (CWE-190: Integer Overflow or Wraparound) affecting Bcrypt libraries in the RubyGems ecosystem. The issue involves bcrypt-ruby has an integer overflow that causes zero key-strengthening iterations at cost=31 on jruby. Remediation is available by upgrading affected packages to version 3.1.22.

CVE-2026-33306 at a Glance

CVE Identifier CVE-2026-33306
GHSA Identifier GHSA-f27w-vcwj-c954
Severity MODERATE
CVSS v3.1 Base Score N/A
CWE Classification CWE-190: Integer Overflow or Wraparound
Affected Product Bcrypt
Package Ecosystem RubyGems
Published Date
Last Updated

How to Fix CVE-2026-33306

To remediate this vulnerability, upgrade all affected Bcrypt dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

bcrypt fixed: 3.1.22
Upgrade bcrypt to 3.1.22
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for bcrypt

How to Check if You Are Affected

To determine whether your application is affected by CVE-2026-33306, inspect your project dependencies for Bcrypt:

inspect dependencies for bcrypt

Analyze the terminal output to locate any version of Bcrypt in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 3.1.22), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-190: Integer Overflow or Wraparound, where 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. In Bcrypt, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

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

CVE-2026-33306 Affected Bcrypt Versions

1 component(s)
Fixed Versions:
3.1.22
Product / Package Ecosystem Affected Versions Fixed Version
bcrypt
RubyGems
< 3.1.22
3.1.22

References

Frequently Asked Questions

What is CVE-2026-33306?
CVE-2026-33306 is a security vulnerability in Bcrypt involving bcrypt-ruby has an Integer Overflow that Causes Zero Key-Strengthening Iterations at Cost=31 on JRuby under CWE-190: Integer Overflow or Wraparound.
Which Bcrypt versions are affected?
Affected versions include releases prior to 3.1.22 across affected packages: bcrypt.
What version fixes CVE-2026-33306?
Upgrading to 3.1.22 (or the latest patched release for your respective branch) resolves the vulnerability.
Is bcrypt affected?
Yes, bcrypt is affected in releases prior to 3.1.22. Upgrade your dependency to 3.1.22 or later.
What CWE is associated with CVE-2026-33306?
CVE-2026-33306 is classified under CWE-190: Integer Overflow or Wraparound (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.).
How can I check RubyGems dependencies for CVE-2026-33306?
Run the dependency tree command: 'inspect dependencies for bcrypt'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-f27w-vcwj-c954",
  "modified" : "2026-03-25T21:36:33Z",
  "published" : "2026-03-19T17:54:17Z",
  "aliases" : [ "CVE-2026-33306" ],
  "summary" : "bcrypt-ruby has an Integer Overflow that Causes Zero Key-Strengthening Iterations at Cost=31 on JRuby",
  "details" : "### Impact\n\nAn 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.\n\nThe 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.\n\nThe 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.\n\n### Patches\n\nThis problem has been fixed in version 3.1.22\n\n### Workarounds\n\nSet the cost to something less than 31.",
  "severity" : [ {
    "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" : [ {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "bcrypt"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "3.1.22"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 3.1.21"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/bcrypt-ruby/bcrypt-ruby/security/advisories/GHSA-f27w-vcwj-c954"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-33306"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/bcrypt-ruby/bcrypt-ruby/commit/831ce64cb0a9502130fa93a28bfd9527a5fa45c4"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/bcrypt-ruby/bcrypt-ruby"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/bcrypt-ruby/bcrypt-ruby/releases/tag/v3.1.22"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rubysec/ruby-advisory-db/blob/master/gems/bcrypt/CVE-2026-33306.yml"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-190" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-03-19T17:54:17Z",
    "nvd_published_at" : "2026-03-24T01:17:02Z"
  }
}