Skip to content

Limit input-value depth in variables and schema defaults - #4552

Merged
andimarek merged 3 commits into
masterfrom
codex/limit-variable-coercion-depth
Nov 12, 2026
Merged

andimarek merged 3 commits into
masterfrom
codex/limit-variable-coercion-depth

Conversation

@andimarek

@andimarek andimarek commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

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:

  • Supplied variable values are checked during coercion and normalized-variable conversion, using the request's GraphQLContext override or the JVM-wide limit. Exceeding the limit produces the existing variable-coercion request error, including the variable definition location.
  • Schema defaults are checked during schema validation using the JVM-wide limit, consistently for SDL literals, programmatic values, and legacy internal defaults. Each default is checked independently before recursive schema validators inspect it. Request overrides and later global changes do not recheck validated defaults during execution, getters, printing, or introspection.

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(...), use InputValueLimits.NONE for trusted inputs, or change the JVM-wide limit with setDefaultLimits. 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:

  • Full local Java 25 validation passed: ./gradlew test testng check javadoc jacocoTestReport. Spock: 6,292 passed, 7 skipped. TestNG: 141 passed, 49 skipped.
  • No per-class coverage regressions across 995 classes against the unchanged baseline.
  • 36 limit/default tests passed with -Xss256k; the final cyclic-default case also passed in the full suite.
  • The diagnostic cleanup passed 247 existing tests locally (1 skipped) and build checks, without adding test cases. All 10 GitHub checks passed on 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 9afd53208 used 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 ExecutionInput callers.

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Test Report

Test Results

Java Version Total Passed Failed Errors Skipped
Java 17 6480 (+37 🟢) 6424 (+37 🟢) 0 (±0) 0 (±0) 56 (±0)
Java 21 6480 (+37 🟢) 6424 (+37 🟢) 0 (±0) 0 (±0) 56 (±0)
Java 25 6480 (+37 🟢) 6424 (+37 🟢) 0 (±0) 0 (±0) 56 (±0)
jcstress 32 (±0) 32 (±0) 0 (±0) 0 (±0) 0 (±0)
Total 19472 (+111 🟢) 19304 (+111 🟢) 0 (±0) 0 (±0) 168 (±0)

Code Coverage (Java 25)

Metric Covered Missed Coverage vs Master
Lines 30649 3009 91.1% +0.1% 🟢
Branches 9151 1485 86.0% +0.2% 🟢
Methods 8171 1166 87.5% +0.1% 🟢

Changed Class Coverage (10 classes)

Class Line Branch Method
g.e.InputValueLimits +100.0% 🟢 ±0.0% +100.0% 🟢
g.e.InputValueLimits
$Builder
+100.0% 🟢 +100.0% 🟢 +100.0% 🟢
g.e.ValuesResolverConversion +0.4% 🟢 +2.1% 🟢 +1.4% 🟢
g.e.ValuesResolverLegacy ±0.0% +2.8% 🟢 ±0.0%
g.GraphqlErrorException +9.1% 🟢 ±0.0% +16.7% 🟢
g.s.v.DefaultValueDepth +98.7% 🟢 +91.9% 🟢 +100.0% 🟢
g.s.v.NoDefaultValueCircularRefs +23.0% 🟢 +23.3% 🟢 +20.0% 🟢
g.s.v.SchemaValidator ±0.0% +100.0% 🟢 ±0.0%
g.u.FpKit +0.1% 🟢 +0.7% 🟢 +0.2% 🟢
g.v.OperationValidator +0.2% 🟢 +0.1% 🟢 ±0.0%

Full HTML report: build artifact jacoco-html-report

Updated: 2026-11-12 00:39:27 UTC

@andimarek andimarek changed the title Limit nested external input values during coercion Limit input-value depth in variables and schema defaults Nov 11, 2026
@andimarek andimarek added this to the 27 milestone Nov 12, 2026
@andimarek
andimarek merged commit cc83716 into master Nov 12, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant