Safe File Uploads: Limits, Type Checks and a Clear Quarantine Boundary
A filename and browser MIME type do not establish what a file contains. Validate uploads, isolate processing and publish only approved files without making the visitor guess what went wrong.

A file input with accept="image/*" helps the picker show relevant files. It does not prove the uploaded content is an image. The browser can send a different file, a misleading MIME type or a filename designed to cause trouble later.
Upload design has two audiences: the visitor who needs a reliable interaction and the service that must process untrusted bytes safely. A good implementation handles both without pretending one client-side check covers the entire path.
Define a narrow contract
List allowed formats, maximum size, number of files and the processing outcome. If the task is to upload a profile photo, accepting arbitrary archives and documents creates unnecessary risk.
Show clear limits before selection and enforce them server-side. Client checks save time but can be bypassed. Include limits at the reverse proxy or storage boundary so an oversized request does not consume unbounded resources before validation starts.
Use stable units and explain whether the size applies before or after processing. An image can be small on disk but expand into a huge pixel buffer during decoding.
Validate content, not labels
Check file signatures with maintained tools and verify that the file can be decoded or parsed as the expected format. Neither the extension nor the client-provided content type is authoritative.
For images, constrain dimensions and total decoded pixels. For documents, use a maintained parser in a restricted environment. Archives need limits on expansion, entry counts and nesting, or they should simply be rejected if the product does not require them.
A file matching a signature can still be malicious or malformed. Type detection is one layer, not a security verdict. Apply malware scanning and additional policy checks where the workflow warrants them.
Keep uploads out of public serving
Receive the file into private staging or quarantine storage. Assign a server-generated identifier rather than using the submitted filename as a filesystem path. Keep the original name only as sanitised display metadata if needed.
Do not publish the object while scanning or conversion is pending. A signed upload URL should be constrained to the intended object and appropriate expiry, and the completion step must verify what actually arrived.
If users can upload directly to storage, your application still needs to inspect and authorise the object before marking it ready. A successful storage response is not approval for public display.
Isolate processing
- Receive — Size and authentication limits
- Identify — Allowed type and parseability
- Process — Restricted worker and resource limits
- Approve — Scan and policy outcome
- Serve — Authorised access with safe response headers
Conversion workers should not have broad network access or credentials unrelated to processing. Treat parser updates as security maintenance. Timeout a stuck job and keep a recoverable record rather than leaving the interface spinning indefinitely.
For images, re-encoding can remove unwanted metadata and normalise output, but it is not a universal guarantee against every decoder vulnerability. The decoder itself remains part of the attack surface.
Serve deliberately
Use the intended content type and appropriate Content-Disposition. User-supplied HTML or SVG can execute active content when served in the wrong context. If those formats are not required, reject them; if they are required, use a reviewed sanitisation and isolation strategy.
A separate untrusted-content origin can reduce some risks, but origin isolation requires careful cookie, header and embedding decisions. Do not assume a different path under the same site creates an equivalent boundary.
Enforce ownership on downloads. A random object identifier is not authorization. Avoid exposing private documents through permanent public URLs merely because the upload interface is behind login.
Give the visitor truthful states
Distinguish selected, uploading, processing, ready and rejected. Browser transfer progress is not conversion progress. If upload finished but scanning continues, say so.
Allow retry after a network error without creating duplicate application records. Keep a stable upload or job identity where appropriate. Offer cancellation honestly: bytes or processing already accepted may need separate cleanup.
Preserve valid selections when one file fails, and explain the specific permitted issue without returning raw parser exceptions. "The image exceeds the supported dimensions" is more useful and safer than a stack trace.
Test hostile and inconvenient inputs
Try an extension mismatch, truncated file, oversized dimensions, unsupported format, duplicate submission and an interrupted upload. Test a scan rejection and a worker timeout. Verify no quarantined object is publicly retrievable.
Check keyboard access and file selection on mobile. Do not require drag-and-drop as the only route. Make status announcements concise and associate validation messages with the upload control.
Clean up the lifecycle
Expire abandoned staging objects and define retention for rejected files. Keep audit metadata without unnecessarily retaining raw sensitive content. Ensure deleting an application record also schedules the associated storage cleanup when appropriate.
A safe upload system is a lifecycle, not a picker. It receives untrusted content, proves enough about it for the intended use and serves it only after the correct decision. The interface should make that lifecycle understandable rather than hiding it behind a single percentage.
Paj Digital Labs
The engineering journal of Paj Digital Solutions — hosting, server infrastructure and web engineering, written by the people who run the servers.
Related reading

International Websites: Locale URLs, Hreflang and Formatting Without Guesswork
Language, country and formatting are related but different choices. Give translated pages stable URLs, preserve user selection and keep search signals aligned with real equivalents.

Progressive Enhancement for Article Sites: The Page Should Outlive Its Scripts
Core reading and navigation should remain available when hydration or a third-party script fails. Start with useful HTML and layer interactions without turning every link into an application dependency.

Website Search That Finds Answers: Ranking, Typos and Empty Results
Search quality depends on the documents and ranking rules, not the size of the input box. Index useful fields, handle imperfect queries and give readers a way forward when nothing matches.