Repository navigation
fix(graphql): charge list complexity even when the selection is skipped - #15305
Conversation
A list field's complexity was childComplexity x limit, which is 0 when @Skip(if: true) / @include(if: false) removes every selected field. The resolver still runs the REST find() + count(), so the same field aliased thousands of times forced unbounded work at zero charged complexity. Floor the per-row cost at one unit so an executed list field always counts against the cap.
|
Review complete. No issues found — approved ✅. This PR hardens the GraphQL query-complexity limiter: when
Reviewed commit: 7c855c3 |
🟢 Tier S · Ready to mergeThe GraphQL complexity callback now charges at least one unit per requested row for list fields, including selections whose child fields are all skipped. An abuse regression test aliases a skipped list selection repeatedly and checks that the request is rejected by the complexity limit.
📂 Walkthrough · 2
Reviewed |
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
Satisfies the Rector StringCastAssertStringContainsString rule in CI.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
…mplexity fix(graphql): charge list complexity even when the selection is skipped (cherry picked from commit 999a7e8)
What
The GraphQL complexity callback scores a list field as
childComplexity * limit. When every field in the selection set is removed with@skip(if: true)or@include(if: false),childComplexitybecomes0, so the field scores0. graphql-php still invokes the resolver for that field, which runs the underlying REST route (find()+count()).An attacker could therefore alias the same list field thousands of times in one request at a charged complexity of
0and force thousands of sequential database round trips — exactly what_APP_GRAPHQL_MAX_COMPLEXITYis meant to bound.Fix
Floor the per-row cost at one unit (
max($complexity, 1) * $limit). A list field that executes always counts at least its row budget against the cap, so aliasing it repeatedly now exceeds the limit and is rejected. Legitimate queries with a non-empty selection are unaffected — their child complexity is already ≥ 1.Finding
Strix #11 (medium, CVSS 5.3). GraphQL list-field complexity can be forced to zero with
@skip/@include.Test
Added
testZeroSelectionListComplexityBlockedto the GraphQLAbuseTest: it aliasesdatabasesListDocuments40× with every subfield@skipped and asserts the request is rejected with aMax query complexityerror. Under the old scoring each alias cost 0 and the query ran; with the floor it exceeds the cap.composer lintandcomposer analyzepass.Part of appwrite-labs/infrastructure#1013