Details
Impact
- Process termination: a single 74 KB POST kills the entire PHP process that handles it. In php-fpm, the worker is killed and respawned by the master; every other in-flight request on that worker is dropped. In long-running PHP runtimes (Swoole, RoadRunner, ReactPHP), the entire daemon dies.
- Pre-validation:
Parser::parseis invoked before any validation rule. Field count caps, complexity analyzers, persisted query allow-lists, and all custom validators run after parsing and therefore cannot intercept the crash. - No catchable error: unlike a slow query, a memory_limit exceeded, or a parse error, SIGSEGV cannot be intercepted by PHP. There is no error log entry from the PHP application; only the FPM master log shows
child exited on signal 11. - Tiny payload: 74 KB is well below every common HTTP body size limit. The query is also extremely compressible:
[repeated 37,500 times compresses to a few hundred bytes via gzip, bypassing nginxclient_max_body_size, AWS ALB body-size caps, and WAF inspection of the encoded payload. - Ecosystem reach: webonyx/graphql-php is the parser used by Lighthouse (Laravel), Overblog/GraphQLBundle (Symfony), wp-graphql (WordPress), Drupal GraphQL module, and the majority of PHP GraphQL servers. Any of these is exposed unless the front layer rejects the decompressed payload before reaching the parser.
Affected Versions
- `webonyx/[email protected]` (latest stable as of 2026-04-08): all four vectors confirmed by direct measurement.
- The recursive descent design has been unchanged since the parser was rewritten in v15.x. Earlier 15.x and 14.x releases share the same code path and are believed vulnerable but were not retested individually.
Remediation
Option 1 -- Add a parser-level recursion depth counter (recommended)
Add a recursionDepth and maxRecursionDepth field to GraphQL\Language\Parser. Increment at the entry of each recursive method, decrement on return, and throw a SyntaxError when it exceeds the configured limit. A sensible default is 256: well above any realistic legitimate query, and approximately 100x below the smallest current crash threshold.
// src/Language/Parser.php
class Parser
{
private int $recursionDepth = 0;
private int $maxRecursionDepth;
public function __construct($source, array $options = [])
{
$this->maxRecursionDepth = $options['maxRecursionDepth'] ?? 256;
// ... existing body ...
}
private function parseValueLiteral(bool $isConst): ValueNode
{
if (++$this->recursionDepth > $this->maxRecursionDepth) {
throw new SyntaxError(
$this->lexer->source,
$this->lexer->token->start,
"Document exceeds maximum allowed recursion depth of {$this->maxRecursionDepth}."
);
}
try {
// ... existing body ...
} finally {
--$this->recursionDepth;
}
}
}
Apply the same pattern to parseSelectionSet, parseObject, parseObjectField, parseList, parseTypeReference, parseInlineFragment, and parseField. The thrown SyntaxError is a normal PHP exception and is fully catchable by user code.
Option 2 -- Iterative parsing for the deepest call chains
Rewrite parseValueLiteral / parseObject / parseList and parseTypeReference using an explicit work stack instead of mutual recursion. This removes the call frame budget entirely for those vectors but does not address parseSelectionSet, which is harder to convert.
Option 3 -- Recommend a token limit option in addition to depth
graphql-php currently has no token limit option at all. Adding a maxTokens parser option would provide defense in depth even if the recursion limit is misconfigured.
The strongest fix is Option 1 with a non-zero default for maxRecursionDepth.
Audit status of related parser-side findings on graphql-php 15.31.4
The following two related parser/validator findings were tested against webonyx/[email protected].
Token-limit comment bypass
Not applicable: graphql-php exposes no `maxTokens` option of any kind. The bypass class does not apply because there is no token counter to bypass. However, this is itself a finding worth documenting: graphql-php has no parser-side resource limits whatsoever. A 391 KB comment-padded payload (100,000 comment lines) is parsed in 193 ms with a +18.4 MB heap delta, with no upper bound. Operators relying on graphql-php as their primary line of defense have no parser-level mitigation against query-size DoS, only the global memory_limit and PHP's post_max_size.
The Lexer::lookahead method does loop while $token->kind === Token::COMMENT (so comments are silently consumed before any per-token check would run), but in graphql-php this is moot because there is no maxTokens counter to bypass in the first place.
OverlappingFieldsCanBeMerged validation DoS
graphql-php is vulnerable. src/Validator/Rules/OverlappingFieldsCanBeMerged.php:311 contains an O(n^2) pairwise loop, and inline fragments are flattened into the same $astAndDefs map at line 266 (case $selection instanceof InlineFragmentNode: $this->internalCollectFieldsAndFragmentNames(... $astAndDefs ...)), bypassing the named-fragment cache. Measured validation cost: 117 seconds for a 364 KB query (200 outer x 100 inner inline fragments). This is documented in a separate advisory: see GHSA_REPORT_GRAPHQL_PHP_15-31-4_OVERLAPPING_FIELDS.md.
This audit covers the three parser-side and validation-side findings tracked together for this implementation. The parser stack overflow documented above and the OverlappingFieldsCanBeMerged validation DoS are exploitable on graphql-php 15.31.4; the token-limit comment bypass is not applicable because there is no token limit option to bypass (which is itself a defense-in-depth gap).
Resources
- PHP documentation `zend.max_allowed_stack_size` -- introduced in PHP 8.3
- Linux signal(7) -- SIGSEGV (signal 11) is delivered by the kernel for invalid memory access; PHP cannot intercept it
- Companion advisory for this implementation:
OverlappingFieldsCanBeMergedquadratic validation DoS via flattened inline fragments (Quadratic validation cost in OverlappingFieldsCanBeMerged via inline fragments).