Security Vulnerability Report
中文
CVE-2026-33306 CVSS 7.5 HIGH

CVE-2026-33306

Published: 2026-03-24 01:17:02
Last Modified: 2026-03-30 14:07:23

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 Details

CVSS Score
7.5
Severity
HIGH
CVSS Vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N

Configurations (Affected Products)

cpe:2.3:a:bcrypt-ruby_project:bcrypt-ruby:*:*:*:*:*:ruby:*:* - VULNERABLE
bcrypt-ruby < 3.1.22

PoC / Exploit Code

⚠ For Security Research Only
The following code is for security research and authorized testing only.
python
require 'bcrypt' # PoC for CVE-2026-33306: Integer Overflow in bcrypt-ruby for JRuby # This script demonstrates that setting cost=31 results in zero iterations, # making the hash generation instant instead of taking 2^31 rounds. password = "test_password" puts "Testing bcrypt with cost=31 on JRuby..." start_time = Time.now # Generate hash with max cost (triggers the vulnerability) # On a patched version, this would take a very long time. hash = BCrypt::Password.create(password, :cost => 31) end_time = Time.now time_taken = end_time - start_time puts "Generated Hash: #{hash}" puts "Time elapsed: #{time_taken} seconds" if time_taken < 1.0 puts "[!] Vulnerability detected: Hash generation was too fast (zero iterations)." else puts "[+] System appears patched or cost is handled correctly." end

References

Raw JSON Data

JSON
{"cve": {"id": "CVE-2026-33306", "sourceIdentifier": "[email protected]", "published": "2026-03-24T01:17:02.037", "lastModified": "2026-03-30T14:07:23.300", "vulnStatus": "Analyzed", "cveTags": [], "descriptions": [{"lang": "en", "value": "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."}, {"lang": "es", "value": "bcrypt-ruby es un enlace Ruby para el algoritmo de hash de contraseñas bcrypt() de OpenBSD. Antes de la versión 3.1.22, un desbordamiento de entero en la implementación Java de BCrypt para JRuby puede causar cero iteraciones en el bucle de fortalecimiento. Las aplicaciones afectadas deben estar configurando el costo en 31 para que esto ocurra. La implementación de JRuby de bcrypt-ruby ('BCrypt.java') calcula el recuento de rondas de fortalecimiento de clave como un entero con signo de 32 bits. Cuando 'cost=31' (el máximo permitido por la gema), el desbordamiento de entero con signo hace que el recuento de rondas se vuelva negativo, y el bucle de fortalecimiento ejecuta cero iteraciones. Esto colapsa bcrypt de 2^31 rondas de fortalecimiento exponencial de clave a una computación en tiempo efectivamente constante — solo quedan la configuración inicial de clave EksBlowfish y la fase final de cifrado 64x. El hash resultante parece válido ('$2a$31$...') y se verifica correctamente a través de 'checkpw', haciendo que la debilidad sea invisible para la aplicación. Este problema se activa solo cuando se usa cost=31 o al verificar un hash '$2a$31$'. Este problema ha sido solucionado en la versión 3.1.22. Como solución alternativa, configure el costo en algo menor que 31."}], "metrics": {"cvssMetricV40": [{"source": "[email protected]", "type": "Secondary", "cvssData": {"version": "4.0", "vectorString": "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/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X", "baseScore": 4.5, "baseSeverity": "MEDIUM", "attackVector": "LOCAL", "attackComplexity": "HIGH", "attackRequirements": "PRESENT", "privilegesRequired": "NONE", "userInteraction": "NONE", "vulnConfidentialityImpact": "HIGH", "vulnIntegrityImpact": "HIGH", "vulnAvailabilityImpact": "NONE", "subConfidentialityImpact": "NONE", "subIntegrityImpact": "NONE", "subAvailabilityImpact": "NONE", "exploitMaturity": "UNREPORTED", "confidentialityRequirement": "NOT_DEFINED", "integrityRequirement": "NOT_DEFINED", "availabilityRequirement": "NOT_DEFINED", "modifiedAttackVector": "NOT_DEFINED", "modifiedAttackComplexity": "NOT_DEFINED", "modifiedAttackRequirements": "NOT_DEFINED", "modifiedPrivilegesRequired": "NOT_DEFINED", "modifiedUserInteraction": "NOT_DEFINED", "modifiedVulnConfidentialityImpact": "NOT_DEFINED", "modifiedVulnIntegrityImpact": "NOT_DEFINED", "modifiedVulnAvailabilityImpact": "NOT_DEFINED", "modifiedSubConfidentialityImpact": "NOT_DEFINED", "modifiedSubIntegrityImpact": "NOT_DEFINED", "modifiedSubAvailabilityImpact": "NOT_DEFINED", "Safety": "NOT_DEFINED", "Automatable": "NOT_DEFINED", "Recovery": "NOT_DEFINED", "valueDensity": "NOT_DEFINED", "vulnerabilityResponseEffort": "NOT_DEFINED", "providerUrgency": "NOT_DEFINED"}}], "cvssMetricV31": [{"source": "[email protected]", "type": "Primary", "cvssData": {"version": "3.1", "vectorString": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N", "baseScore": 7.5, "baseSeverity": "HIGH", "attackVector": "NETWORK", "attackComplexity": "LOW", "privilegesRequired": "NONE", "userInteraction": "NONE", "scope": "UNCHANGED", "confidentialityImpact": "HIGH", "integrityImpact": "NONE", "availabilityImpact": "NONE"}, "exploitabilityScore": 3.9, "impactScore": 3.6}]}, "weaknesses": [{"source": "[email protected]", "type": "Primary", "description": [{"lang": "en", "value": "CWE-190"}]}], "configurations": [{"nodes": [{"operator": "OR", "negate": false, "cpeMatch": [{"vulnerable": true, "criteria": "cpe:2.3:a:bcrypt-ruby_pr ... (truncated)