Repository navigation
Add an option to refuse query operations over POST - #10755
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are identified, and the supplied evidence indicates the option is covered across affected transports, pipelines, response metadata, documentation, and tests.
No open issues 🎉
What changed in this PR
Adds GraphQLServerOptions.EnableQueriesOverPost, allowing applications to refuse GraphQL query operations over POST while continuing to support queries over GET or QUERY and mutations/subscriptions over POST.
Changes:
- Added and documented the
EnableQueriesOverPostserver option. - Applied query restrictions across standard, multipart, persisted-operation, GET, QUERY, and Fusion pipelines.
- Added refusal response handling for status codes,
Allow, andAccept-Queryheaders. - Added comprehensive middleware, transport, persisted-operation, multipart, Fusion, and batching tests.
| File | Description |
|---|---|
website/content/docs/hotchocolate/server/options.md |
Documents the new option in the server options table. |
website/content/docs/hotchocolate/server/http-transport.md |
Documents refusing queries over POST and the relationship to QUERY requests. |
website/content/docs/hotchocolate/server/endpoints.md |
Documents configuration and endpoint behavior. |
src/HotChocolate/Fusion/test/Fusion.AspNetCore.Tests/OperationKindTests.cs |
Tests query refusal and mutation support through the Fusion gateway. |
src/HotChocolate/AspNetCore/test/AspNetCore.Tests/PersistedOperationMiddlewareTests.cs |
Tests persisted query and mutation behavior over POST and GET. |
src/HotChocolate/AspNetCore/test/AspNetCore.Tests/HttpQueryMiddlewareTests.cs |
Verifies QUERY requests continue to execute queries. |
src/HotChocolate/AspNetCore/test/AspNetCore.Tests/HttpPostMiddlewareTests.cs |
Covers POST refusals, batching, mutations, subscriptions, and interceptor overrides. |
src/HotChocolate/AspNetCore/test/AspNetCore.Tests/HttpMultipartMiddlewareTests.cs |
Tests query refusal for multipart requests. |
src/HotChocolate/AspNetCore/test/AspNetCore.Tests/HttpGetMiddlewareTests.cs |
Verifies GET queries remain available. |
src/HotChocolate/AspNetCore/test/AspNetCore.Tests/GraphQLOverHttpSpecTests.cs |
Covers status codes and Allow/Accept-Query headers across transport versions. |
src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/Utilities/MiddlewareHelper.cs |
Adds POST flag filtering and refused-query response metadata handling. |
src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/Utilities/HttpResultContextData.cs |
Defines response metadata keys for allowed methods and QUERY support. |
src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/PersistedOperationMiddleware.cs |
Applies the option to persisted-operation POST and GET paths. |
src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/Options/GraphQLServerOptions.cs |
Defines and clones EnableQueriesOverPost. |
src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/HttpPostMiddlewareBase.cs |
Filters POST operation flags and marks refused single-query results. |
src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/HttpGetMiddleware.cs |
Adds refused-query metadata for GET responses. |
src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/Formatters/DefaultHttpResponseFormatter.cs |
Emits configured Allow and Accept-Query headers for refused operations. |
Review effort: Lite
Contributor
Patch coverage100.0% of changed lines covered (74/74)
Project coverage: 59.3% (318668/537779 lines) |
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.
Summary
GraphQLServerOptions.EnableQueriesOverPost,trueby default. When it isfalse, POST requests refuse query operations, so queries run over QUERY or GET while mutations and subscriptions stay on POST, as the QUERY proposal for GraphQL over HTTP recommends for query operations. It covers the GraphQL endpoint, multipart requests, and the persisted-operation POST routes, and the Fusion gateway gets it through the same middleware.Acceptheader and transport version. Its405lists the methods that serve queries inAllow(GET, HEAD, plusQUERYwhen QUERY requests are enabled, or an empty value when none does), withAccept-Querywhen QUERY is listed. In a request batch or an operation batch each query fails on its own, and a variable batch is refused as a whole. While the option isfalse, a query refused over GET lists the methods that serve queries instead ofPOST.EnableQueriesOverPostsection on the endpoints page, rows in both options tables, and pointers from the POST and QUERY sections of the HTTP transport page.Test plan
HttpPostMiddlewareTests: a single query, a variable batch, a request batch, and an operation batch are refused; a mutation and a subscription over POST still run; an interceptor that setsRequestFlags.AllowAlllets a query through.GraphQLOverHttpSpecTests: status,Allow, andAccept-QueryunderLegacy,Draft20250508, andDraft20260903for severalAcceptheaders; theAllowlist for each GET and QUERY configuration, including an empty header; a query refused over GET and HEAD while the option isfalse, andAllow: POSTkept for a refused mutation.PersistedOperationMiddlewareTests,HttpMultipartMiddlewareTests,HttpGetMiddlewareTests, andHttpQueryMiddlewareTests: the persisted POST and GET routes, multipart requests, and GET and QUERY still serving queries.OperationKindTestsinFusion.AspNetCore.Tests: the gateway refuses a query and a query variable batch over POST and runs a mutation.Allowvalue asAllow:over HTTP/1.1, checked outsideTestServer.