Skip to content

fix(storage): require ownership on chunked upload resume - #14014

Merged
HarshMN2345 merged 7 commits into
mainfrom
cursor/storage-chunked-resume-ownership-3d35
Sep 30, 2026
Merged

HarshMN2345 merged 7 commits into
mainfrom
cursor/storage-chunked-resume-ownership-3d35

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

POST /v1/storage/buckets/:bucketId/files with Content-Range and x-appwrite-id resumes a chunked upload by loading the existing file with authorization skipped. Bucket create permission was the only check, so another user who can create in the bucket could continue someone else's incomplete upload. The final chunk also wrote the caller's $permissions onto that file.

Resume is now allowed only when the caller may update the file, using the same rules as Files/Update.php:

  • bucket update permission, or
  • file update permission when file security is enabled, or
  • the user who started the upload (so a chunked create can still finish when the file does not grant update)

A later chunk no longer replaces permissions stored on the first chunk. The same check runs before a completed upload is returned for an idempotent resume, so that response is not given to a caller who cannot update the file.

The pending document is created in the same request as the first chunk. That request is not a resume: finalizeUpload only runs the ownership check when the file already existed. Guests have an empty user id, which is stored but never treated as ownership, so a guest can create with Content-Range and a different guest cannot continue that upload.

Same class of bug as #13118 (chunked deployment resume), applied to Storage files (Help Scout #1468091).

Test Plan

  • Client e2e testCreateFileResumeRequiresOwnership:
    • owner can resume a file that does not grant them update
    • another user with only bucket create permission is rejected (401 user_unauthorized) and the file is unchanged
    • a later chunk from the owner does not replace the original permissions
    • resuming a finished upload does not return the file to another user
    • a different user who may update the file can resume it, without replacing permissions
  • Client e2e testCreateFileChunkedAsGuest:
    • guest single-chunk Content-Range create succeeds
    • guest first chunk of a larger upload succeeds
    • a second guest cannot resume that incomplete upload, and permissions stay empty
  • CI Storage client e2e

Related PRs and Issues

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs? (no API metadata change)
Open in Web Open in Cursor 

@HarshMN2345
HarshMN2345 marked this pull request as ready for review September 30, 2026 11:20
@ghost

ghost commented Sep 30, 2026 •

Copy link
Copy Markdown

🔵 Tier A · Mergeable after minor fixes

The previously reported S3 multipart test fixture issue remains unresolved; the latest refactor introduces no new findings.

The PR restricts chunked Storage upload resumes to callers with update permission or the original uploader, while preserving permissions set on the first chunk. Client e2e tests cover owner, delegated-user, unauthorized-user, guest, and completed-upload retry behavior. The latest refactor records uploader metadata inline without changing the authorization behavior.

Latest changes: The newest commit replaces the withUploader helper with inline array_merge calls at both file-creation sites and removes the helper.

Verdict New comments Fixed Still open
✅ Approved 0 0 1
Fix with agent prompt
### Issue 1
tests/e2e/Services/Storage/StorageCustomClientTest.php:1640-1643
**Use a full-sized first part in the multipart resume test**

With S3-backed storage, the successful resume cases fail during multipart completion because `resume-chunk` is below S3's 5 MiB minimum for non-final parts. Please make the first body `$chunkSize` bytes and its range cover that whole part, so this regression test also works with the supported S3 adapter.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
📂 Walkthrough · 2
File Change
src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Create.php Record uploader identity inline, authorize resumes, and preserve permissions from the first chunk.
tests/e2e/Services/Storage/StorageCustomClientTest.php Cover resume authorization, permission preservation, guest uploads, and completed-file metadata disclosure prevention.
⏳ Still open from earlier reviews · 1

Reviewed the commits since f5899f1 · 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 B · 1 blocking finding to address. Summary

@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Critical risk] Adds ownership check to chunked file upload resume.

The PR is not yet safe to merge because existing partial uploads can become impossible for their creators to finish.

Fix All in Claude CodeFindings

  1. P1 Existing uploads cannot resume ▶
Fix with agent prompt
### Issue 1
src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Create.php:648-654
Partial uploads started before this change have no `uploaderId` in their metadata. If their creator has bucket create access but neither bucket nor file update access, the new checks cannot recognize them as the uploader. Their next chunk is rejected, leaving an upload they previously could finish stuck after deployment.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR restricts chunked Storage upload resumes to the original uploader or a caller with update permission, preserves permissions from the first chunk, and adds client e2e coverage.

  • The latest Storage refactor inlines uploader metadata and removes redundant checks.

Reviews (3) · Last reviewed commit: "refactor(storage): inline uploader metad..."

Comment on lines +648 to +654
$metadata = $file->getAttribute('metadata', []);
$uploaderId = \is_array($metadata) ? ($metadata[self::UPLOADER_ID] ?? '') : '';
if (\is_string($uploaderId) && $uploaderId !== '' && $uploaderId === $user->getId()) {
return;
}

throw new Exception(Exception::USER_UNAUTHORIZED, $authorization->getDescription());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Existing uploads cannot resume

