You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(bind): match request media type case-insensitively in BindBody - #3213
BindBody compares the request media type against the lowercase MIME constants as-is, so a client that sends a supported type in a different case gets a 415. Media type and subtype names are case-insensitive (RFC 9110 section 8.3.1).
e.POST("/", func(c*echo.Context) error {
varvstruct{ IDint`json:"id"` }
returnc.Bind(&v)
})
// POST / with Content-Type: Application/JSON and body {"id": 1}// got: 415 Unsupported Media Type, expected: bound with ID=1
The same happens for Application/XML, Text/XML, Application/X-WWW-Form-Urlencoded and Multipart/Form-Data.
The fix lowercases the media type before the switch. Parameters are left untouched, and the form and multipart branches already go through net/http, which parses the type with mime.ParseMediaType. #3095 had the same change and was labelled bug/v5 before its author closed it.
TestDefaultBinder_BindBody_MediaTypeIsCaseInsensitive covers all five types. On master every case fails with code=415, message=Unsupported Media Type. With the fix, go test -race ./..., go vet, staticcheck and golint all pass.
Summary by CodeRabbit
Bug Fixes
Body binding now recognizes content types regardless of capitalization, including JSON, XML, and form submissions.
No actionable comments were generated in the recent review.
Walkthrough
Changes: Body media type handling
Layer / File(s)
Summary
Media type normalization and coverage bind.go, bind_test.go
bindBodyMediaType lowercases the trimmed base media type. Tests check mixed-case content types across JSON, XML, URL-encoded form, and multipart form.
Suggested reviewers:vishr
Change: Bug fix
Merge Risk: Minimal · up to b5652
BindBody now accepts request media types regardless of letter case, as RFC 9110 specifies, and the new tests cover the supported body formats. No concrete risk was found, so this is ready to merge.
Security architecture risk: Minimal · up to b5652
Requests using mixed-case media types now reach the same decoders as their lowercase equivalents. The change does not add a format or an endpoint, and the review found no material weakening of access controls or request isolation.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
inferred — The changed acceptance behavior applies wherever a handler invokes BindBody directly or uses the default binder. The same parser families and caller-supplied destinations were already reachable with lowercase labels.
Trust Boundaries and Controls
observed — The client-supplied Content-Type selects a decoder. The changed code normalizes that selection value; it does not change request identity or the authorization checks a caller applies around binding.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: e231783a-5f75-4913-a130-9e49c5110c63
Commits
Reviewing files that changed from the base of the PR and between 59aacdd and b56520d.
Files selected for processing: 2
bind.go
bind_test.go
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
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
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.
BindBodycompares the request media type against the lowercase MIME constants as-is, so a client that sends a supported type in a different case gets a 415. Media type and subtype names are case-insensitive (RFC 9110 section 8.3.1).The same happens for
Application/XML,Text/XML,Application/X-WWW-Form-UrlencodedandMultipart/Form-Data.The fix lowercases the media type before the switch. Parameters are left untouched, and the form and multipart branches already go through
net/http, which parses the type withmime.ParseMediaType. #3095 had the same change and was labelled bug/v5 before its author closed it.TestDefaultBinder_BindBody_MediaTypeIsCaseInsensitivecovers all five types. On master every case fails withcode=415, message=Unsupported Media Type. With the fix,go test -race ./...,go vet,staticcheckandgolintall pass.Summary by CodeRabbit