infra icon indicating copy to clipboard operation
infra copied to clipboard

Forgiving base64

Open annevk opened this issue 2 years ago • 8 comments

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 avatar Apr 21 '23 09:04 annevk

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: https://github.com/tc39/proposal-arraybuffer-base64/issues/5.

annevk avatar Apr 21 '23 10:04 annevk

cc @mozfreddyb @martinthomson

annevk avatar Apr 21 '23 13:04 annevk

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.

martinthomson avatar Apr 24 '23 05:04 martinthomson

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.

annevk avatar Apr 24 '23 06:04 annevk

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

martinthomson avatar Apr 24 '23 06:04 martinthomson

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

annevk avatar Apr 27 '23 15:04 annevk

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.

martinthomson avatar Apr 27 '23 22:04 martinthomson

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.

lemire avatar Apr 15 '24 22:04 lemire