Skip to content

jwt: reshape base64-corruption hint as diagnosis-first - #2095

Merged
lestrrat merged 1 commit into
develop/v4from
fix-v4-base64-corruption-error-wording
Apr 29, 2026
Merged

lestrrat merged 1 commit into
develop/v4from
fix-v4-base64-corruption-error-wording

Conversation

@lestrrat

Copy link
Copy Markdown
Collaborator

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 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) and jwt/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-first asserts 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.

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.
@lestrrat
lestrrat merged commit bbabdec into develop/v4 Apr 29, 2026
7 checks passed
@lestrrat
lestrrat deleted the fix-v4-base64-corruption-error-wording branch April 29, 2026 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant