Secure Browser Image Uploads with CORS and Retention

Zusammenfassung

Pixel’s announcement explains a three-layer design for direct browser uploads: short-lived upload grants, tenant-owned object records, and separately expiring export snapshots. It highlights why CORS alone cannot authorize access or define retention, and how an application object ledger helps manage deletion across originals, replacements, thumbnails, and exports.

DEV Community

Direct Browser Image Uploads Need CORS and Retention Boundaries (3 Layers)

Direct browser uploads look like a storage selection problem. For a B2B SaaS product catalog, they are mostly a retention and deletion problem with a CORS check at the front door. The durable design is three layers: a short-lived upload grant, an object record owned by one tenant, and an export job that creates a separately expiring snapshot. TL;DR: Compare CORS support only after writing down who may upload, who may read an export, and when each object becomes deletable. Amazon S3, Cloudflare R2, and Wasabi expose different control planes and billing models, but none of them can infer a tenant's retention policy from a browser request. Put that policy in your application database, then make storage configuration enforce the same boundary. The constraint is deletion, not the upload button Imagine a SaaS workspace that uploads product images from the browser. A user can add a 4 MB JPEG today, replace it tomorrow, and request a tenant-scoped export next week. The original upload, the replacement, thumbnails, failed processing objects, and the export archive do not naturally share one lifetime. Treating them as a single folder creates an uncomfortable question: which object is safe to delete? I start with an object ledger. It records the tenant identifier, object key, media type, byte count, creation time, retention deadline, deletion state, and the export jobs that reference the object. The server generates the key and includes an opaque tenant scope, for example tenant/7f3c/assets/2026/10/28/9a...; a browser never chooses the tenant prefix. The exact key shape is less important than making cross-tenant reads hard to express and easy to audit. A CORS rule answers a browser question: may this origin read a response from this storage endpoint? It does not authenticate a tenant, authorize an object key, or decide whether an old image may be erased. Those decisions belong to the application and its records. The browser is only one participant. The worker, database, and deletion log must agree on the same object identity, or a clean-looking upload flow can leave data behind. This separation also handles a common trap. A successful upload response proves that bytes arrived. It does not prove that the object belongs in the catalog, passed validation, or is still needed. I keep an upload in pending until a server-side finalize step checks the grant, records the object, and queues image processing. Unclaimed pending objects get a short cleanup deadline. Small boundary. Big difference. What does a tenant-scoped export actually require? An export is a read model, not a recursive listing of a tenant prefix. The export worker reads the ledger, selects records whose tenant ID matches the authenticated request, verifies their retention state, and writes an archive under a separate export namespace. The requester's authorization is checked before the job is created and again when the job starts. A copied job identifier must not become a second authorization mechanism. The archive gets its own expiry. This matters when a customer downloads an export twice over several days: extending the archive's lifetime must not silently extend the lifetime of every source image. Conversely, deleting a source image should not corrupt an export that was already promised to the customer; the product must state which guarantee it makes and record that decision. A useful state model is deliberately boring: from dataclasses import dataclass
from datetime import datetime
from enum import Enum

class ObjectState(Enum):
PENDING = "pending"
ACTIVE = "active"
DELETE_REQUESTED = "delete_requested"
DELETED = "deleted"

@dataclass
class Asset:
tenant_id: str
object_key: str
state: ObjectState
retain_until: datetime

def may_include_in_export(asset: Asset, tenant_id: str, now: datetime) -> bool:
return (
asset.tenant_id == tenant_id
and asset.state is ObjectState.ACTIVE
and asset.retain_until >= now
)
...
Secure Browser Image Uploads with CORS and Retention
Powered by Readybot.io

Das Neueste von Pixel

Incident Response: Look Beyond the Red Alert

Pixel’s DEV Community announcement explores how teams can fixate on one failing service while overlooking the real cause of an outage, such as a full …

Sach: AI Fact-Checks WhatsApp Forwards in India

Pixel’s announcement introduces Sach, a tool that checks forwarded messages in English, Hindi, Telugu, and 14 other Indian languages against official sources. It gives cited …

Java 25 Removes SecurityManager: What to Fix

Pixel’s announcement explains how Java 24’s JEP 486 permanently disabled the SecurityManager, breaking test workarounds that intercept System.exit. It recommends returning exit codes or throwing …