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

Forgiving base64 #566

Open
annevk opened this issue Apr 21, 2023 · 8 comments
Open

Forgiving base64 #566

annevk opened this issue Apr 21, 2023 · 8 comments

Comments

@annevk
Copy link
Member

annevk commented Apr 21, 2023

Is forgiving base64 essentially

  1. Remove ASCII whitespace.
  2. Ordinary base64 decode.

?

It's a lot clearer about erroneous inputs though so if we decide to change this we want to make sure we end up making the same requirements.

cc @zcorpan @bakkot

@annevk
Copy link
Member Author

annevk commented Apr 21, 2023

I guess https://www.rfc-editor.org/rfc/rfc4648#section-3.5 in particular is a thing that our algorithm addresses explicitly. We ignore some bits instead of checking they are 0. That's a thing I haven't seen a single browser-based base64/base64url implementation enforce. Number of = is enforced though.

So we might need to define something equivalent for base64url given CSP/SRI use that and might not rely on encoding alone.

Related: tc39/proposal-arraybuffer-base64#5.

@annevk
Copy link
Member Author

annevk commented Apr 21, 2023

cc @mozfreddyb @martinthomson

@martinthomson
Copy link
Contributor

Something to consider here is whether you might want to recommend that implementations avoid creating side-channels (esp. through timing) based on the content of the information being encoded. There are a number of cases where the information that is being passed should not be leaked to other processes, but might be if the encoding function were highly variable.

@annevk
Copy link
Member Author

annevk commented Apr 24, 2023

Maybe we should instead encourage folks to not use base64 for such cases? I doubt any browser has base64 code paths that take that into account and I'm not sure we should have those.

@martinthomson
Copy link
Contributor

Firefox considers it, at least in those few places we moved to a CT encoder, which at least includes base64url in Push.

@annevk
Copy link
Member Author

annevk commented Apr 27, 2023

@martinthomson could you point to the cases in the Push specification that warrant that? Thanks!

@martinthomson
Copy link
Contributor

Nothing concrete in the spec. But the values are secrets and I've learned that you don't write code that changes what it does based on the value of a secret.

@lemire
Copy link

lemire commented Apr 15, 2024

The simdutf library (used in Node.js for base64 decoding) implements forgiving base64. As far as we know, it is fully compliant. One issue that I have encountered is that there is no base64url equivalent that is explicit.

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

No branches or pull requests

3 participants