Skip to content
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

Insecure handling of padding during JWE decryption #19

Closed
mtruscello opened this issue Jun 7, 2023 · 1 comment
Closed

Insecure handling of padding during JWE decryption #19

mtruscello opened this issue Jun 7, 2023 · 1 comment

Comments

@mtruscello
Copy link

The logic for padding removal from JWE encryption is incorrect. The current code merely strips unprintable characters regardless if they belong to the padding or not:

decoded_payload = ''.join(c for c in decrypted.decode() if c.isprintable())

For AES GCM this isn't an issue because the padding removal is handled automatically.
For modes that do care about padding (e.g. AES CBC) this is blindly removing characters under the assumption that A) they belong to the padding and B) that the padding is valid. This allows an attacker to spoof data much more easily because the padding is never validated and invalid JSON characters are being silently removed.

The pycryptodome library that this package uses contains padding utilities. I strongly recommend you use them.

@NehaSony
Copy link
Contributor

Hi @mtruscello
Thanks for reporting this. This should be available in the next versions onwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants