jwt: reshape base64-corruption hint as diagnosis-first - #2095
Merged
Merged
Conversation
The previous wording — "base64 decode failed; if the issuer emits
padded/standard base64, set jwt.WithStrictBase64Encoding(false)" —
read as a fix-it instruction and tilted users toward weakening the
strict decoder reflexively. A `base64.CorruptInputError` cannot
distinguish "your producer is non-conforming" from "the input is
malformed or tampered with"; the user has to make that call
deliberately.
Reshape the error to lead with the diagnosis ("base64url decode
failed under strict RFC 7515 rule"), present the remedy as a
conditional ("if the issuer is known to emit padded or standard-
base64 alphabet, retry with WithStrictBase64Encoding(false)"), and
explicitly mention the default action ("otherwise treat the input
as malformed"). Same change at both hint sites (jwt/jwt.go in the
fast path verify branch and jwt/parse_fast.go in parseCompactFast).
Existing tests that match on the option name still pass; a new
test asserts the diagnosis-first shape.
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.
The previous wording — "base64 decode failed; if the issuer emits padded/standard base64, set jwt.WithStrictBase64Encoding(false)" — read as a fix-it instruction and tilted users toward weakening the strict decoder reflexively. A
base64.CorruptInputErrorcannot distinguish "your producer is non-conforming" from "the input is malformed or tampered with"; the user has to make that call deliberately.Reshape the error to lead with the diagnosis ("base64url decode failed under strict RFC 7515 rule"), present the remedy as a conditional ("if the issuer is known to emit padded or standard-base64 alphabet, retry with
jwt.WithStrictBase64Encoding(false)"), and explicitly mention the default action ("otherwise treat the input as malformed"). Same change at both hint sites:jwt/jwt.go(fast-path verify branch) andjwt/parse_fast.go(parseCompactFast).Existing tests that match on the option name continue to pass. A new test in
jwt/jwt_test.go:TestStrictBase64Encoding/error_message_is_diagnosis-firstasserts the new wording carries (a) the RFC 7515 anchor, (b) the conditional "if the issuer is known", (c) the "otherwise treat the input as malformed" branch.