Skip to content

fix(storage): reject uploads whose content is not an allowed format - #15458

Merged
HarshMN2345 merged 4 commits into
mainfrom
fix-storage-file-type-content
Nov 10, 2026
Merged

HarshMN2345 merged 4 commits into
mainfrom
fix-storage-file-type-content

Conversation

@HarshMN2345

Copy link
Copy Markdown
Member

Buckets with allowedFileExtensions only checked the filename, so a PDF or HTML page renamed to .png was stored in an images-only bucket.

When an upload finishes, the type sniffed from the file's bytes is now checked against the bucket's allowed extensions. It applies only when the file's extension has a fixed signature (images and PDF, listed in formats.php under signatures). The content must sniff as one of the formats the bucket allows, so a JPEG named .png still passes in a bucket that allows jpg. Ambiguous sniffs (zip, octet-stream) and extensions without a signature keep the name-only check. A rejected upload is removed and returns storage_file_type_unsupported.

Behaviour change: uploads to restricted buckets whose content is not an allowed format now fail. The S3-compatible API is not covered here.

Tested on the local stack: a PDF or HTML file named .png/.jpg is rejected, a JPEG named .png passes when jpg is allowed and fails when only png is, HTML named .tpl passes, unrestricted buckets accept anything. Storage CustomClient e2e passes; CustomServer has the same 3 failures as main locally (preview cache, bucket prefix delete, maintenance docker socket).

@luxor-code-review

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

Copy link
Copy Markdown

Review complete. No issues found.


This PR introduces an extension-vs-content check on file upload: a new signatures map in the storage-formats config lists the MIME sniffs each signed extension may produce, and Files\Create now deletes and rejects uploads (422 STORAGE_FILE_TYPE_UNSUPPORTED) when a file named with a signed extension sniffs to a MIME type outside that extension's signature list (with documented exemptions for ambiguous container formats like application/zip and application/octet-stream).

Files Change
app/config/storage/formats.php Adds a signatures map keyed by extension, plus a comment explaining the ambiguous exemptions for container formats.
src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Create.php After extension validation, sniffs the uploaded file and rejects/deletes it when the sniffed MIME does not match the signature list of signed allowed extensions.

All reviewers converged that the core enforcement logic is sound: the check is skipped correctly when allowedFileExtensions is empty, extension matching is case-insensitive end-to-end, and cleanup on rejection matches the existing deletion pattern. Adjacent-path gaps were noted below the reporting threshold (S3-gateway uploads and file renames do not re-run the new signature check, and a legitimately sniffed image/heif AVIF could be rejected), as was the documented tradeoff that application/octet-stream sniffs bypass the check; none rose to a publishable finding.

Reviewed commit: 9ec433f

@appwrite

appwrite Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

This adds fixed-signature MIME mappings for supported image and PDF extensions and validates completed uploads in restricted buckets against the formats allowed by their extensions. Disallowed content is removed and returns storage_file_type_unsupported, while ambiguous and unsigned formats retain the existing name-only behavior. An end-to-end regression test covers an allowed JPEG uploaded under a .png name and a PDF masquerading as .png, including verifying the rejected file is absent.

Latest changes: The newest commit adds a Storage CustomServer E2E case for accepted alternate image signatures and rejection plus cleanup of a PDF uploaded as a PNG.

Verdict New comments Fixed Still open
✅ Approved 0 1 0
📂 Walkthrough · 3
File Change
app/config/storage/formats.php Defines MIME signature mappings for supported image and PDF extensions and documents ambiguous formats.
src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Create.php Checks sniffed MIME type against allowed signed formats after upload completion and removes rejected files.
tests/e2e/Services/Storage/StorageCustomServerTest.php Adds API coverage for permitted JPEG content under a PNG name and rejection/removal of PDF content under a PNG name.
✅ Fixed since the last review · 1
  • Add an E2E test for signature mismatch rejection · src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Create.php:509

Reviewed the commits since 8efc107 · 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 A · Looks good to merge. Summary

@github-actions

github-actions Bot commented Nov 10, 2026 •

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.

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix-storage-file-type-content (after).

Metric Before After Change
🚀 Requests/sec 194.2 201.23 ⚪ +3.6%
⏱️ Latency P50 86.76 ms 87.14 ms ⚪ +0.4%
⏱️ Latency P95 215.42 ms 200.5 ms 🟢 -6.9%
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 87.14 200.5 12,540 201.23 -14.92
Account 162.4 303.7 660 11.27 -8.35
TablesDB 83.92 150.72 6,820 111.88 -19.81
Storage 82.21 191.32 3,300 55.82 +8.95
Functions 118.77 229.01 1,760 30.65 -24.89

Top API waits (after)

API request Max wait (ms)
account.name.update 416.78
account.prefs.update 415.74
storage.buckets.create 376.59
functions.variables.update 367.7
functions.create 354.06

@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

@HarshMN2345
HarshMN2345 merged commit 18921fa into main Nov 10, 2026
68 checks passed
ChiragAgg5k pushed a commit that referenced this pull request Nov 12, 2026
fix(storage): reject uploads whose content is not an allowed format

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