-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for CVE-2024-33664. JWE limited to 250K #352
Open
alistairwatts
wants to merge
1
commit into
mpdavis:master
Choose a base branch
from
alistairwatts:cve-2024-33664
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+53
−7
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,3 +96,5 @@ class Zips: | |
|
||
|
||
ZIPS = Zips() | ||
|
||
JWE_SIZE_LIMIT = 250 * 1024 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -6,7 +6,7 @@ | |||||
|
||||||
from . import jwk | ||||||
from .backends import get_random_bytes | ||||||
from .constants import ALGORITHMS, ZIPS | ||||||
from .constants import ALGORITHMS, ZIPS, JWE_SIZE_LIMIT | ||||||
from .exceptions import JWEError, JWEParseError | ||||||
from .utils import base64url_decode, base64url_encode, ensure_binary | ||||||
|
||||||
|
@@ -76,6 +76,13 @@ def decrypt(jwe_str, key): | |||||
>>> jwe.decrypt(jwe_string, 'asecret128bitkey') | ||||||
'Hello, World!' | ||||||
""" | ||||||
|
||||||
# Limit the token size - if the data is compressed then decompressing the | ||||||
# data could lead to large memory usage. This helps address This addresses | ||||||
# CVE-2024-33664. Also see _decompress() | ||||||
if len(jwe_str) > JWE_SIZE_LIMIT: | ||||||
raise JWEError("JWE string exceeds {JWE_SIZE_LIMIT} bytes") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
header, encoded_header, encrypted_key, iv, cipher_text, auth_tag = _jwe_compact_deserialize(jwe_str) | ||||||
|
||||||
# Verify that the implementation understands and can process all | ||||||
|
@@ -424,13 +431,13 @@ def _compress(zip, plaintext): | |||||
(bytes): Compressed plaintext | ||||||
""" | ||||||
if zip not in ZIPS.SUPPORTED: | ||||||
raise NotImplementedError("ZIP {} is not supported!") | ||||||
raise NotImplementedError(f"ZIP {zip} is not supported!") | ||||||
if zip is None: | ||||||
compressed = plaintext | ||||||
elif zip == ZIPS.DEF: | ||||||
compressed = zlib.compress(plaintext) | ||||||
else: | ||||||
raise NotImplementedError("ZIP {} is not implemented!") | ||||||
raise NotImplementedError(f"ZIP {zip} is not implemented!") | ||||||
return compressed | ||||||
|
||||||
|
||||||
|
@@ -446,13 +453,18 @@ def _decompress(zip, compressed): | |||||
(bytes): Compressed plaintext | ||||||
""" | ||||||
if zip not in ZIPS.SUPPORTED: | ||||||
raise NotImplementedError("ZIP {} is not supported!") | ||||||
raise NotImplementedError(f"ZIP {zip} is not supported!") | ||||||
if zip is None: | ||||||
decompressed = compressed | ||||||
elif zip == ZIPS.DEF: | ||||||
decompressed = zlib.decompress(compressed) | ||||||
# If, during decompression, there is more data than expected, the | ||||||
# decompression halts and raise an error. This addresses CVE-2024-33664 | ||||||
decompressor = zlib.decompressobj() | ||||||
decompressed = decompressor.decompress(compressed, max_length=JWE_SIZE_LIMIT) | ||||||
if decompressor.unconsumed_tail: | ||||||
raise JWEError(f"Decompressed JWE string exceeds {JWE_SIZE_LIMIT} bytes") | ||||||
else: | ||||||
raise NotImplementedError("ZIP {} is not implemented!") | ||||||
raise NotImplementedError(f"ZIP {zip} is not implemented!") | ||||||
return decompressed | ||||||
|
||||||
|
||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be an f-string.