fix(adapters): make base64url.decode reject invalid input everywhere#56
Open
Tleaoo wants to merge 5 commits into
Open
fix(adapters): make base64url.decode reject invalid input everywhere#56Tleaoo wants to merge 5 commits into
Tleaoo wants to merge 5 commits into
Conversation
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.
Align
base64url.decodefailure semantics across all six adaptersWhere we are today
operations.jsondeclares exactly one legal error type forbase64url.decode—
encoding_error— yet the six adapters disagree three ways about whatinvalid input even is:
Axis 1: characters outside the URL-safe alphabet (
"not-valid!!!")Buffer.from(value, 'base64url')silently ignores foreign charactersre.substrips foreign characters, then decodes what's leftparse_error(undeclared for this op)encoding_error✓Axis 2: valid base64url, bytes not valid UTF-8 (
"_w"→0xFF)parse_errorforce_encoding("UTF-8")produces an invalid string that blows up later inJSON.generateasunknown_errorencoding_error✓So the same wire input can produce a success, a
parse_error, anunknown_error, or anencoding_errordepending on which SDK you ask. Thereference adapter is among the most wrong (it manufactures data from garbage
input). Nothing catches this because the vector file only round-trips valid
data.
What this PR changes
Target semantics — the strict behavior rust and java already implement, and
the only one compatible with the declared
errorTypes:reject foreign characters, reject undecodable bytes, always as
encoding_error.TextDecoder(..., { fatal: true }).route
base64url-*failures toencoding_errorinstead of lumping decodein with
parse_error. (The helper's only caller is the decode command, sonothing else shifts.)
base64url-decodeout of theparse_errorbucket inerror_type_for_command; add avalid_encoding?guard so invalid UTF-8fails as
encoding_errorat the operation instead of corrupting theresponse serialization.
utf8.Validcheck after decoding (alphabet rejection wasalready correct).
Two new error-case vectors,
invalid_characters_rejectedandinvalid_utf8_rejected, pin both axes for every adapter from now on.Verification
scenarios (base64url vector: 64/64 across both adapters).
changed logic was exercised standalone (
Base64.urlsafe_decode64+valid_encoding?+ the new mapping): invalid chars →encoding_error,0xFF→encoding_error, round-trip unchanged. The gem is not involved ineither changed path.
has); change is 6 lines against stdlib (
unicode/utf8),gofmt -eclean.CI compiles it.
handle_base64url_decodeandbase64urlDecodeToStringthat they already implement the target semantics,so the new vectors pass them as-is.