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
"sodium.from_base64" accepts invalid encodings #89
Comments
The whole base64 code is a complete horror. Which is why it was never documented. I'll try to rewrite that soon. |
Would it make sense to use https://github.com/beatgammit/base64-js? No clue how it compares it terms of strictness/correctness, but I briefly played around with it earlier today after seeing it recommended by MDN and was surprised to see that it was about an order of magnitude faster with my test input (which was only a few ms difference and may not hold true for all inputs). |
Nope, it wouldn't make sense. If a Base64 codec is added, it has to be constant-time for a given data length, at least to be consistent with the hex codec. |
Ahh, got it, that makes sense. |
@jedisct1: Wishing you a happy new year! 🎉 Did you have any chance to look into the Base64 rewrite or has it been already done? |
It's been done a long time ago :) It just uses the native libsodium functions. |
Greeeeat! So we will update our libsodium.js version. 😃 |
The
sodium.from_base64
decoder tolerates invalid Base64 encodings. Here is an example with an invalid input which has characters applied after the suffix code:It is generally safer to reject non-Base64 characters than tolerating them.
As section 3.3 of RFC 4648 explains:
The text was updated successfully, but these errors were encountered: