Open
Conversation
|
If an implementation could pass the proposed tests, then that would certainly fix the issue that was filed in OpenStack. I'm curious to see an example of the implementation changes required to match this proposal, though. |
Author
|
Here is an implementation: https://github.com/reaperhulk/cryptography/tree/strictb64 (reaperhulk/cryptography@62f45f5 is the commit) I'm not happy with it (regex scanning the token is an awful solution), but I'm unsure of a better way (at least until I can convince python to add a strict flag to b64decode). |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fernet tokens use URL safe base64 encoding. Platforms like Python (and Ruby, etc) have chosen to implement decoding of this in a very liberal way. Specifically, characters outside the base64 alphabet are silently dropped and parsing is terminated when valid padding is detected. This is at odds with the recommendations in RFC 4648 (section 3.3), but is not explicitly disallowed. In practice this means it is possible to take a valid Fernet token and craft one that appears different (e.g. with invalid characters or garbage after the padding char(s)) that will still validate. This is a problem as clients may not realize that, counterintuitively, the token is semi-mutable prior to decoding without affecting the HMAC.
The proposed fix is to add new invalid test vectors that exercise these behaviors and require conformant implementations to do more rigorous checking on the base64 prior to decoding. In Python this might look like: