Dev.to Security πŸ” Cybersecurity πŸ‘ 0 πŸ“– 8 min read

Cloud Storage CORS Support: Direct Browser Uploads with Tenant-Isolated Snapshot Restore

The constraint that changes this storage decision is tenant isolation. A browser upload can be CORS-correct and still be unsafe if a restore request lets tenant A address tenant B's snapshot. For a developer tool that ke

The constraint that changes this storage decision is tenant isolation. A browser upload can be CORS-correct and still be unsafe if a restore request lets tenant A address tenant B's snapshot. For a developer tool that keeps per-tenant backups, I would make the tenant boundary part of the object key, the authorization check, the restore transaction, and the audit record. The storage bill is a later input.

The boundary is the product.

This is where the design earns its complexity. Suppose tenant t_482 asks to restore s_20261030-017 while a worker is already processing a request for t_731; the object names may be valid, the signatures may both be unexpired, and the storage API may return success for either key. The application still has to load the catalog row under the caller's tenant, verify the complete state, reserve the destination version, and record the decision before a byte changes the project. If the worker retries after a timeout, it should find the recorded idempotency result instead of applying the snapshot a second time. If the object exists but its catalog row is gone, the worker should preserve the evidence for reconciliation rather than infer that the object is restorable. This is more code than β€œupload to a prefix,” but the extra code is the part that makes a tenant boundary reviewable.

Check the negative path.

Short answer: choose the storage service whose CORS, object authorization, deletion, and egress behavior you can express as enforceable invariants. Cloudflare R2, Amazon S3, and Wasabi can all be evaluated for direct browser uploads, but none of them supplies tenant isolation merely because the browser received a signed URL. The application must bind every upload and restore to an authenticated tenant and a server-issued snapshot identifier.

What must a restore prove before it reads anything?

A restore is a read with consequences. It can replace configuration, regenerate credentials, or put a project back into an older state, so the permission check cannot be β€œdoes this object exist?” It must prove that the caller owns the tenant, that the snapshot belongs to that tenant, that the snapshot is complete, and that the requested destination is allowed.

I use a logical record before I issue an upload URL. It contains a tenant ID, snapshot ID, expected object key, state, checksum policy, creation time, and retention decision. The browser receives permission for one object and one method for a short interval. It does not receive a bucket-wide credential, and it does not choose the tenant segment of the key.

A useful key is boring: tenants/t_482/snapshots/s_20261030-017/manifest.json. A stable prefix makes policy review and incident queries possible; a random name alone makes it harder to see whether an authorization rule has crossed a boundary. The object key is still not an authorization decision. The database row and the authenticated request are.

The restore path should load the snapshot row using both identifiers, then verify its state in one transaction before producing a read URL or streaming the object through the backend. A missing row and an unauthorized row should not become distinguishable object-existence probes. The audit trail should retain the internal reason, actor, tenant, snapshot, and result.

That is the exactly-once mindset applied to storage. A restore command may be retried by a client, a queue, or an operator. Give it an idempotency key, record the command outcome, and make the side effect conditional on the snapshot version. A signed download URL can be replayed within its lifetime; the restore command must still enforce the application-level rule.

Why is CORS only the browser half of the boundary?

CORS controls which browser origins may read a response and which cross-origin requests the browser will expose to page JavaScript. It does not establish tenant identity, encrypt a key into a policy, or stop a server-side caller that already has credentials. Treating an Access-Control-Allow-Origin response as an authorization feature is a category error.

For direct upload, the browser normally needs an allowed origin, the intended method, and the headers required by the upload protocol. A preflight failure is visible and annoying. A policy that is too broad is quieter: it can remain unnoticed until a different tenant, staging origin, or compromised page obtains a usable upload capability.

Keep the CORS rule narrow enough to name the real application origins. Avoid a wildcard when the browser needs credentials or when the operation exposes tenant data. Expose only response headers that the client actually consumes, such as a checksum or an operation identifier. The storage service should receive a server-generated object key and a content constraint; the client should not be trusted to declare that tenant_id=t_482 is true.

Here is the application-side shape I want to see before a Go handler signs anything.

type Snapshot struct {
\tTenantID  string
\tID        string
\tObjectKey string
\tState     string
\tVersion   int64
}

func authorizeRestore(ctx context.Context, callerTenant, snapshotID string) (Snapshot, error) {
\tsnapshot, err := snapshots.Find(ctx, snapshotID)
\tif err != nil {
\t\treturn Snapshot{}, err
\t}
\tif snapshot.TenantID != callerTenant || snapshot.State != "complete" {
\t\treturn Snapshot{}, ErrNotFound
\t}
\treturn snapshot, nil
}

