Skip to content

fix(abuse): keep rate limits on requests with out-of-range Content-Range - #14816

Merged
ChiragAgg5k merged 4 commits into
mainfrom
fix/abuse-content-range
Oct 22, 2026
Merged

ChiragAgg5k merged 4 commits into
mainfrom
fix/abuse-content-range

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

What

The abuse init hook derives {chunkId} from the Content-Range header. Bounds at or past PHP_INT_MAX saturate when parsed, so the chunk arithmetic turned into a float division by zero. The hook's catch, which exists so a limiter outage fails open, also swallowed that error and skipped the limit for the request.

  • Appwrite\Utopia\Request::parseContentRange() now rejects ranges whose size reaches PHP_INT_MAX (any bound that overflowed lands there), so end + 1 always stays an integer. Upload routes already answer an unparseable range with 400 storage_invalid_content_range.
  • New Request::getContentRangeChunk() computes the chunk index as intdiv(start, APP_LIMIT_UPLOAD_CHUNK_SIZE), the chunk the server stores the range in, instead of dividing by the client-chosen range length. It returns 0 without a valid range (same value as before for requests without the header). Both abuse hooks use it.
  • The abuse init hook fails open only when the limiter call itself fails. An error while building the key parameters is rethrown instead of skipping the limit.

The existing start <= end <= size rule is unchanged (the storage TODO about end >= size is left for a breaking release).

Tests

  • Unit: tests/unit/Utopia/RequestTest.php covers chunk indexes and rejected ranges (bounds at and past the integer limit, start after end, end past size, malformed headers). Run locally.
  • E2E: tests/e2e/General/AbuseTest.php checks that a request carrying an out-of-range Content-Range is still counted and throttled, and that a file upload with one is rejected with 400 storage_invalid_content_range. CI only.

Related: appwrite-labs/cloud#6674

Content-Range bounds at or past PHP_INT_MAX made the chunk index arithmetic throw, and the abuse hook treated that like a limiter outage and skipped the limit. Reject such ranges in the request parser, compute the chunk index with integer division, and only fail open when the limiter itself fails.
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. 🟡 1 medium

💬 Inline comments (1)

  • 🟡 Attacker can rotate {chunkId} to mint fresh rate-limit buckets — Request.php:259

This change moves Content-Range parsing into src/Appwrite/Utopia/Request.php and wires the parsed range into the abuse-limit key construction in app/controllers/shared/api.php, so chunked upload requests are bucketed by content chunk rather than only by client, closing a rate-limit bypass for chunked uploads.

Files Change
src/Appwrite/Utopia/Request.php Adds Content-Range parsing with validation and memoized getters for start/end/total.
app/controllers/shared/api.php Uses the parsed chunk info in the abuse key so chunked uploads are rate-limited per chunk.
tests/unit/Utopia/RequestTest.php, tests/e2e/General/AbuseTest.php Adds unit coverage for parsing edge cases and an e2e abuse-limit test for chunked uploads.

Reviewed commit: ec3eae2

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

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

Content-Range parsing now rejects integer-overflowing ranges, and upload abuse keys use the server's upload-chunk index. The init hook only fails open for limiter-call errors, with unit and E2E coverage for the parsing, throttling, and upload-rejection behavior.

Latest changes: The newest commit adds a randomized forwarded client address to the invalid-range upload test so its requests use an isolated IP-based abuse-limit key.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 4
File Change
app/controllers/shared/api.php Both abuse hooks derive the chunk key from the upload chunk size, and init-hook errors during key construction are no longer swallowed as limiter outages.
src/Appwrite/Utopia/Request.php Rejects Content-Range values that cannot be safely represented as integers and exposes the server-aligned chunk index.
tests/e2e/General/AbuseTest.php Verifies out-of-range Content-Range throttling and upload rejection, using a randomized forwarded address for the upload requests.
tests/unit/Utopia/RequestTest.php Covers chunk-index calculation and invalid Content-Range boundaries.

Reviewed the commits since 5ce8381 · 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 S · Looks good to merge. Summary

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

The PR hardens abuse rate-limiting by parsing Content-Range on the Request object so chunked uploads are throttled by content chunk, and adds e2e/unit coverage.

Key findings

  • 🟡 Attacker can rotate {chunkId} to mint fresh rate-limit buckets — Request.php:259

Comment thread src/Appwrite/Utopia/Request.php Resolved
Dividing the range start by the client's own range length let each request pick its own chunk bucket. Using the fixed upload chunk size maps every range to the chunk the server stores it in.
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/abuse-content-range (after).

Metric Before After Change
🚀 Requests/sec 184.46 206.65 🟢 +12%
⏱️ Latency P50 93.04 ms 84.87 ms 🟢 -8.8%
⏱️ Latency P95 219.08 ms 191.7 ms 🟢 -12.5%
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.87 191.7 12,825 206.65 -27.38
Account 145.81 279.79 675 11.22 -41.53
TablesDB 81.1 145.05 6,975 114.45 -21.33
Storage 81.8 203.72 3,375 57.09 +7.23
Functions 109.76 212.52 1,800 31.44 -115.91

Top API waits (after)

API request Max wait (ms)
functions.variables.update 462.01
account.prefs.update 442.47
functions.create 423.05
storage.files.create 418.99
functions.variables.create 377.66

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

@ChiragAgg5k
ChiragAgg5k merged commit f83fd3a into main Oct 22, 2026
67 checks passed
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…port #14816)

Content-Range bounds at or past PHP_INT_MAX made the chunk arithmetic divide by zero, and the abuse hook swallowed the error and skipped the limit. Such ranges are now rejected, the chunk index is start divided by the upload chunk size, and the hook fails open only when the limiter itself fails.

(cherry picked from commit f83fd3a)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…port #14816)

Content-Range bounds at or past PHP_INT_MAX made the chunk arithmetic divide by zero, and the abuse hook swallowed the error and skipped the limit. Such ranges are now rejected, the chunk index is start divided by the upload chunk size, and the hook fails open only when the limiter itself fails.

(cherry picked from commit f83fd3a)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…port #14816)

Content-Range bounds at or past PHP_INT_MAX made the chunk arithmetic divide by zero, and the abuse hook swallowed the error and skipped the limit. Such ranges are now rejected, the chunk index is start divided by the upload chunk size, and the hook fails open only when the limiter itself fails.

(cherry picked from commit f83fd3a)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…port #14816)

Content-Range bounds at or past PHP_INT_MAX made the chunk arithmetic divide by zero, and the abuse hook swallowed the error and skipped the limit. Such ranges are now rejected, the chunk index is start divided by the upload chunk size, and the hook fails open only when the limiter itself fails.

(cherry picked from commit f83fd3a)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…port #14816)

Content-Range bounds at or past PHP_INT_MAX made the chunk arithmetic divide by zero, and the abuse hook swallowed the error and skipped the limit. Such ranges are now rejected, the chunk index is start divided by the upload chunk size, and the hook fails open only when the limiter itself fails.

(cherry picked from commit f83fd3a)
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
fix(abuse): keep rate limits on requests with out-of-range Content-Range

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