Skip to content

fix: respect MaxBodyBytes limit for raw bodies - #1095

Open
leonklingele wants to merge 2 commits into
danielgtaylor:mainfrom
leonklingele:fix/raw-body-max-bodybytes
Open

fix: respect MaxBodyBytes limit for raw bodies#1095
leonklingele wants to merge 2 commits into
danielgtaylor:mainfrom
leonklingele:fix/raw-body-max-bodybytes

Conversation

@leonklingele

Copy link
Copy Markdown
Contributor

Previously, Huma only enforced the request body limit for regular, non-raw bodies.
This is a bug. Make Huma check the limit for raw bodies, too.

See also #1094 for a similar fix.

Previously, Huma only enforced the request body limit for regular, non-raw bodies.
This is a bug. Make Huma check the limit for raw bodies, too.

See also danielgtaylor#1094 for a similar fix.
Copilot AI lite review requested due to automatic review settings August 8, 2026 13:35
@codecov

codecov Bot commented Aug 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.20%. Comparing base (198225e) to head (5b27238).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1095   +/-   ##
=======================================
  Coverage   93.20%   93.20%           
=======================================
  Files          23       23           
  Lines        4988     4990    +2     
=======================================
+ Hits         4649     4651    +2     
  Misses        272      272           
  Partials       67       67           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a bug where Operation.MaxBodyBytes (and the default request limit behavior) was not applied when an operation used RawBody, bringing raw-body request handling in line with regular body handling.

Changes:

  • Apply ensureBodyReadTimeout and ensureMaxBodyBytes during RawBody input type processing.
  • Add a regression test ensuring the default body size limit rejects oversized raw-body requests.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
huma.go Ensures default body read timeout and max body bytes are applied for RawBody inputs.
huma_test.go Adds a test verifying oversized raw bodies are rejected when MaxBodyBytes is omitted.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread huma.go
Comment on lines 1469 to +1472
initRequestBody(op, setRequestBodyRequired)
rbt = setRequestBodyFromRawBody(op, registry, f)
ensureBodyReadTimeout(op)
ensureMaxBodyBytes(op)
Comment thread huma_test.go
Comment on lines +4505 to +4516
func TestRawBodyHasDefaultSizeLimit(t *testing.T) {
mux, api := humatest.New(t, huma.DefaultConfig("Test API", "1.0.0"))

var handlerCalled bool
var receivedLen int

huma.Register(api, huma.Operation{
Method: http.MethodPost,
Path: "/raw",
// MaxBodyBytes intentionally omitted
// Default is 1 MB set by "ensureMaxBodyBytes"
}, func(ctx context.Context, input *struct {
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.

2 participants