From dd86d75086723b271c8d30112de0ab2bbe142569 Mon Sep 17 00:00:00 2001 From: starlet-dx <15929766099@163.com> Date: Fri, 8 Mar 2024 10:49:08 +0800 Subject: [PATCH] Fix CVE-2024-28102 (cherry picked from commit ae0980184c1529bb57d2731cc68e0d6fc43dccfe) --- CVE-2024-28102.patch | 75 ++++++++++++++++++++++++++++++++++++++++++++ python-jwcrypto.spec | 7 ++++- 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 CVE-2024-28102.patch diff --git a/CVE-2024-28102.patch b/CVE-2024-28102.patch new file mode 100644 index 0000000..8c271b0 --- /dev/null +++ b/CVE-2024-28102.patch @@ -0,0 +1,75 @@ +From 90477a3b6e73da69740e00b8161f53fea19b831f Mon Sep 17 00:00:00 2001 +From: Simo Sorce +Date: Tue, 5 Mar 2024 16:57:17 -0500 +Subject: [PATCH] Address potential DoS with high compression ratio + +Fixes CVE-2024-28102 + +Signed-off-by: Simo Sorce +--- + jwcrypto/jwe.py | 7 +++++++ + jwcrypto/tests.py | 26 ++++++++++++++++++++++++++ + 2 files changed, 33 insertions(+) + +diff --git a/jwcrypto/jwe.py b/jwcrypto/jwe.py +index 9412881..5df500b 100644 +--- a/jwcrypto/jwe.py ++++ b/jwcrypto/jwe.py +@@ -10,6 +10,9 @@ + from jwcrypto.jwa import JWA + from jwcrypto.jwk import JWKSet + ++# Limit the amount of data we are willing to decompress by default. ++default_max_compressed_size = 256 * 1024 ++ + + # RFC 7516 - 4.1 + # name: (description, supported?) +@@ -422,6 +425,10 @@ def _decrypt(self, key, ppe): + + compress = jh.get('zip', None) + if compress == 'DEF': ++ if len(data) > default_max_compressed_size: ++ raise InvalidJWEData( ++ 'Compressed data exceeds maximum allowed' ++ 'size' + f' ({default_max_compressed_size})') + self.plaintext = zlib.decompress(data, -zlib.MAX_WBITS) + elif compress is None: + self.plaintext = data +diff --git a/jwcrypto/tests.py b/jwcrypto/tests.py +index bb2ff10..59049f8 100644 +--- a/jwcrypto/tests.py ++++ b/jwcrypto/tests.py +@@ -2111,6 +2111,32 @@ def test_pbes2_hs256_aeskw_custom_params(self): + jwa.default_max_pbkdf2_iterations += 2 + p2cenc.add_recipient(key) + ++ def test_jwe_decompression_max(self): ++ key = jwk.JWK(kty='oct', k=base64url_encode(b'A' * (128 // 8))) ++ payload = '{"u": "' + "u" * 400000000 + '", "uu":"' \ ++ + "u" * 400000000 + '"}' ++ protected_header = { ++ "alg": "A128KW", ++ "enc": "A128GCM", ++ "typ": "JWE", ++ "zip": "DEF", ++ } ++ enc = jwe.JWE(payload.encode('utf-8'), ++ recipient=key, ++ protected=protected_header).serialize(compact=True) ++ with self.assertRaises(jwe.InvalidJWEData): ++ check = jwe.JWE() ++ check.deserialize(enc) ++ check.decrypt(key) ++ ++ defmax = jwe.default_max_compressed_size ++ jwe.default_max_compressed_size = 1000000000 ++ # ensure we can eraise the limit and decrypt ++ check = jwe.JWE() ++ check.deserialize(enc) ++ check.decrypt(key) ++ jwe.default_max_compressed_size = defmax ++ + + class JWATests(unittest.TestCase): + def test_jwa_create(self): diff --git a/python-jwcrypto.spec b/python-jwcrypto.spec index 988903c..f0d17fa 100644 --- a/python-jwcrypto.spec +++ b/python-jwcrypto.spec @@ -1,13 +1,15 @@ %global _empty_manifest_terminate_build 0 Name: python-jwcrypto Version: 1.5.0 -Release: 2 +Release: 3 Summary: Implementation of JOSE Web standards License: LGPL-3.0-or-later URL: https://github.com/latchset/jwcrypto Source0: https://files.pythonhosted.org/packages/ed/72/b9289ee27d228fc7cae5c83d1c640de2a7cc0621805aa839ba239d6ef8fc/jwcrypto-1.5.0.tar.gz # https://github.com/latchset/jwcrypto/commit/d2655d370586cb830e49acfb450f87598da60be8 Patch0: CVE-2023-6681.patch +# https://github.com/latchset/jwcrypto/commit/90477a3b6e73da69740e00b8161f53fea19b831f +Patch1: CVE-2024-28102.patch BuildArch: noarch @@ -69,6 +71,9 @@ mv %{buildroot}/doclist.lst . %{_docdir}/* %changelog +* Fri Mar 08 2024 yaoxin - 1.5.0-3 +- Fix CVE-2024-28102 + * Fri Dec 29 2023 yaoxin - 1.5.0-2 - Fix CVE-2023-6681 -- Gitee