Partial uploads started before this change have no uploaderId in their metadata. If their creator has bucket create access but neither bucket nor file update access, the new checks cannot recognize them as the uploader. Their next chunk is rejected, leaving an upload they previously could finish stuck after deployment.

Knowledge Base Used: Storage and file handling

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Create.php
Line: 648-654

Comment:
**Existing uploads cannot resume**

Partial uploads started before this change have no `uploaderId` in their metadata. If their creator has bucket create access but neither bucket nor file update access, the new checks cannot recognize them as the uploader. Their next chunk is rejected, leaving an upload they previously could finish stuck after deployment.

**Knowledge Base Used:** [Storage and file handling](https://app.greptile.com/appwrite/-/custom-context/knowledge-base/appwrite/appwrite/-/docs/storage-files-api.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex

@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

@HarshMN2345 HarshMN2345 reopened this Sep 30, 2026
HarshMN2345 and others added 2 commits September 30, 2026 11:28
Resuming a file with Content-Range and x-appwrite-id loaded it with
authorization skipped, so any caller who could create in the bucket
could continue the upload and replace its permissions. Resume now
requires bucket or file update permission, or the user who started
the upload, and later chunks leave the original permissions in place.

Co-authored-by: Harsh Mahajan <[email protected]>
The pending file is created in the same request that sends the first
chunk, so the resume check was rejecting guests after the transfer.
Only an upload that already existed is checked. An empty guest id is
still not ownership, so another guest cannot continue it.

Co-authored-by: Harsh Mahajan <[email protected]>
@cursor
cursor Bot force-pushed the cursor/storage-chunked-resume-ownership-3d35 branch from 7f66e5f to 2649a24 Compare September 30, 2026 11:29
A caller who cannot read the finished file gets not-found on get, and
a chunked resume does not return the file model.

Co-authored-by: Harsh Mahajan <[email protected]>

@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 on lines +1640 to +1643
$firstBody = 'resume-chunk';
$nextBody = 'x';
$firstRange = 'bytes 0-' . (\strlen($firstBody) - 1) . '/' . $totalSize;
$nextRange = 'bytes ' . $chunkSize . '-' . $chunkSize . '/' . $totalSize;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use a full-sized first part in the multipart resume test

With S3-backed storage, the successful resume cases fail during multipart completion because resume-chunk is below S3's 5 MiB minimum for non-final parts. Please make the first body $chunkSize bytes and its range cover that whole part, so this regression test also works with the supported S3 adapter.

Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/e2e/Services/Storage/StorageCustomClientTest.php
Line: 1640-1643

Comment:
**Use a full-sized first part in the multipart resume test**

With S3-backed storage, the successful resume cases fail during multipart completion because `resume-chunk` is below S3's 5 MiB minimum for non-final parts. Please make the first body `$chunkSize` bytes and its range cover that whole part, so this regression test also works with the supported S3 adapter.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

🟡 Minor · testing · Reply if this doesn't apply.

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → cursor/storage-chunked-resume-ownership-3d35 (after).

Metric Before After Change
🚀 Requests/sec 186.14 197.13 🟢 +5.9%
⏱️ Latency P50 90.18 ms 88.56 ms ⚪ -1.8%
⏱️ Latency P95 223.49 ms 204.5 ms 🟢 -8.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 88.56 204.5 12,483 197.13 -18.99
Account 163.15 313.94 657 10.91 -32.67
TablesDB 86.73 166.14 6,789 109.38 +3.63
Storage 77.66 172.62 3,285 55 -20.16
Functions 122.99 250.57 1,752 30.07 -58.54

Top API waits (after)

API request Max wait (ms)
functions.create 451.32
account.name.update 443.03
account.prefs.update 427.16
functions.variables.update 385.73
tablesdb.rows.delete 385.55

HarshMN2345 and others added 3 commits September 30, 2026 17:09
Files live in a collection per bucket, so the bucketId comparison never fails, and upload metadata is built by the server, so a chunk cannot overwrite the uploader.
@HarshMN2345
HarshMN2345 merged commit 966ec9f into main Sep 30, 2026
51 checks passed
@TorstenDittmann
TorstenDittmann deleted the cursor/storage-chunked-resume-ownership-3d35 branch September 30, 2026 12:02
abnegate added a commit that referenced this pull request Sep 30, 2026
Brings in main's OAuth2 state and nonce validation (#14012), which cloud
needs, along with the realtime origin alignment (#14020), subscriber
target ownership (#14019), GitLab primary email (#14010), impersonation
MFA (#14017), write-only webhook passwords (#14016), chunked-upload
resume ownership (#14014), preview authorize validation (#14013),
nightly forcing (#14015) and scheduled-function enqueue checks (#14011).

The merge had no textual conflicts, and main left composer.json and
composer.lock unchanged. So the lock keeps the branch's database and
async pins.

Main's assertResumeAllowed() in Storage Buckets/Files/Create checks
Input(Database::PERMISSION_UPDATE, ...). utopia-php/database 8 has no
PERMISSION_* constants, so every chunked resume would fail with an
undefined-constant error. It now passes PermissionType::Update, as the
rest of that action already does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

2 participants