Skip to content

fix(graphql): cost invalid list limits at the complexity cap - #14821

Merged
ChiragAgg5k merged 4 commits into
mainfrom
fix/graphql-complexity-limit
Oct 22, 2026
Merged

ChiragAgg5k merged 4 commits into
mainfrom
fix/graphql-complexity-limit

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

What

The GraphQL complexity callback for list fields multiplied the child complexity by the limit query as given. A limit below 1 is rejected later by the route's query validator, but by then the complexity check has already summed it, so it could lower the operation's total cost.

The callback now treats a missing, non-integer, below-1 or above-the-cap limit as just over _APP_GRAPHQL_MAX_COMPLEXITY and caps each field's cost there, which also keeps the sum an integer for very large limits (webonyx's complexity rule returns int). Valid limits are costed exactly as before.

Tests

  • E2E General\AbuseTest::testGraphQLComplexityIgnoresInvalidLimits (abuseEnabled group, since the complexity rule is only registered with abuse options on): two aliased usersList fields with limit(10) succeed; limit(100) next to a field with a negative limit, and a PHP_INT_MAX limit, are each refused with the max complexity error and no data. Runs on CI.

Related: appwrite-labs/cloud#6666

The complexity callback multiplied by the raw limit, so a limit below 1 could cancel out its siblings before the query validator rejected it.
@luxor-code-review

luxor-code-review Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR fixes a GraphQL query-complexity scoring edge case where a list field's limit multiplied by its base complexity could overflow or otherwise bypass the cap, and adds an e2e regression test. The complexity closure now clamps results to maxComplexity + 1 so any over-cap query deterministically fails validation instead of relying on unchecked arithmetic. Negative or non-integer limit values now also short-circuit to the capped value. A new testListUsersComplexityIgnoresNegativeLimit in the GraphQL users e2e suite verifies both a within-cap success path and that a raw negative limit query is rejected with a complexity error and no data.

Files Change
app/init/resources/request.php Cap the list-field complexity calculation at maxComplexity + 1, returning the cap for invalid or oversized limits.
tests/e2e/Services/GraphQL/UsersTest.php Add an e2e test covering the success path at low limits and failure for a negative limit exceeding the cap.

Reviewed commit: 49065fc

@ChiragAgg5k ChiragAgg5k self-assigned this Oct 22, 2026
@ghost

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The incremental test relocation and assertion changes introduce no issues requiring a fix.

The GraphQL list-field complexity callback now assigns invalid list limits an over-cap cost and caps individual contributions, preventing invalid limits from reducing aggregate cost or overflowing it. E2E coverage checks that valid limits pass and negative, over-cap, and PHP_INT_MAX limits are rejected when abuse-enabled complexity rules are active.

Latest changes: The new commits move the complexity regression test from the GraphQL users suite into AbuseTest under the abuseEnabled group and assert the HTTP status for each rejected operation.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 3
File Change
app/init/resources/request.php Bounds each GraphQL list field's complexity contribution and treats invalid limits as over the configured cap.
tests/e2e/General/AbuseTest.php Runs the GraphQL complexity regression checks with abuse enabled, covering valid and invalid list limits.
tests/e2e/Services/GraphQL/UsersTest.php Removes the complexity test now covered by the abuse-enabled general test.

Merged main (7090683); no changes to this PR's code since db51d62 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost 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 A · Looks good to merge. Summary

Comment thread app/init/resources/request.php Resolved

@ghost ghost 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 Oct 22, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

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

Metric Before After Change
🚀 Requests/sec 195.05 206.64 🟢 +5.9%
⏱️ Latency P50 88.59 ms 84.11 ms 🟢 -5.1%
⏱️ Latency P95 208.33 ms 194.53 ms 🟢 -6.6%
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 84.11 194.53 12,654 206.64 -13.79
Account 148.78 272.3 666 11.16 -43.02
TablesDB 79.35 144.15 6,882 113.73 -21.29
Storage 83.87 190.44 3,330 56.95 +6.91
Functions 118.6 235.64 1,776 31.13 -9.96

Top API waits (after)

API request Max wait (ms)
storage.buckets.create 447.35
account.name.update 408.15
account.prefs.update 394.14
functions.create 358.31
storage.files.create 337.74

@github-actions

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.

The complexity rule is only registered when abuse options are enabled, so the test has to live in the abuseEnabled group.
…y-limit

# Conflicts:
#	tests/e2e/General/AbuseTest.php
@ChiragAgg5k
ChiragAgg5k merged commit 70b1d4c into main Oct 22, 2026
67 checks passed
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…#14821)

A negative or huge limit in a list query made the complexity sum negative or overflow, so a costly query could pass the complexity check. Invalid or oversized limits are now costed at the cap.

(cherry picked from commit 70b1d4c)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…#14821)

A negative or huge limit in a list query made the complexity sum negative or overflow, so a costly query could pass the complexity check. Invalid or oversized limits are now costed at the cap.

(cherry picked from commit 70b1d4c)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…#14821)

A negative or huge limit in a list query made the complexity sum negative or overflow, so a costly query could pass the complexity check. Invalid or oversized limits are now costed at the cap.

(cherry picked from commit 70b1d4c)
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
…y-limit

fix(graphql): cost invalid list limits at the complexity cap

(cherry picked from commit 70b1d4c)
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