fix(ui-react): encode list filters as UTF-8 base64#6388
Merged
Conversation
`btoa(JSON.stringify(...))` rejects characters above U+00FF, so any filter value containing non-Latin-1 text (tag names, hostnames, usernames, emails) throws `InvalidCharacterError` and the request never goes out. Route filter encoding through a shared `toBase64Json` helper that serializes via `Buffer.from(..., "utf-8")`. ASCII payloads encode to the same bytes as before, so the backend decode path (`base64.StdEncoding.DecodeString` then `json.Unmarshal`) needs no change.
|
Claude finished @luizhf42's task in 15s —— View job Code Review CompleteReviewed 10 files across code quality, security, testing, language patterns, and architecture — no issues found. The code looks good as-is. Highlights:
If you push additional changes and want a new review, tag |
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.
What
The filter encoder used on every list page (
btoa(JSON.stringify(...))) throwsInvalidCharacterErrorfor any value containing characters above U+00FF, blocking searches and tag filters that include non-Latin-1 text. Replaced the inline encoder with a shared helper that goes through UTF-8 bytes first.Why
Reproduced while stress-testing the Enterprise RC: filtering devices by a tag named
日本語タグ, or searching for a hostname containing Japanese characters, never sends the request — the browser throws at encode time and the UI looks broken even though the backend is fine. Affects every list page that builds a filter URL: namespace devices, admin devices, admin users, admin namespaces, public keys, containers, web endpoints, invitations.Changes
utils/encoding.ts: newtoBase64Json(value: unknown): stringhelper usingBuffer.from(JSON.stringify(value), "utf-8").toString("base64").Bufferis already polyfilled in the bundle viavite-plugin-node-polyfillsand used elsewhere for byte-level work (ssh-keys.ts,TerminalInstance.tsx), so no new dependency surface.btoa(JSON.stringify(x))fortoBase64Json(x). ASCII payloads serialize to the exact same bytes the old code produced, so the backend decoder (base64.StdEncoding.DecodeStringthenjson.Unmarshalatpkg/api/query/filter.go:39) is unchanged.btoaoutput to lock in backward compatibility; Unicode round-trip guards the bug from regressing.Testing
Reproducer needs non-Latin-1 data in the DB — any tag/device/namespace/user with characters above U+00FF.
InvalidCharacterError: Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range, and the request never leaves the browser.filterquery param decodes (viaatobthenJSON.parse) to the expected clauses.toBase64Json(x) === btoa(JSON.stringify(x))for ASCII input, locked by the unit test.Pages to exercise: namespace devices, admin devices, admin users, admin namespaces, public keys, containers, web endpoints, invitations.