Repository navigation
fix(storage): harden chunked uploads, rename and preview - #14935
Conversation
- Reject a Content-Range that addresses a chunk past the last one. - Apply the bucket's allowed extensions when a file is renamed. - Rate limit file previews per caller and file. - Abort chunked uploads idle for 7 days during maintenance and remove their pending file documents.
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Request input holds only query and body values, so a key such as
{param-fileId} never resolved for a path param and every file shared
one preview counter.
|
Review complete. 🟠 1 high · 🟡 1 medium 💬 Inline comments (1)
📍 Findings outside the diff (1) — 🟠 1 high — defects on lines GitHub can't attach comments to🟠 High — Query params override path params in abuse keys, enabling limit bypass · api.php:622–626 · // app/controllers/shared/api.php
622 foreach (\array_merge($pathParams, $request->getParams()) as $key => $value) {
623 if (! empty($value)) {
624 $params['{param-' . $key . '}'] = (\is_array($value) || \is_object($value)) ? (string) \json_encode($value) : (string) $value;
625 }
626 }The abuse-key param map is built with This PR closes gaps around chunked upload lifecycle and abuse limiting: stale incomplete uploads are now reaped by a maintenance worker, invalid content ranges past the last chunk are rejected at chunk time, file renames are validated against bucket extension policies, and file previews get a per-file 60/minute abuse limit keyed on
Reviewed commit: b9a904e |
🟢 Tier S · Ready to merge
Storage API changes reject invalid chunk ranges, enforce bucket extension allowlists on renamed files, and rate-limit previews per file. The maintenance worker also reaps idle chunked uploads by aborting their staged data before deleting pending file records, with retry handling for failed aborts. E2E and unit coverage was added for these behaviors. Latest changes: The newest commits renew the cleanup lock before each device operation and stop cleanup when renewal fails, with a unit case covering lease loss before fallback deletion.
📂 Walkthrough · 9
✅ Fixed since the last review · 1
Reviewed the commits since |
There was a problem hiding this comment.
The PR adds upload-retention cleanup for stale chunked uploads, content-range boundary validation, allowedFileExtensions enforcement on file rename, and per-file abuse keys for file previews — but the abuse-key param merge lets client query params shadow path params, enabling a per-file rate-limit bypass.
Key findings
- 🟠 Query params override path params in abuse keys, enabling limit bypass — api.php:622
- 🟡 Failed S3 abort strands pending upload row forever — Deletes.php:2134
The stored date carries a T separator and offset, so a string comparison against the cutoff misorders values on the same day.
A failed abort keeps the row and its upload ID for up to three runs before falling back to deleting the path. The cleanup lease matches the upload lease and is checked before any row is changed.
Also exercises the upload retry through the maintenance job instead of the private method.
…rdening # Conflicts: # src/Appwrite/Platform/Workers/Deletes.php
Refreshing the lease before the abort, the retry write, the fallback delete and the row removal stops cleanup once another holder owns the key, and gives each step a full TTL.
What does this PR do?
Small storage hardening fixes:
Content-Rangestarting at the declared size (e.g.bytes 10485760-10485760/10485760) mapped to chunkchunksTotal + 1. That stray part could leave an upload unable to finalize. These requests now fail withstorage_invalid_content_range, the same as other invalid ranges. A zero total is rejected for the same reason.PUT /v1/storage/buckets/:bucketId/files/:fileIdnow checks a changednameagainst the bucket'sallowedFileExtensions, as create already does. It returnsstorage_file_type_unsupportedon a mismatch. A name that doesn't change is not re-checked, so files uploaded before an allowlist change can still have their permissions updated.getFilePreviewgets an abuse limit of 60 requests per minute. The key is IP + user + file, so a gallery of many different files is unaffected. API keys and console users are exempt, as with every other abuse limit.APP_STORAGE_UPLOAD_RETENTION). It aborts the staged parts on the device (Localtmp_directory or S3 multipart upload) and deletes the pending file document. Until now these were only removed if someone explicitly deleted the file.Why the cleanup sits in the maintenance delete job
Expiry of per-project data already runs from
DELETE_TYPE_MAINTENANCEin the deletes worker (sessions, tokens, challenges, transactions, presences, push ledger). The storage device for the project is already injected there, so adding cleanup to that list needs no new queue, schedule or injection, and the worker'saction()signature stays the same.signatureuntil its last chunk completes it, so the query uses the existing_key_signatureindex. A row is touched only afterchunksUploaded < chunksTotalis confirmed in code.$updatedAtmeasures time since the last chunk. A slow but active upload is never removed.The per-chunk component of the create-file abuse key is left unchanged. Removing it would limit every client upload to 60 chunks (about 300 MB) per minute.
Test Plan
New E2E tests:
StorageCustomServerTest::testChunkedUploadRejectsRangePastLastChunk: a range one past the last chunk returns 400storage_invalid_content_range, and no pending file is created.StorageCustomServerTest::testUpdateFileRejectsDisallowedExtension: in apng-only bucket, renaming torenamed.pngsucceeds, renaming torenamed.exereturns 400storage_file_type_unsupported, and the stored name is unchanged.StorageCustomServerTest::testIdleChunkedUploadDeletedByMaintenance:maintenance --type=trigger.AbuseTest::testAbuseGetFilePreview(abuseEnabledgroup):Local runs:
composer lint(Pint) on the changed files passes.tests/unit/Platform/Workers/DeletesTest.phppasses.Related PRs and Issues
Checklist