An upload is not ready for download simply because storage accepted its bytes. The file may have a misleading type, exceed processing limits, contain active content, or change between validation and publication. Keep incoming bytes unavailable until the application has verified the exact object it intends to serve.
This guide covers a server-controlled upload lifecycle from acceptance to retrieval. The synthetic workflow uses quarantine, explicit state transitions, and bounded processing. No single parser, file signature, or malware scan is treated as proof that a file is harmless.
Define the useful formats and their limits
Start with the user task. A profile image feature can accept a narrower set of formats than a document collaboration service. List the formats needed, the maximum uploaded and expanded size, and the transformations the application performs.
OWASP's file upload guidance recommends layered validation and warns that the client-provided Content-Type is not trustworthy. It also treats file-signature checks as one signal rather than a sufficient standalone control.
For a synthetic image feature, bound dimensions, frame count, decode time, and output size in addition to raw bytes. A small compressed input can require substantial processing. Put authoritative limits at the server and processor boundaries even when the interface validates them first.
Give users clear accepted-format and size information before they choose a file. Preserve that convenience while making the server's validation independent. Return a stable rejection reason that helps the user correct the file without exposing parser internals or storage paths.
Store incoming bytes in an unavailable state
Authorize upload creation against the current account and resource. Apply account quotas and request limits before allocating significant storage. Use an application-generated object key rather than allowing an original filename to become a filesystem path or storage authority.
Create a quarantine record that names the object identity, owner, expected purpose, received size, and lifecycle state. Keep the original filename only as bounded display metadata when needed, and encode it for its output context.
In a synthetic state model, an upload moves from receiving to quarantined, then either approved or rejected. Approved objects may later become unavailable because of deletion or a revised safety decision. Enforce these transitions with authoritative conditional writes, not only disabled buttons in the interface.
If direct-to-storage uploads are supported, scope their temporary upload capability to the intended object and enforce completion checks server-side. A successful client callback must not be allowed to declare arbitrary objects approved. Verify the stored size and object version rather than trusting the browser's report.
Validate the exact object that will be published
Bind inspection to an immutable object version or content identity. Do not inspect one upload and then serve a replacement written under the same key. The publication decision should identify the validated version and reject a completion update when that identity has changed.
Run content parsing in a restricted worker appropriate to the format. Bound CPU time, memory, output bytes, and filesystem access. Keep the parser maintained and isolate failures so that a malformed file does not crash the request process.
For a synthetic image workflow, decoding and re-encoding to an approved format can narrow the output surface. Inspect the generated result and record its identity separately from the original. Do not assume that conversion removes every dangerous property for every format.
If malware inspection is part of the policy, define what a scanner timeout, unavailable engine, or unsupported file means. Keep the object quarantined when required verification is incomplete. Sending private documents to a public scanning service introduces a separate disclosure decision that must be authorized and documented.
Publish through an explicit authorization boundary
After validation, mark the exact approved object available through a conditional transition. Use a retrieval path that checks current ownership and access policy. An opaque object key can reduce accidental guessing but is not authorization.
Decide how each format is served. For untrusted downloadable documents, an attachment response and a separate serving origin may reduce interaction with the application's authenticated origin. Configure the verified media type and prevent content sniffing where the serving stack supports that control.
Do not create response headers by inserting the original filename directly. Use maintained header formatting with a safe fallback name and bounded metadata. Protect against control characters and preserve a usable download name through the supported encoding mechanism.
If access is delegated through a time-limited download URL, scope it to the approved object version and keep its lifetime appropriate to the task. Account for revocation expectations: deleting an application permission does not necessarily invalidate an already issued capability immediately.
Make processing failures visible and recoverable
The user interface should distinguish uploading, waiting for inspection, ready, and rejected. Do not show a completed download link while validation is still pending. For long processing, provide a non-blocking status view and a clear retry or replacement action.
Treat retries as lifecycle operations. Repeated completion callbacks should not enqueue unbounded duplicate inspections or consume quota twice. A delayed worker should not approve an object after the user deleted it. Test these races with concurrent requests and conditional transitions.
Clean up abandoned uploads, rejected objects, and expired temporary versions through a bounded job with an explicit retention policy. Avoid deleting objects that still have active ownership or processing claims. Record cleanup outcomes without storing file contents in logs.
Verify both upload and retrieval paths
Use synthetic fixtures for allowed content, mismatched extension and media type, oversized input, excessive expanded size, malformed parsing, scanner failure, and replacement after inspection. Include another account attempting to complete or retrieve the upload.
Check resulting object state and access directly. A rejected upload should remain unavailable through every serving path, including caches and delegated links. A deleted object should follow the documented revocation behavior rather than disappearing only from the user interface.
Apply the API boundary testing guide to these transitions and the safe logging guide to processing errors. The useful release evidence is that only the exact approved version becomes accessible under the current policy, with incomplete verification remaining visible and contained.
Was this guide useful?
Your rating helps us prioritize clearer, more practical technical content.
Review diffs, run checks, and prepare the release in Arezgit.
Keep Git review, security scanning, API checks, database inspection, and release preparation together in one local desktop application.
Explore Arezgit