Product Security
Secure uploads from mobile and web to object storage
A complete thinking model for file validation, durable storage and accessible media delivery.
Williams Madu · · 14 min read
A file upload is a security boundary and an editorial workflow, not merely an input field. Design for MIME validation, storage permissions, retry safety, image metadata and CDN delivery.
An upload crosses multiple trust boundaries
The browser can tell the server what a file is called and what MIME type it claims, but neither statement is authoritative. Accepting those values without checking file bytes, size limits and authorization creates a route for malicious content and costly storage abuse.
Separate the short-lived permission to upload from the long-lived permission to view or delete the object. An anonymous reader of a published article should not receive the ability to overwrite its original image.
- Verify authentication and per-user or per-role authorization.
- Enforce size and permitted content types on the server.
- Inspect content signatures and reject dangerous file formats.
- Generate storage keys without trusting user-provided paths.
- Scan suspicious content when threat and product requirements warrant it.
Choose the right transfer architecture
Small uploads can pass through an application server, but larger files often benefit from controlled direct-to-storage transfer. In that model, the API issues a short-lived upload grant, the client sends bytes to object storage, and the API confirms and records the resulting media object.
A signed upload grant must not become a blanket bucket permission. Restrict the key prefix, content type, expiration and size where the provider supports it. Always confirm object ownership and integrity before publishing a media record.
- Create a pending media record linked to the authorized editor.
- Issue a narrowly scoped upload grant.
- Send the file with progress and cancellation support.
- Confirm the stored object and validate metadata on the server.
- Move the record from pending to ready only after successful checks.
Plan for the network to disappear
Mobile networks fail between bytes, during confirmation or immediately after storage succeeds. The UI must not create duplicate objects every time the user taps retry. Resumable or multipart uploads can help where provider capabilities and size justify the complexity.
Give each attempt a durable client-visible operation ID. Preserve the draft article while uploads retry, and distinguish pending media from ready media. The article should never reference an object that has not passed validation.
- Use explicit idle, uploading, confirming, ready and failed states.
- Provide safe retry and cancel actions.
- Clean up abandoned pending objects using a scheduled policy.
- Log errors with a reference the operator can locate.
type UploadState =
| { status: 'idle' }
| { status: 'uploading'; progress: number; operationId: string }
| { status: 'confirming'; operationId: string }
| { status: 'ready'; mediaId: string; url: string }
| { status: 'error'; message: string; canRetry: boolean }
// Persist the draft while storage transfer is in progress.An explicit state machine prevents a failed transfer from silently producing a published broken image.
Image metadata is part of accessibility
Every editorial image needs alternative text that communicates meaning without repeating nearby copy. Decorative artwork can use an empty alt, but an architecture diagram or screenshot should have a useful description and often a caption.
Record natural dimensions and use responsive variants to avoid downloading a massive original image for a small card. Prefer immutable CDN URLs or versioned storage keys for predictable caching.
A real image is not production-ready until its storage, accessibility, delivery and failure behavior are also designed.
Separate development data from production media
Local tests should not accidentally pollute permanent production storage. Use a separate environment, a clearly scoped test prefix, or stable externally hosted editorial examples. Do not seed production media merely because a local development server started.
If an application uses Vercel Blob or a similar object store, keep credentials on the server and treat public read URLs differently from write tokens. Ensure that deletion policies and storage costs are understood before publishing large galleries.
Further reading and references:
Test the complete lifecycle
Acceptance includes a successful image, an oversized file, a disguised file type, an interrupted transfer, a duplicate confirmation, an unauthorized deletion and a broken delivery URL. Test each condition from the browser and from a direct API client.
Verify that thumbnail, banner and gallery variants render on a narrow device without layout shift. Confirm that the article remains readable when the CDN returns an error. Storage correctness and visual polish are both part of the same feature.
- Upload a valid JPEG or PNG with meaningful alt text.
- Attempt an invalid MIME type and an oversized file.
- Simulate an interrupted upload and use the intended recovery action.
- Publish an article and verify the public URL has no write permission.
- Check mobile rendering, caching behavior and deletion controls.