
Cloud Vulnerability DB
A community-led vulnerabilities database
Fixed in jwe 1.1.2. DEF decompression now inflates incrementally and raises JWE::InvalidData when the decompressed content exceeds 1 MiB.
When JWE.decrypt processes an authenticated compact JWE with zip=DEF, ruby-jwe inflates the decrypted content without limiting its output size. A sender can use the recipient's public key to construct a valid token whose compressed content expands substantially during decryption.
jwe 1.1.1 is commit 0a210f19a8a76699c213e147abd9174fa64ffa32; default branch HEAD is 608da6e5e5f7b7851d5a412925677393d3c34128.lib/jwe.rb calls apply_zip after content decryption at release lines 41-51 and HEAD lines 41-51.lib/jwe/zip/def.rb reaches unbounded Zlib::Inflate.inflate at release lines 15-21 and HEAD lines 15-21. The release gem's affected source matches HEAD.I generated valid RSA JWEs locally and passed them to the public JWE.decrypt API. The controls and measurements below use the library defaults with the preconditions that the caller accepts RSA-encrypted JWE and zip=DEF.
| Input | Release 1.1.1 | Patched release and HEAD |
|---|---|---|
| Uncompressed and ordinary compressed content | Accepted | Accepted |
| 768 KiB and exactly 1 MiB compressed content | Accepted | Accepted |
| 1 MiB plus one byte | Accepted | Rejected with JWE::InvalidData |
| 8 MiB expansion from an 11,324-byte token | Returned 8,388,608 bytes; 740.8:1 output-to-token ratio; 32,416 KiB peak process RSS | Rejected with JWE::InvalidData; 25,988 KiB peak process RSS on patched HEAD |
| Raw DEFLATE and RFC 1950 wrapped DEFLATE | Accepted | Accepted by the public API and existing ZIP tests |
An application that decrypts attacker-submitted RSA JWEs and accepts zip=DEF can be made to inflate a small token into a much larger plaintext. The attacker needs no recipient secret because the recipient's RSA public key is enough to construct a valid encrypted token and authentication tag. For the measured input, the decrypt process reached 32,368 KiB RSS while returning 8 MiB of plaintext. Concurrent in-flight decryptions add their expanded plaintext to process memory demand and can exhaust the service's available memory. This does not bypass JWE authentication or disclose the recipient's key.
The patch changes the shared JWE::Zip::Def#decompress path to inflate incrementally and reject output above 1 MiB. It keeps both the raw DEFLATE and legacy RFC 1950 wrapped-DEFLATE paths. The focused JWE and ZIP specs passed all 21 examples on the patched tree.
diff --git a/lib/jwe/zip/def.rb b/lib/jwe/zip/def.rb
index e78676a..11b11ec 100644
--- a/lib/jwe/zip/def.rb
+++ b/lib/jwe/zip/def.rb
@@ -6,6 +6,8 @@ module JWE
module Zip
# Deflate algorithm.
class Def
+ MAX_DECOMPRESSED_SIZE = 1024 * 1024
+
def compress(payload)
zlib = Zlib::Deflate.new(Zlib::DEFAULT_COMPRESSION, -Zlib::MAX_WBITS)
zlib.deflate(payload, Zlib::FINISH)
@@ -13,12 +15,31 @@ module JWE
# Was using RFC 1950 instead of 1951.
def decompress(payload)
- Zlib::Inflate.inflate(payload)
+ decompress_bounded(payload, Zlib::MAX_WBITS)
# Keeping compatibility for old encoded tokens
rescue Zlib::DataError
- inflate = Zlib::Inflate.new(-Zlib::MAX_WBITS)
- inflate.inflate(payload)
+ decompress_bounded(payload, -Zlib::MAX_WBITS)
+ end
+
+ private
+
+ def decompress_bounded(payload, window_bits)
+ inflater = Zlib::Inflate.new(window_bits)
+ output = ''.b
+ inflater.inflate(payload) do |chunk|
+ if chunk.bytesize > MAX_DECOMPRESSED_SIZE - output.bytesize
+ raise JWE::InvalidData, 'Decompressed content exceeds the maximum size'
+ end
+ output << chunk
+ end
+ chunk = inflater.finish
+ if chunk.bytesize > MAX_DECOMPRESSED_SIZE - output.bytesize
+ raise JWE::InvalidData, 'Decompressed content exceeds the maximum size'
+ end
+ output << chunk
+ ensure
+ inflater.close if inflater && !inflater.closed?
end
end
endI searched the project's open and closed issues and pull requests for compression, inflate and decompression terms, and checked its active branches, release notes, README, GitHub advisories and OSV records. Issue #5 concerns outbound DEFLATE format, while issue #15 and PR #16 concern truncation during outbound compression. PR #16 changes compress, not decompress. The AES-GCM tag advisory affects versions through 1.1.0; its fix validates the authentication tag and does not cover unbounded inbound decompression. I found no public report or fix for this path.
Happy to share the token generator as a regression test.
Reported by Dickson Wu (SEAL & CertiK).
Source: NVD
Free Vulnerability Assessment
Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.
Get a personalized demo
"Best User Experience I have ever seen, provides full visibility to cloud workloads."
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
"We know that if Wiz identifies something as critical, it actually is."