|
| 1 | +--- |
| 2 | +gem: jwt |
| 3 | +cve: 2026-45363 |
| 4 | +ghsa: c32j-vqhx-rx3x |
| 5 | +url: https://github.com/jwt/ruby-jwt/security/advisories/GHSA-c32j-vqhx-rx3x |
| 6 | +title: 'ruby-jwt: Empty-key HMAC bypass; cross-language sibling of CVE-2026-44351' |
| 7 | +date: 2026-05-18 |
| 8 | +description: | |
| 9 | + `JWT.decode(token, '', true, algorithm: 'HS256')` accepts an attacker-forged token. |
| 10 | + `OpenSSL::HMAC.digest('SHA256', '', payload)` returns a valid digest under an empty key, and no `raise |
| 11 | + InvalidKeyError if key.empty?` precondition exists in the HMAC algorithm. |
| 12 | +
|
| 13 | + ``` |
| 14 | + JWT.decode(token, "", true, algorithm: 'HS256') |
| 15 | + -> JWA::Hmac.verify(verification_key: "", ...) |
| 16 | + -> OpenSSL::HMAC.digest('SHA256', "", signing_input) == signature |
| 17 | + ``` |
| 18 | +
|
| 19 | + The same path is reached when a keyfinder block or key_finder: argument returns "", nil, or an |
| 20 | + array containing nil for an unknown key. JWT::Decode#find_key only rejects literal nil and empty |
| 21 | + arrays, and JWT::JWA::Hmac silently coerces nil to "" (signing_key ||= '') before signing. |
| 22 | +
|
| 23 | + ``` |
| 24 | + JWT.decode(token, nil, true, algorithms: ['HS256']) { |_h| "" } |
| 25 | + -> find_key returns "" # "" && !Array("").empty? == true |
| 26 | + -> JWA::Hmac.verify(verification_key: "", ...) |
| 27 | + -> verifies |
| 28 | + ``` |
| 29 | + Common application patterns that produce the unsafe value: `redis.get("kid:#{kid}").to_s`, ORM string columns with `default: ''`, `ENV['SECRET'] || '', Hash.new('')` lookups, [primary, fallback] where fallback may be nil. Applications passing a non-empty static key:, or whose keyfinder returns nil / raises on miss, are not affected. |
| 30 | +
|
| 31 | + The existing `enforce_hmac_key_length` option would block this but defaults to false. On OpenSSL ≥ 3.5 the empty-key HMAC.digest call no longer raises, so the OpenSSL-3.0 rescue in JWA::Hmac#sign does not fire. |
| 32 | +
|
| 33 | + Affects HS256/HS384/HS512 via both JWT.decode (positional key and block keyfinder) and |
| 34 | + `JWT::EncodedToken#verify_signature!(key_finder:)` |
| 35 | +cvss_v3: 7.4 |
| 36 | +patched_versions: |
| 37 | + - ">= 3.2.0" |
| 38 | +related: |
| 39 | + url: |
| 40 | + - https://github.com/jwt/ruby-jwt/security/advisories/GHSA-c32j-vqhx-rx3x |
| 41 | + - https://github.com/jwt/ruby-jwt/commit/db560b769a07bd9724e77ff505011ac01872106f |
| 42 | + - https://github.com/jwt/ruby-jwt/releases/tag/v3.2.0 |
| 43 | + - https://github.com/advisories/GHSA-c32j-vqhx-rx3x |
0 commit comments