Skip to content

Answer 413 for multipart and server body limits under Draft20260903 - #10452

Merged
glen-84 merged 9 commits into
mainfrom
gai/multipart-body-size-limits
Sep 30, 2026
Merged

glen-84 merged 9 commits into
mainfrom
gai/multipart-body-size-limits

Conversation

@glen-84

@glen-84 glen-84 commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Every request body size limit of the HTTP transport now reports a code that names the limit and answers 413 under the Draft20260903 transport version. Under Draft20250508 it answers 400, and under Legacy an application/json response stays 200. HC0010 stays the maxAllowedRequestSize code and now also covers a multipart operations field. The new HC0135 covers a multipart section over FormOptions.MultipartBodyLengthLimit, and the new HC0136 a body over the web server's limit or over FormOptions.BufferBodyLengthLimit.
  • The multipart middleware reads the form with an internal reader that follows FormFeature's multipart branch (identical from .NET 8 to .NET 11), so each limit throws its own error while the structure refusals and their messages stay as they were. The reader refuses any request whose IAntiforgeryValidationFeature reports IsValid as false. FormFeature also requires an internal marker, but the antiforgery and CSRF protection middlewares set that marker whenever they record a verdict, so with them the answer is unchanged. docs/updating-dotnet.md lists what to recheck when the target frameworks or the SDK change, AGENTS.md points to it, and CI now spellchecks and lints docs/.
  • Wire changes under every version, described in both 16.6 to 16.7 migration guides: an operations field over maxAllowedRequestSize is refused (MultipartBodyLengthLimit still applies to it, and the smaller of the two decides the code); an oversized section carries HC0135 in place of HC0033; the web server's limit carries HC0136 in place of HC0012 or HC0033; and a body over BufferBodyLengthLimit carries HC0136 in place of HC0033.

Test plan

  • GraphQLOverHttpSpecTests pins each limit under Draft20250508 and Draft20260903, and under Legacy for operations: the web server's limit for POST, QUERY, and multipart, the operations field, a file and map over the section limit, and BufferBodyLengthLimit. A form over the section-count limit still gets a 400 status code under both versions.
  • MultipartFormReaderTests checks parity with FormFeature for the structure refusals and their messages, each limit at and past its boundary, both orderings of the two operations limits, the header limits, buffered and seekable bodies, and the antiforgery check. Removing any limit fails exactly its test.
  • HotChocolate.AspNetCore.Tests passes on net8.0 to net11.0, as do HotChocolate.Fusion.AspNetCore.Tests on net10.0 and both Azure Functions test projects.

Copilot AI balanced review requested due to automatic review settings September 30, 2026 08:50
@github-actions github-actions Bot added 📚 documentation This issue is about working on our documentation. 🧰 maintenance 🌶️ hot chocolate labels Sep 30, 2026

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.

Copilot review overview

🟡 Changes recommended

The new multipart reader changes antiforgery rejection behavior despite the stated compatibility guarantee.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds size-specific GraphQL errors and Draft20260903 HTTP 413 responses for multipart and server-enforced body limits.

Changes:

  • Introduces HC0135/HC0136 and a limit-aware multipart reader.
  • Expands transport coverage across POST, QUERY, multipart, buffering, and antiforgery scenarios.
  • Updates migration documentation and documentation CI.
