From ea7fc3909b8d743296b5fa202874fc31028a2fb5 Mon Sep 17 00:00:00 2001 From: starlet-dx <15929766099@163.com> Date: Thu, 13 Feb 2025 16:39:02 +0800 Subject: [PATCH] Fix CVE-2024-28102 --- CVE-2024-28102.patch | 80 ++++++++++++++++++++++++++++++++++++++++++++ python-jwcrypto.spec | 7 +++- 2 files changed, 86 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..170fe92 --- /dev/null +++ b/CVE-2024-28102.patch @@ -0,0 +1,80 @@ +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 + +Origin: https://github.com/latchset/jwcrypto/commit/90477a3b6e73da69740e00b8161f53fea19b831f +--- + jwcrypto/jwe.py | 7 +++++++ + jwcrypto/tests.py | 26 ++++++++++++++++++++++++++ + 2 files changed, 33 insertions(+) + +diff --git a/jwcrypto/jwe.py b/jwcrypto/jwe.py +index b86e27c..9b718cb 100644 +--- a/jwcrypto/jwe.py ++++ b/jwcrypto/jwe.py +@@ -8,6 +8,9 @@ from jwcrypto.common import base64url_decode, base64url_encode + from jwcrypto.common import json_decode, json_encode + from jwcrypto.jwa import JWA + ++# 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?) +@@ -373,6 +376,10 @@ class JWE(object): + + 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 7f5f9e9..16297f0 100644 +--- a/jwcrypto/tests.py ++++ b/jwcrypto/tests.py +@@ -1195,6 +1195,32 @@ class ConformanceTests(unittest.TestCase): + check.deserialize(enc, key) + self.assertEqual(b'plain', check.payload) + ++ 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): +-- +2.43.0 + diff --git a/python-jwcrypto.spec b/python-jwcrypto.spec index f7be831..65a5b1c 100644 --- a/python-jwcrypto.spec +++ b/python-jwcrypto.spec @@ -1,11 +1,13 @@ Name: python-jwcrypto Version: 0.5.0 -Release: 4 +Release: 5 Summary: Implements JWK, JWS, JWE specifications with python-cryptography License: LGPLv3+ URL: https://github.com/latchset/jwcrypto Source0: https://github.com/latchset/jwcrypto/releases/download/v%{version}/jwcrypto-%{version}.tar.gz +Patch0: CVE-2024-28102.patch + BuildArch: noarch BuildRequires: python%{python3_pkgversion}-devel python%{python3_pkgversion}-setuptools BuildRequires: python%{python3_pkgversion}-cryptography >= 1.5 python%{python3_pkgversion}-pytest @@ -41,5 +43,8 @@ Implements JWK, JWS, JWE specifications using python-cryptography %{python3_sitelib}/jwcrypto-%{version}-py%{python3_version}.egg-info %changelog +* Thu Feb 13 2025 yaoxin <1024769339@qq.com> - 0.5.0-5 +- Fix CVE-2024-28102 + * Fri Apr 17 2020 lizhenhua - 0.5.0-4 - Package init