Repository navigation
fix(storage): reject uploads whose content is not an allowed format - #15458
Conversation
|
Review complete. No issues found. This PR introduces an extension-vs-content check on file upload: a new
All reviewers converged that the core enforcement logic is sound: the check is skipped correctly when Reviewed commit: 9ec433f |
🟢 Tier S · Ready to mergeThis 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 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.
📂 Walkthrough · 3
✅ Fixed since the last review · 1
Reviewed the commits since |
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)
|
fix(storage): reject uploads whose content is not an allowed format (cherry picked from commit 18921fa)
Buckets with
allowedFileExtensionsonly checked the filename, so a PDF or HTML page renamed to.pngwas 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.phpundersignatures). The content must sniff as one of the formats the bucket allows, so a JPEG named.pngstill passes in a bucket that allowsjpg. Ambiguous sniffs (zip, octet-stream) and extensions without a signature keep the name-only check. A rejected upload is removed and returnsstorage_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/.jpgis rejected, a JPEG named.pngpasses whenjpgis allowed and fails when onlypngis, HTML named.tplpasses, 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).