File Description
website/​content/​docs/​hotchocolate/​server/​http-transport.md Documents 413 size refusals.
website/​content/​docs/​hotchocolate/​server/​files.md Documents multipart limits and error codes.
website/​content/​docs/​hotchocolate/​server/​endpoints.md Extends request-size documentation to multipart operations.
website/​content/​docs/​hotchocolate/​migrating/​migrate-from-16-6-to-16-7.md Adds server migration guidance.
website/​content/​docs/​fusion/​request-limits.md Documents Fusion multipart limits.
website/​content/​docs/​fusion/​migration/​migrate-from-16-6-to-16-7.md Adds Fusion migration guidance.
src/​HotChocolate/​Primitives/​src/​Primitives/​ErrorCodes.cs Defines the new error codes.
src/​HotChocolate/​Fusion/​src/​Fusion.AspNetCore/​DependencyInjection/​FusionServerServiceCollectionExtensions.cs Registers Fusion request limits.
src/​HotChocolate/​AspNetCore/​test/​AspNetCore.Tests/​Parsers/​MultipartFormReaderTests.cs Tests multipart parsing and limits.
src/​HotChocolate/​AspNetCore/​test/​AspNetCore.Tests/​Parsers/​LengthLimitedReadStreamTests.cs Tests stream boundaries.
src/​HotChocolate/​AspNetCore/​test/​AspNetCore.Tests/​HttpMultipartMiddlewareTests.cs Tests antiforgery handling.
src/​HotChocolate/​AspNetCore/​test/​AspNetCore.Tests/​GraphQLOverHttpSpecTests.cs Tests version-specific statuses and errors.
src/​HotChocolate/​AspNetCore/​test/​AspNetCore.Tests/​__snapshots__/​HttpMultipartMiddlewareTests.Upload_Too_Large_File_Test.snap Updates oversized-file output.
src/​HotChocolate/​AspNetCore/​src/​AspNetCore/​Extensions/​HotChocolateAspNetCoreServiceCollectionExtensions.cs Registers server request limits.
src/​HotChocolate/​AspNetCore/​src/​AspNetCore.Pipeline/​Utilities/​ThrowHelper.cs Centralizes new exceptions.
src/​HotChocolate/​AspNetCore/​src/​AspNetCore.Pipeline/​Utilities/​MiddlewareHelper.cs Marks all size errors as oversized requests.
src/​HotChocolate/​AspNetCore/​src/​AspNetCore.Pipeline/​Utilities/​HttpResultContextData.cs Generalizes request-size metadata.
src/​HotChocolate/​AspNetCore/​src/​AspNetCore.Pipeline/​Properties/​AspNetCorePipelineResources.resx Adds error messages.
src/​HotChocolate/​AspNetCore/​src/​AspNetCore.Pipeline/​Properties/​AspNetCorePipelineResources.Designer.cs Adds generated resource accessors.
src/​HotChocolate/​AspNetCore/​src/​AspNetCore.Pipeline/​Parsers/​MultipartFormReader.cs Implements limit-aware multipart parsing.
src/​HotChocolate/​AspNetCore/​src/​AspNetCore.Pipeline/​Parsers/​LengthLimitedReadStream.cs Implements bounded reads.
src/​HotChocolate/​AspNetCore/​src/​AspNetCore.Pipeline/​Parsers/​HttpRequestLimits.cs Holds normalized HTTP limits.
src/​HotChocolate/​AspNetCore/​src/​AspNetCore.Pipeline/​Parsers/​DefaultHttpRequestParser.cs Converts server 413 failures.
src/​HotChocolate/​AspNetCore/​src/​AspNetCore.Pipeline/​HttpMultipartMiddleware.cs Uses the new multipart reader.
src/​HotChocolate/​AspNetCore/​src/​AspNetCore.Pipeline/​ExecutorSession.cs Exposes the configured request limit.
docs/​updating-dotnet.md Documents upstream synchronization checks.
dictionary.txt Adds documentation vocabulary.
AGENTS.md Links the .NET update procedure.
.github/​workflows/​ci.yml Lints and spellchecks docs/.
Files not reviewed (1)
  • src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/Properties/AspNetCorePipelineResources.Designer.cs: Generated file

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

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Patch coverage

94.6% of changed lines covered (209/221)

File Covered Changed Patch %
…/src/AspNetCore.Pipeline/Parsers/LengthLimitedReadStream.cs 24 33 72.7% 🔴
…/AspNetCore/src/AspNetCore.Pipeline/Utilities/ThrowHelper.cs 16 17 94.1% 🟡
…/src/AspNetCore.Pipeline/Parsers/MultipartFormReader.cs 140 142 98.6% 🟡
…/AspNetCore/src/AspNetCore.Pipeline/ExecutorSession.cs 2 2 100.0% 🟢
…/src/AspNetCore.Pipeline/HttpMultipartMiddleware.cs 12 12 100.0% 🟢
…/src/AspNetCore.Pipeline/Parsers/DefaultHttpRequestParser.cs 6 6 100.0% 🟢
…/src/AspNetCore.Pipeline/Parsers/HttpRequestLimits.cs 3 3 100.0% 🟢
…/src/AspNetCore.Pipeline/Utilities/MiddlewareHelper.cs 4 4 100.0% 🟢
…/HotChocolateAspNetCoreServiceCollectionExtensions.cs 1 1 100.0% 🟢
…/FusionServerServiceCollectionExtensions.cs 1 1 100.0% 🟢
Uncovered changed lines (JSON)
{
  "sha": "40807fc63f5f039409b4c1e619a7f74b751615da",
  "files": [
    { "path": "src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/Parsers/LengthLimitedReadStream.cs", "ranges": [[20, 20], [22, 22], [26, 27], [31, 32], [62, 62], [64, 64], [67, 67]] },
    { "path": "src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/Utilities/ThrowHelper.cs", "ranges": [[159, 159]] },
    { "path": "src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/Parsers/MultipartFormReader.cs", "ranges": [[163, 164]] }
  ]
}

Project coverage: 57.8% (299366/518134 lines)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📚 documentation This issue is about working on our documentation. 🌶️ hot chocolate 🧰 maintenance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants