base64: Support multi bytes encoding characters - #1122
Merged
Conversation
btoa()/atob() treat each character as a single Latin-1 byte, which silently corrupts non-ASCII characters in SASL credentials. For example, "ø" (U+00F8) gets encoded as byte 0xF8 instead of the correct UTF-8 sequence 0xC3 0xB8, causing XMPP authentication failures for users with non-ASCII usernames (Nordic æøå, German umlauts, Cyrillic, CJK, etc.). Use TextEncoder/TextDecoder to properly handle UTF-8 encoding and decoding before passing to btoa()/atob(). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Member
|
The new tests are passing, CI failures are unrelated and will be addressed separately. |
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.
Summary
encode()/decode()in@xmpp/base64usebtoa()/atob(), which only handle Latin-1 (single-byte) encodingø(U+00F8) get encoded as a single byte (0xF8) instead of the correct UTF-8 sequence (0xC3 0xB8)The fix replaces
btoa()/atob()withTextEncoder/TextDecoderto properly handle UTF-8, and adds a test suite covering Nordic (æøå), German (äöüß), French (éèêëç), Cyrillic, CJK, Arabic, Hebrew, and emoji characters.Reproduction
Any username containing characters outside ASCII will produce corrupted SASL PLAIN payloads. For example, with username
øyvindranda:When a server decodes the
+A==payload, byte0xF8is not valid UTF-8, so the username gets mangled (e.g. replaced with U+FFFD), and JID construction or session binding fails silently.Test plan
packages/base64/test/test.jspassøyvindrandaauthenticates successfully after fix🤖 Generated with Claude Code