Denial of Service in Document Validation
Description
Hot Chocolate limits how deeply a GraphQL document can be nested with the parser option MaxAllowedRecursionDepth. Document validation, cost analysis and operation compilation are not bound by this limit and had no depth limit of their own. A client document can make them overflow the stack, and the process terminates with a StackOverflowException.
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.
Fixed Versions
- 16.7.3
- 15.1.20
- 14.3.4
- 13.9.19
Impact
An unauthenticated client can terminate the server or gateway process with a single request. A StackOverflowException cannot be caught, so every in-flight request and open subscription on that process is dropped, and the request can be repeated after each restart. The attacker needs almost no knowledge of the schema. Authorization on fields or types does not prevent it, because the crash happens before any field is resolved. The parser's MaxAllowedRecursionDepth and AddMaxExecutionDepthRule do not prevent it either. Requiring authentication for the GraphQL endpoint limits the attack to authenticated clients.
This issue is classified as CWE-674: Uncontrolled Recursion.
Recommendation
Upgrade to one of the fixed releases. The validator then refuses an operation whose selection sets are nested deeper than 200 levels, counting the nesting inside the fragments it uses. Fields with a selection set, inline fragments and fragment spreads each count as one level. Such an operation is answered with a validation error. The limit is set with MaxAllowedSelectionSetDepth on the validation options:
builder
.AddGraphQLServer()
.ConfigureValidation((_, b) => b.ModifyOptions(o => o.MaxAllowedSelectionSetDepth = 100));If the application raises the parser option MaxAllowedRecursionDepth, raise this limit as well. A document whose fragment spreads form a cycle is now answered with the fragment cycle error only.
There is no workaround.
Affected versions
- HotChocolate.ValidationFrom 16.0.0 · fixed in 16.7.3
- HotChocolate.ValidationFrom 15.0.0 · fixed in 15.1.20
- HotChocolate.ValidationFrom 14.0.0 · fixed in 14.3.4
- HotChocolate.Validationfixed in 13.9.19
- HotChocolate.AspNetCoreFrom 16.0.0 · fixed in 16.7.3
- HotChocolate.AspNetCoreFrom 15.0.0 · fixed in 15.1.20
- HotChocolate.AspNetCoreFrom 14.0.0 · fixed in 14.3.4
- HotChocolate.AspNetCorefixed in 13.9.19
- HotChocolate.FusionFrom 15.0.0 · fixed in 15.1.20
- HotChocolate.FusionFrom 14.0.0 · fixed in 14.3.4
- HotChocolate.Fusionfixed in 13.9.19
- HotChocolate.Fusion.AspNetCoreFrom 16.0.0 · fixed in 16.7.3