Skip to content

fix(graphql): charge list complexity even when the selection is skipped - #15305

Merged
ChiragAgg5k merged 2 commits into
mainfrom
fix/graphql-zero-selection-complexity
Nov 4, 2026
Merged

ChiragAgg5k merged 2 commits into
mainfrom
fix/graphql-zero-selection-complexity

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

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), childComplexity becomes 0, so the field scores 0. 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 0 and force thousands of sequential database round trips — exactly what _APP_GRAPHQL_MAX_COMPLEXITY is 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 testZeroSelectionListComplexityBlocked to the GraphQL AbuseTest: it aliases databasesListDocuments 40× with every subfield @skipped and asserts the request is rejected with a Max query complexity error. Under the old scoring each alias cost 0 and the query ran; with the floor it exceeds the cap.

composer lint and composer analyze pass.

Note: the related undercharge where list routes bound results with a separate limit argument (Strix #12) is deliberately left out — charging the true 1–5000 limit there can push legitimate single usage queries past the default cap, which needs a product call.

Part of appwrite-labs/infrastructure#1013

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.
@luxor-code-review

luxor-code-review Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR hardens the GraphQL query-complexity limiter: when @skip/@include removes every selected child field, the list resolver still executes a full find() + count() per alias, but the previous formula charged zero complexity for that work, letting callers alias a field many times for free. The fix clamps per-field complexity to at least 1 before multiplying by the row limit, and adds an e2e test proving that a 40-alias zero-selection query is now blocked by the complexity cap. Review found no defects in the change itself; the verified residual observation is that single-document fields and mutations (no queries param) still cost 1 per alias regardless of backend work, a pre-existing surface outside this diff's scope.

Files Change
app/init/resources/request.php Complexity estimator now uses min(max($complexity, 1) * $limit, $over) so zero-selection list aliases are charged per row.
tests/e2e/Services/GraphQL/Legacy/AbuseTest.php Adds testZeroSelectionListComplexityBlocked asserting a 40-alias @skip-emptied query exceeds the complexity cap.

Reviewed commit: 7c855c3

@appwrite

appwrite Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The 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.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 2
File Change
app/init/resources/request.php Floors list child complexity at one before multiplying by the requested limit.
tests/e2e/Services/GraphQL/Legacy/AbuseTest.php Adds an e2e regression test for aliased list fields with fully skipped selections.

Reviewed 97ee3b9 · Details · Comment @appwrite review to re-run, or mention @appwrite with a question.

@appwrite appwrite Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

Satisfies the Rector StringCastAssertStringContainsString rule in CI.
@ChiragAgg5k ChiragAgg5k closed this Nov 4, 2026
@ChiragAgg5k ChiragAgg5k reopened this Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/graphql-zero-selection-complexity (after).

Metric Before After Change
🚀 Requests/sec 199.83 214.24 🟢 +7.2%
⏱️ Latency P50 86.47 ms 81.28 ms 🟢 -6%
⏱️ Latency P95 202.31 ms 186.38 ms 🟢 -7.9%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 81.28 186.38 13,566 214.24 -15.93
Account 148.54 288.91 714 11.92 -6.11
TablesDB 79.06 144.06 7,378 119.56 -19.93
Storage 74.92 172.47 3,570 59.48 -9.64
Functions 113.5 213.42 1,904 32.27 -21.04

Top API waits (after)

API request Max wait (ms)
account.prefs.update 454.81
functions.variables.update 435.56
account.name.update 415.68
tablesdb.rows.delete 409.69
functions.create 388.39

@ChiragAgg5k
ChiragAgg5k merged commit 999a7e8 into main Nov 4, 2026
120 of 122 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/graphql-zero-selection-complexity branch November 4, 2026 12:14
@ChiragAgg5k ChiragAgg5k self-assigned this Nov 5, 2026
ChiragAgg5k added a commit that referenced this pull request Nov 12, 2026
…mplexity

fix(graphql): charge list complexity even when the selection is skipped

(cherry picked from commit 999a7e8)
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