Repository navigation
Limit input-value depth in variables and schema defaults - #4552
Merged
Merged
Conversation
Contributor
Test ReportTest Results
Code Coverage (Java 25)
Changed Class Coverage (10 classes)
|
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.
Deeply nested external variables can overflow recursive coercion even for a small operation. This change adds
InputValueLimits, with a default maximum depth of 128 input-object/list values per path.The policy applies at two boundaries:
GraphQLContextoverride or the JVM-wide limit. Exceeding the limit produces the existing variable-coercion request error, including the variable definition location.Non-null wrappers do not count. Nulls and scalar payloads are not traversed. Singleton-list coercion counts as a list level, and siblings do not accumulate depth. Filling in an omitted schema default does not consume the supplied variable's depth budget.
The early schema check reports the default's coordinate without printing the oversized value. Programmatic list defaults use collections or arrays; iterators, streams, and other iterables are rejected during schema validation without being consumed.
Applications can configure
InputValueLimits.newInputValueLimits().maxDepth(...), useInputValueLimits.NONEfor trusted inputs, or change the JVM-wide limit withsetDefaultLimits. Set the JVM-wide limit before building a schema to control default validation; per-request overrides govern supplied variables only.Breaking change: Values deeper than 128 are rejected by default, including schema defaults at build time. Programmatic list defaults must use collections or arrays. Custom scalar payloads remain the scalar implementation's responsibility.
Internal coercion helpers no longer carry synthetic variable names. Variable names are attached to request errors at the variable boundary; internal OneOf assertions identify the input type.
Tests exercise exact boundaries across argument, input-field and directive defaults; SDL parsing; strict request overrides; introspection and default getters; supplied-variable rejection; very deep and cyclic defaults; list coercion; scalar opacity; and rejecting one-shot inputs without consuming them.
Validation:
./gradlew test testng check javadoc jacocoTestReport. Spock: 6,292 passed, 7 skipped. TestNG: 141 passed, 49 skipped.-Xss256k; the final cyclic-default case also passed in the full suite.ad9cce96f: Java 17/21/25 tests and TestNG, build checks, Javadoc, jcstress, file validation, and the per-class coverage gate.JMH results recorded for the initial variable-coercion commit
9afd53208used two forks, three 5-second warmup iterations, and three 5-second measurement iterations per fork (µs/op, master → initial implementation): scalar 0.045 → 0.045; shallow object 0.078 → 0.075; 100-item list 0.776 → 0.794; 33-level object chain 11.257 → 11.462. The small differences were within the measured uncertainty. These measurements do not cover the added schema-validation pass; no new timing claim is made for the follow-up.HTTP adapters may enforce JSON nesting limits before values reach GraphQL Java; this change also protects direct
ExecutionInputcallers.