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

Relax payload from_utf8 behind flag #98

Closed
loehde opened this issue Jul 26, 2023 · 3 comments
Closed

Relax payload from_utf8 behind flag #98

loehde opened this issue Jul 26, 2023 · 3 comments

Comments

@loehde
Copy link

loehde commented Jul 26, 2023

A minor suggestion

It would be nice if the payload could be relaxed to a non-valid utf-8 encoding, currently it restricts binary encodings. I know binary encoding, is not compliant with the PASETO RFC. As a suggestion, it could be hidden behind a feature flag to allow binary encodings and since the function signature for payload is &[u8], and a valid footer does not need a valid utf-8 encoding.

https://github.com/brycx/pasetors/blob/807d3ad3660158bac25be0f66768d84ee259323d/src/token.rs#L119C21-L119C21

@brycx
Copy link
Owner

brycx commented Jul 27, 2023

Hej Kasper,

Thanks for the suggestion! As you also mention, non-valid UTF-8 data is prohibited by the spec. As the spec also suggests, if non-UTF-8 data is needed, this ought to be encoded using the base64-url encoding, which is also used throughout the rest of PASETO.

Is there anything preventing you from doing this? Encoding your binary data beforehand and then decoding it after having processed the token?

@loehde
Copy link
Author

loehde commented Jul 30, 2023

Hej Johannes,

Thank you for your fast response. There is nothing preventing me from using base64 encoding, except it introduces serialization/deserialization overhead and introduces space overhead, which is typical not an issue. But it would be nice to serialize it directly instead of introducing steps, since the function signature takes an &[u8] maybe it should be changed to a &str if it should stay complaint with PASETO? Since it introduces confusion?

It is delightful to hear your thoughts, and thank you for the awesome library, huge thumbs up!

//Kasper

@brycx
Copy link
Owner

brycx commented Aug 1, 2023

"[..] takes an &[u8] maybe it should be changed to a &str if it should stay complaint with PASETO? Since it introduces confusion?"

Yes, this sounds like a good idea. I see how it is confusing, I don't want people necessarily forced to read the spec before using the library. Should be noted that this API confusion is only present in the lower-level versionN:: modules, since AFAIR the high-level interfaces for v4 should already enforce this UTF-8 input through the Claims type.

Doing this change would be SemVer breaking.

Thank you for the kind words! Glad you like it.

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