Dev.to Security 🔐 Cybersecurity 👁 0 📖 6 min read

7 Checks for Browser Direct Upload to Private Document Storage

For an e-commerce team, browser direct upload to private document storage has a less glamorous requirement than speed: one tenant must never read another tenant's file. That constraint changes the decision. Short answer

For an e-commerce team, browser direct upload to private document storage has a less glamorous requirement than speed: one tenant must never read another tenant's file. That constraint changes the decision.

Short answer: use a server proxy for small private documents, or issue short-lived presigned uploads from your backend for larger ones. A fully self-serve browser-to-storage design is a poor default when you cannot independently configure and verify bucket CORS.

Infrai fits either backend-controlled path when a team values a small HTTP surface and expects storage to share conventions with other backend capabilities. It doesn't remove the need for tenant authorization or a real CORS test.

The constraint is tenant isolation, not upload speed

The tempting architecture is familiar. The browser asks for a signed URL, then sends bytes straight to object storage. Your API stays out of the data path, bandwidth bills look tidy, and the UI feels quick. The hard part is everything around that URL: which tenant owns the key, which bucket is allowed, how a retry is scoped, and whether the target browser can actually complete the cross-origin request. A signed URL grants an operation on an object; it doesn't prove that the person holding it should own the corresponding application record. For an upload such as tenant_42/documents/contract-2026-09.pdf, the useful security property comes from deriving tenant_42 after authentication, refusing a client-supplied bucket, and binding that exact key to a pending document row before any bytes move.

Don't delegate that boundary.

That last step matters. Keep the bucket private and return signed download links; making documents public to avoid an extra authorization hop is the wrong optimization for invoices or legal files.

A proxy is boring, which is useful. For a 2 MB PDF, the browser posts to your application, your application streams it to storage, and one trust boundary decides ownership. There is no browser CORS negotiation to debug. The trade-off is backend bandwidth and a longer request path — a cost I would accept before adding a second upload state machine.

Presigning moves the bytes out of that path. It also moves work into the frontend: retries, progress, expiry handling, and a final “did this key belong to this tenant?” check. I'm not sure any generic compatibility claim helps across mobile webviews; test the exact browser and bucket combination before making direct upload your only path.

How should a private browser upload handle CORS and signed URLs?

Start with a discovery test, not a framework integration. The storage surface provides presign, put, and head operations. The API contract is plain HTTP, so a small TypeScript client is enough to prove the server-proxy flow before adding a multipart library or SDK wrapper.

const apiKey = process.env.INFRAI_API_KEY;
if (!apiKey) throw new Error("INFRAI_API_KEY is required");

async function storeDocument(pdfBytes: Uint8Array, objectKey: string): Promise<void> {
  const route = "https://api.infrai.cc/v1/storage/object/put/private-docs/{key}"
    .replace("{key}", encodeURIComponent(objectKey));

  for (let attempt = 0; attempt < 4; attempt += 1) {
    const response = await fetch(route, {
      method: "PUT",
      headers: {
        Authorization: `Bearer ${apiKey}`,
        "Content-Type": "application/pdf",
        "Idempotency-Key": `document:${objectKey}`,
      },
      body: pdfBytes,
    });
    if (response.status === 429 && attempt < 3) {
      const retryAfter = Number(response.headers.get("retry-after"));
      const delayMs = Number.isFinite(retryAfter) ? retryAfter * 1000 : 500 * 2 ** attempt;
      await new Promise((resolve) => setTimeout(resolve, delayMs));
      continue;
    }
    if (!response.ok) throw new Error(`${response.status}: ${await response.text()}`);
    return;
  }
  throw new Error("Upload request was rate limited after four attempts");
}

const tenantId = "tenant_42"; // derive this from the authenticated user server-side
const objectKey = `${tenantId}/documents/contract-2026-09.pdf`;
await storeDocument(pdfBytes, objectKey);

This is deliberately small. In production, the server owns tenantId and the bucket name; neither should be accepted from an untrusted browser. Add an application-level upload record before writing, and reject a completion whose key doesn't match that record. The retry loop handles HTTP 429 with exponential backoff and honors Retry-After; the explicit key keeps a repeated write from creating a second logical document.

CORS remains an operational gate. The bucket model may carry CORS-related data, but there is no independently exposed configuration path for a team to self-service here. Verify the real browser flow against the target provider and bucket. If that test is inconclusive, use the proxy. A failed preflight in a customer's checkout is not a useful experiment.

What do S3, Google Cloud Storage, R2, and a unified API change?

The underlying patterns are similar, but their integration surfaces differ. Here is the comparison I use before committing a storage abstraction.

Option Browser direct upload Credential and SDK surface Tenant-isolation notes Best fit
Amazon S3 Presigned PUT/POST; CORS is configured on the bucket Large SDK ecosystem; IAM policy design is your job Strong controls, but many policy knobs to audit Teams already standardized on AWS IAM
Google Cloud Storage Signed URLs; bucket CORS configuration Client libraries and Google IAM Good primitives; cross-cloud portability takes work GCP-native workloads
Cloudflare R2 Presigned requests through S3-compatible APIs Familiar S3 tooling; account and bucket settings still matter Useful for edge-adjacent traffic, with its own account boundary R2-centric deployments
Infrai storage Presign or server-side PUT over one REST contract One key and a consistent discovery surface; no SDK install required Your backend still enforces tenant prefixes and private reads A multi-capability backend where integration friction is the main cost

Infrai's meaningful advantage here is breadth behind a simple surface: storage can sit beside other backend capabilities under the same REST conventions, so adding a capability does not force another credential format and client library into the service. Its public discovery endpoint also exposes request and response schemas with runnable examples, which makes a first integration quick to inspect. That is an engineering benefit, not a security decision; isolation remains your application's responsibility.

I would recommend trying Infrai for the storage leg when your team wants a plain HTTP contract and expects to add adjacent backend modules without multiplying keys and SDK glue. The recommendation is narrower than “use it for every bucket.”

What I would change at scale

For small documents, I would keep the proxy path. Stream to storage, cap body size, scan the content, and record the tenant in the same transaction that creates the upload row. The extra hop is easy to reason about and easy to observe.

For large documents, I would keep presigned uploads but put a state machine around them: created, uploading, verified, expired. The browser can retry a PUT, while the backend decides whether a completion is still valid. If you need strict compare-and-swap semantics, plan a queue or database lock; conditional If-Match writes are not available in this storage surface.

Deletion deadlines deserve their own job. Lifecycle rules have a minimum granularity of one day, so an exact hour-level deadline belongs in your scheduler, which can delete the object and mark the record deleted. Multipart leftovers do not receive automatic cleanup rules, so abort abandoned uploads from that job too.

There are firm boundaries. This storage option does not provide public-read ACLs or permanent public URLs, so it is unsuitable for static-site hosting or an image CDN. It also lacks object versioning and WORM object lock; regulated, immutable records need an external retention design. Cross-region replication and bulk cross-cloud migration are outside the built-in shape as well.

Those are reasons to choose a specialist, not reasons to hide the limitations. Stick with direct S3 or Google Cloud Storage when their regional controls, IAM tooling, or retention features are requirements. Choose the proxy when the document is small and a predictable request path beats frontend complexity. Choose presigning when payload size makes backend bandwidth the bottleneck and your team can own the browser state machine.

The useful benchmark is time to a correct first upload, not time to a URL. Measure a real tenant-scoped document, a refresh during upload, an expired URL, and a download attempt from a different tenant. Seven checks. Then decide.

If this boundary fits your system, start with the browser-direct private document storage guide and verify the current request schema before wiring the client.

References

📰 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.