Repository navigation
fix(abuse): keep rate limits on requests with out-of-range Content-Range - #14816
Conversation
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.
|
Review complete. 🟡 1 medium 💬 Inline comments (1)
This change moves
Reviewed commit: ec3eae2 |
🟢 Tier S · Ready to mergeContent-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.
📂 Walkthrough · 4
Reviewed the commits since |
There was a problem hiding this comment.
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
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.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
# Conflicts: # tests/unit/Utopia/RequestTest.php
…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)
…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)
…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)
…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)
…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)
fix(abuse): keep rate limits on requests with out-of-range Content-Range (cherry picked from commit f83fd3a)
What
The abuse init hook derives
{chunkId}from the Content-Range header. Bounds at or pastPHP_INT_MAXsaturate 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 reachesPHP_INT_MAX(any bound that overflowed lands there), soend + 1always stays an integer. Upload routes already answer an unparseable range with400 storage_invalid_content_range.Request::getContentRangeChunk()computes the chunk index asintdiv(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 existing
start <= end <= sizerule is unchanged (the storage TODO aboutend >= sizeis left for a breaking release).Tests
tests/unit/Utopia/RequestTest.phpcovers chunk indexes and rejected ranges (bounds at and past the integer limit, start after end, end past size, malformed headers). Run locally.tests/e2e/General/AbuseTest.phpchecks that a request carrying an out-of-range Content-Range is still counted and throttled, and that a file upload with one is rejected with400 storage_invalid_content_range. CI only.Related: appwrite-labs/cloud#6674