Add depth limit to GraphQL parser#9519
Merged
michaelstaib merged 5 commits intomainfrom Apr 10, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a configurable recursion depth limit to the HotChocolate UTF-8 GraphQL parser to prevent stack overflows from deeply nested documents.
Changes:
- Introduces
MaxAllowedRecursionDepth(default: 200) onParserOptionsand threads it through core + fusion request parsing options. - Enforces recursion depth tracking in the UTF-8 parser for selection sets, value literals, and type references, throwing a
SyntaxExceptionwhen exceeded. - Adds test coverage for default/custom depth limits and several nesting “vectors” (selection sets, object/list values, list types).
Reviewed changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/HotChocolate/Language/test/Language.Tests/Parser/QueryParserTests.cs | Adds unit tests for default/custom recursion depth behavior and error messages. |
| src/HotChocolate/Language/src/Language.Utf8/Utf8GraphQLParser.Values.cs | Tracks recursion depth when parsing value literals (object/list nesting, etc.). |
| src/HotChocolate/Language/src/Language.Utf8/Utf8GraphQLParser.Utilities.cs | Adds IncreaseDepth / DecreaseDepth helpers and throws when limit is exceeded. |
| src/HotChocolate/Language/src/Language.Utf8/Utf8GraphQLParser.Types.cs | Tracks recursion depth when parsing type references (nested list / non-null types). |
| src/HotChocolate/Language/src/Language.Utf8/Utf8GraphQLParser.Operations.cs | Tracks recursion depth when parsing selection sets (nested field selections). |
| src/HotChocolate/Language/src/Language.Utf8/Utf8GraphQLParser.cs | Stores max depth from options and resets recursion depth per Parse() call. |
| src/HotChocolate/Language/src/Language.Utf8/Properties/LangUtf8Resources.resx | Adds localized resource text for the max recursion depth error message. |
| src/HotChocolate/Language/src/Language.Utf8/Properties/LangUtf8Resources.Designer.cs | Adds the strongly-typed resource accessor for the new message. |
| src/HotChocolate/Language/src/Language.Utf8/ParserOptions.cs | Adds MaxAllowedRecursionDepth to parser options (default 200). |
| src/HotChocolate/Fusion/src/Fusion.Execution/Execution/FusionRequestExecutorManager.cs | Passes fusion max recursion depth through to ParserOptions. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Execution/FusionParserOptions.cs | Exposes MaxAllowedRecursionDepth on fusion parser options. |
| src/HotChocolate/Core/src/Types/Execution/Options/RequestParserOptions.cs | Exposes MaxAllowedRecursionDepth on core request parser options + doc updates. |
| src/HotChocolate/Core/src/Types/Execution/DependencyInjection/RequestExecutorServiceCollectionExtensions.cs | Passes core max recursion depth through to ParserOptions. |
Files not reviewed (1)
- src/HotChocolate/Language/src/Language.Utf8/Properties/LangUtf8Resources.Designer.cs: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Agent-Logs-Url: https://github.com/ChilliCream/graphql-platform/sessions/ea56bfff-e29b-4443-b632-677b12920b1e Co-authored-by: michaelstaib <9714350+michaelstaib@users.noreply.github.com>
|
|
This was referenced May 1, 2026
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.
No description provided.