In real code, the repository query should also include the tenant ID: WHERE tenant_id = ? AND snapshot_id = ?. The comparison above is a second defense. The restore worker must repeat the check after dequeuing the job, because authorization at enqueue time does not prove that a later operation still has permission.

Which cloud storage supports CORS for a direct browser restore?

The relevant comparison is not a single storage rate. It is the shape of the control plane around an object: how CORS is declared, how temporary access is authorized, how lifecycle rules are expressed, how failures are observed, and how much application code must carry the tenant policy. Cloudflare R2 documents an S3-compatible API and CORS configuration, Amazon S3 documents bucket CORS rules and presigned access patterns, and Wasabi documents S3-compatible storage with its own service limits and policy surface. Compatibility reduces adapter work; it does not make operational behavior identical.

For this scenario, I would record these questions in a decision sheet:

Boundary to test What to verify before adoption Why it matters for tenant backups
Browser upload Exact origins, methods, and request headers A permissive rule can turn a signed capability into an unintended browser action
Object authorization Whether signing binds method, key, expiry, and required headers A restore URL must not become a reusable tenant credential
Lifecycle Whether incomplete uploads, old snapshots, and deletion markers are separate Retention is part of isolation when deleted data remains recoverable
Observability Request IDs, audit events, access logs, and failure classifications Reconciliation needs evidence, not just a client error
Exit path Tested listing, checksum, metadata, and restore procedure GDPR Article 20 makes portability a user right in applicable cases

The three products belong in the same test harness only at the protocol boundary. Run the same upload and restore scenarios against each adapter, then inspect the provider-specific CORS result, metadata behavior, failed preflight, expired signature, partial upload, and delete response. Do not infer equivalence from a successful 1 MB upload.

The trade-off is concrete: a compatibility layer can shorten adapter work, while provider-specific controls may offer a better operational fit but require more policy tests. Neither choice removes the need for an application catalog, and neither should be selected from storage bytes alone.

The test dataset should include two tenants, two snapshots per tenant, a missing snapshot, an incomplete upload, and a snapshot whose object exists while its database row is marked deleted. That last case catches a common split-brain mistake: treating object storage as the source of truth for authorization. It is not.

What does β€œcheap” mean after the first successful upload?

For direct browser upload, the obvious calculation is stored bytes. A serious calculation includes request volume, retrieval, data transfer, incomplete multipart uploads, replication or backup policy, lifecycle transitions, support work, and the cost of reconstructing a tenant's history after accidental deletion. Rates and service terms change; a static β€œcheapest” label has a short half-life.

The more durable question is which cost the team can measure and bound. A storage option that makes restore verification, egress forecasting, or audit collection opaque can move the cost into incident response. A familiar API can still be expensive if the application repeatedly proxies large objects instead of sending the browser directly to a scoped endpoint.

Instrument bytes uploaded, bytes restored, restore duration, failed preflights, signature failures, orphaned objects, and the age of the oldest incomplete upload. Keep metrics partitioned by tenant class, not by raw tenant name in a high-cardinality label. Put tenant and snapshot identifiers in structured logs with access controls, and keep the immutable audit event separate from the mutable snapshot row.

Reconciliation is the quiet requirement. On a schedule, compare expected complete snapshot records with object metadata, but do not β€œrepair” a mismatch by guessing. An object without a live record may be quarantine material; a record without an object may require a failed restore state and an operator decision. Every automatic action should be idempotent and visible.

A controlled rollout for the restore boundary

Start with one non-production tenant and a fixture set containing duplicate uploads, expired upload permissions, a browser-origin mismatch, a cross-tenant restore attempt, and a retry after the restore worker has acknowledged the command. Assert both the user-visible result and the audit event. A green upload test is insufficient if a negative restore test is absent.

Then enable shadow reconciliation. It reads metadata and compares it with the snapshot catalog without changing objects. Measure how many orphaned or incomplete records appear before deciding on lifecycle automation. β€œDelete” may mean removing the catalog record, marking a snapshot unavailable, scheduling object deletion, or removing every derived artifact. Give each meaning a named state.

For production, use a feature flag at the tenant boundary, keep the old restore path available for a short, bounded transition, and write a migration manifest containing tenant ID, snapshot ID, source key, destination key, checksum, and final state. Never migrate by copying a bucket and declaring success. A copy without a tenant-level restore test is only duplicated uncertainty.

The decision rule is straightforward: select the option that lets your team demonstrate, with logs and repeatable tests, that a browser can upload only the intended object and that a caller can restore only a complete snapshot belonging to its tenant. R2, S3, and Wasabi may each fit a different transfer or operations profile. The invariant does not change with the provider.

Sources

πŸ“° Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.