fix(base64): use standard RFC 4648 alphabet on the text path (#87)#283
Merged
Merged
Conversation
…api#87) strfmt.Base64 maps to OpenAPI `format: byte`, which OAI v2 defines as unqualified "base64 encoded characters". Per RFC 4648, unqualified "base64" is the standard alphabet (section 4, `+/`); base64url (section 5, `-_`) is a separately named encoding the RFC says must not be called "base64". Eight of the nine Base64 serialization paths already used StdEncoding (String, MarshalJSON/UnmarshalJSON, Scan/Value, MarshalBSON/UnmarshalBSON). The lone outlier was the encoding.TextMarshaler/TextUnmarshaler pair, which used URLEncoding since PR go-openapi#57. The result: the same Base64 value serialized to a query parameter (text) versus a JSON body encoded differently whenever the payload hit alphabet index 62/63, breaking opaque tokens that cross boundaries. Route every path through a single seam, `base64Encoding = base64.StdEncoding`, so the whole type now uses standard base64 and there is exactly one place to introduce a URL-safe variant later (see the type-parameterization work). The misleading "URLEncoding alphabet" godoc is corrected. Behavioral change (patch-level spec-conformance fix): the text path now emits and accepts standard base64. base64url text that previously round-tripped via UnmarshalText will now be rejected. In practice this was rarely hit because consumers marshal via JSON even for parameters. * fixes go-openapi#87 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #283 +/- ##
=======================================
Coverage 87.81% 87.81%
=======================================
Files 18 18
Lines 2471 2471
=======================================
Hits 2170 2170
Misses 208 208
Partials 93 93 ☔ View full report in Codecov by Harness. |
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.
strfmt.Base64 maps to OpenAPI
format: byte, which OAI v2 defines as unqualified "base64 encoded characters".Per RFC 4648, unqualified "base64" is the standard alphabet (section 4,
+/); base64url (section 5,-_) is a separately named encoding the RFC says must not be called "base64".Eight of the nine Base64 serialization paths already used StdEncoding (String, MarshalJSON/UnmarshalJSON, Scan/Value, MarshalBSON/UnmarshalBSON).
The lone outlier was the encoding.TextMarshaler/TextUnmarshaler pair, which used URLEncoding since PR #57.
The result: the same Base64 value serialized to a query parameter (text) versus a JSON body encoded differently whenever the payload hit alphabet index 62/63, breaking opaque tokens that cross boundaries.
Route every path through a single seam,
base64Encoding = base64.StdEncoding, so the whole type now uses standard base64 and there is exactly one place to introduce a URL-safe variant later (see the type-parameterization work). The misleading "URLEncoding alphabet" godoc is corrected.Behavioral change (patch-level spec-conformance fix): the text path now emits and accepts standard base64. base64url text that previously round-tripped via UnmarshalText will now be rejected. In practice this was rarely hit because consumers marshal via JSON even for parameters.
Change type
Please select: 🆕 New feature or enhancement|🔧 Bug fix'|📃 Documentation update
Short description
Fixes
Full description
Checklist