Skip to main content
Menu
Advisories

Denial of Service in Document Validation

GHSA-J5VG-MQW8-P958Published Updated GitHub

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(), or AddGraphQLFunction() with Azure Functions) or a Fusion gateway (AddGraphQLGatewayServer() or AddGraphQLGateway(), or AddFusionGatewayServer() 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

References

GitHub · ChilliCream/graphql-platform