Denial of Service via Fragment Expansion
Description
A GraphQL fragment repeats its selections wherever it is spread. Hot Chocolate limited the number of fields in a document and the depth to which it nests, but not the number of selections the document describes once its fragment spreads are followed. A client could therefore send a small document that expands into a very large operation, and the server spent CPU and memory out of proportion to the request while normalizing, analyzing and compiling it, before any field was resolved.
An application is affected when both of the following hold:
- It runs a Hot Chocolate server (
AddGraphQLServer(),AddGraphQL(), orAddGraphQLFunction()with Azure Functions) or a Fusion gateway (AddGraphQLGatewayServer()orAddGraphQLGateway(), orAddFusionGatewayServer()in 13.x to 15.x). - It accepts operation documents from clients. This is the default. Applications that only execute persisted operations are not affected.
The default configuration is affected. Versions before 13.0.0 are also affected and receive no fix on this advisory; those users should move to 13.9.20 or later.
Fixed Versions
- 16.7.4
- 15.1.21
- 14.3.5
- 13.9.20
Impact
Any client that can send a query to the GraphQL endpoint can degrade or deny service with small requests, using no authentication and almost no knowledge of the schema. Enough such requests in flight keep the server from answering other clients through CPU and memory use. On a Fusion gateway, a single request can occupy a processor core past the execution timeout and after the client has disconnected, until the process is restarted. Under a configured memory limit a request is answered with an error and the process survives; without one, memory use can grow until the process is terminated by the host. Field and type authorization do not prevent it, because the work happens before any field is resolved, and the parser and cost limits do not bound it.
This issue is classified as CWE-407: Inefficient Algorithmic Complexity.
Recommendation
Upgrade to one of the fixed releases. The validator then counts the selections of an operation once its fragment spreads are followed, where fields, inline fragments and fragment spreads each count as one selection and the selections of a fragment count every time it is spread, and refuses an operation with more than 100,000 selections with a validation error. The limit is set with MaxAllowedSelections on the validation options:
builder
.AddGraphQLServer()
.ConfigureValidation((_, b) => b.ModifyOptions(o => o.MaxAllowedSelections = 5_000));Applications with very large operations that reuse fragments heavily may need to raise this limit. Valid operations within the limit are not affected.
There is no workaround on an unpatched release that both accepts client documents and leaves this limit unset.
Affected versions
- HotChocolate.ValidationFrom 16.0.0 · fixed in 16.7.4
- HotChocolate.ValidationFrom 15.0.0 · fixed in 15.1.21
- HotChocolate.ValidationFrom 14.0.0 · fixed in 14.3.5
- HotChocolate.Validationfixed in 13.9.20
- HotChocolate.Fusion.UtilitiesFrom 16.0.0 · fixed in 16.7.4
- HotChocolate.Fusion.ExecutionFrom 16.0.0 · fixed in 16.7.4
- HotChocolate.CostAnalysisFrom 16.0.0 · fixed in 16.7.4
- HotChocolate.AspNetCoreFrom 16.0.0 · fixed in 16.7.4
- HotChocolate.AspNetCoreFrom 15.0.0 · fixed in 15.1.21
- HotChocolate.AspNetCoreFrom 14.0.0 · fixed in 14.3.5
- HotChocolate.AspNetCorefixed in 13.9.20
- HotChocolate.Fusion.AspNetCoreFrom 16.0.0 · fixed in 16.7.4
- HotChocolate.FusionFrom 15.0.0 · fixed in 15.1.21
- HotChocolate.FusionFrom 14.0.0 · fixed in 14.3.5
- HotChocolate.Fusionfixed in 13.9.20