Blog
Secure File Uploads: Content-Type Is User Input Too
The client controls filename, extension, and Content-Type. Treating any of them as trusted metadata turns an upload endpoint into a filesystem and content-delivery attack surface.
Allow Only What Product Needs
If users upload profile images, accept a narrow image set. Do not maintain a blacklist of everything dangerous; the list loses.
The OWASP File Upload Cheat Sheet recommends extension allowlisting, type validation beyond the spoofable header, generated filenames, size limits, and authorization.
Check file signatures with a maintained parser, then decode and re-encode images when practical. A valid-looking prefix is not proof the remaining bytes are harmless.
Store Outside Executable Paths
Generate an opaque storage key. Keep the original filename only as sanitized display metadata. Store files outside the application web root or behind a separate object-storage download path.
Serve downloads with a safe Content-Disposition and an explicit content type. Do not let an uploaded HTML or SVG file execute under your trusted origin unless that is a deliberately sandboxed feature.
Bound Every Resource
Enforce request size at the edge and application, bound decompression and image dimensions, stream instead of buffering unlimited bodies, and clean abandoned multipart data.
Malware scanning can be asynchronous, but unscanned objects must remain quarantined. “Upload succeeded” and “content is available” are separate states.