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

Fernet messages can still be decrypted when garbage is appended #1994

Closed
dolph opened this issue May 28, 2015 · 3 comments
Closed

Fernet messages can still be decrypted when garbage is appended #1994

dolph opened this issue May 28, 2015 · 3 comments

Comments

@dolph
Copy link

dolph commented May 28, 2015

To reproduce, start with the beginning of the example from the docs at https://cryptography.io/en/latest/fernet/

>>> from cryptography.fernet import Fernet
>>> key = Fernet.generate_key()
>>> f = Fernet(key)
>>> token = f.encrypt(b"my deep dark secret")

It appears that you can append the token with whatever you want, and still produce the original secret:

>>> f.decrypt(token + '-GARBAGE')
'my deep dark secret'

Even random UUIDs:

>>> import uuid
>>> f.decrypt(token + uuid.uuid4().bytes)
'my deep dark secret'
>>> f.decrypt(token + uuid.uuid4().bytes)
'my deep dark secret'
>>> f.decrypt(token + uuid.uuid4().bytes)
'my deep dark secret'

I'd expect cryptography.fernet.InvalidToken to be raised in all these cases.

This behavior was originally reported by Matt Fischer against openstack/keystone in:

https://bugs.launchpad.net/keystone/+bug/1459483

@reaperhulk
Copy link
Member

Thanks for the report @dolph. We're investigating the fix now.

@reaperhulk
Copy link
Member

fernet/spec#11

@reaperhulk
Copy link
Member

(This is stuck in fernet spec land. Closing in favor of tracking it over there)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants