Skip to content

fix(storage): check the content of uploads with an allowed signed extension - #15546

Merged
ChiragAgg5k merged 3 commits into
mainfrom
fix-upload-octet-stream-allowlist
Nov 12, 2026
Merged

ChiragAgg5k merged 3 commits into
mainfrom
fix-upload-octet-stream-allowlist

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #15458. The content check skipped any upload whose sniffed type is in formats.ambiguous, so with allowedFileExtensions set, content that sniffs as application/octet-stream was accepted under an allowed .png or .pdf name. Every signed extension is an image or PDF, never a container, so the ambiguous exemption is dropped from that check; the later remap for container extensions is unchanged.

Extends testCreateFileRejectsDisallowedContent with random bytes uploaded as binary.png (400 storage_file_type_unsupported).

Related: appwrite-labs/cloud#6666

…ension

A sniffed type in the ambiguous list skipped the content check, so an upload named with an allowed signed extension (png, pdf, ...) was accepted whatever its content. Signed extensions are images and PDFs, never containers, so the exemption is not needed there.
@luxor-code-review

luxor-code-review Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 1 medium

💬 Inline comments (1)

  • 🟡 S3 gateway still allows ambiguous-MIME bypass REST upload removed — Create.php:507

The change closes a content-type bypass in the Storage Files/Create endpoint: previously a file whose extension was allowed could bypass MIME-signature validation when its sniffed type appeared in the ambiguous list (e.g. application/octet-stream). The exemption is removed, so the sniffed type must now match one of the bucket's allowed types.

Files Change
src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Create.php Removes the ambiguous MIME exemption from the upload validation condition, rejecting extension-allowed files whose sniffed type is not in the bucket's allowed list.
tests/e2e/Services/Storage/StorageCustomServerTest.php Adds an e2e case uploading random bytes named binary.png with an image/png declared type and asserting a 400 storage_file_type_unsupported rejection.

One residual gap was identified: the S3-compatible gateway (src/Appwrite/Platform/Modules/S3/Http/S3/Base.php) retains the same ambiguous-MIME exemption its docblock claims mirrors the REST upload, so the two entry points now enforce divergent rules.

Reviewed commit: ec52b68

@appwrite

appwrite Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The upload content check now rejects signed image and PDF extensions when the detected MIME type is outside the bucket’s allowed signatures, including ambiguous octet-stream content. The same rule is applied to both Storage API uploads and S3 gateway writes, with regression coverage for random bytes named as PNG files.

Latest changes: The latest commits remove the ambiguous-MIME exemption from S3 content validation and add an S3 regression case for random bytes uploaded as binary.png.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 4
File Change
src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Create.php Removes the ambiguous-MIME exemption from Storage API validation for signed extensions.
src/Appwrite/Platform/Modules/S3/Http/S3/Base.php Applies the same strict signature check to S3 gateway writes.
tests/e2e/Services/Storage/StorageCustomServerTest.php Adds random binary PNG-named content to the Storage API rejection regression test.
tests/e2e/Services/Storage/S3CustomServerTest.php Adds an S3 regression case for random bytes uploaded with a PNG extension.

Reviewed the commits since ec52b68 · Details · Comment @appwrite review to re-run, or mention @appwrite with a question.

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

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

This PR tightens the Storage file-upload validation so files with signed extensions must sniff to an allowed MIME type, closing an ambiguous-content-type bypass covered by a new e2e test.

Key findings

  • 🟡 S3 gateway still allows ambiguous-MIME bypass REST upload removed — Create.php:507

@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 S3 gateway kept the ambiguous-type exemption that the REST upload dropped, so random bytes named .png still passed there.
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix-upload-octet-stream-allowlist (after).

Metric Before After Change
🚀 Requests/sec 208.18 218.28 ⚪ +4.8%
⏱️ Latency P50 83.86 ms 77.82 ms 🟢 -7.2%
⏱️ Latency P95 190 ms 192.4 ms ⚪ +1.3%
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 77.82 192.4 13,680 218.28 +2.39
Account 161.47 332.8 720 12.06 +65.7
TablesDB 75 142.45 7,440 120.89 -18.64
Storage 71.28 162.14 3,600 60.58 -6.08
Functions 116.59 231.07 1,920 33.03 +21.16

Top API waits (after)

API request Max wait (ms)
account.name.update 632.83
account.prefs.update 480.59
storage.files.create 472.38
functions.delete 450.51
functions.variables.update 439.53

@ChiragAgg5k
ChiragAgg5k merged commit 8d8a96e into main Nov 12, 2026
43 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix-upload-octet-stream-allowlist branch November 12, 2026 13:31
@ChiragAgg5k ChiragAgg5k self-assigned this Nov 13, 2026
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