Private File Upload Cost and Security: Direct Storage or Proxy Backend (A Control Test)
Short answer: choosing between a presigned URL and a proxy upload backend for private B2B SaaS files turns on whether policy permits bytes to enter an isolated storage area before inspection; when it does, direct upload
Short answer: choosing between a presigned URL and a proxy upload backend for private B2B SaaS files turns on whether policy permits bytes to enter an isolated storage area before inspection; when it does, direct upload can separate delivery from backend authorization, while a pre-storage inspection requirement places the byte stream in the proxy.
That split is the least complex design that keeps large request bodies away from ordinary application workers without surrendering access control. The signed URL is a temporary capability, not proof that an upload belongs in the product. A file becomes downloadable only after the backend reconciles the stored object with the upload intent, applies the required checks, and records a committed state. Private downloads follow the same principle: authorize in the application, then issue an expiring read capability for one object.
The hard part isn't moving bytes. It's preserving an auditable state transition when browsers retry, tabs close, callbacks arrive twice, and an authorized user tries to turn a valid capability into access beyond its intended object.
How should a beginner balance web app file upload cost, latency, and security?
Start by separating the control plane from the data plane. The control plane answers who may upload, into which tenant boundary, under which policy, and for how long. The data plane carries the file. A direct-to-storage design keeps those decisions in the backend even though the backend doesn't relay the body; a proxy design combines both planes in one request path.
For a concrete SaaS example, suppose an organization member attaches a private evidence file to a case. The browser first asks the application for an upload intent. The application authenticates the member, verifies access to the case, chooses an opaque object key, records the expected media type and size ceiling, and returns a capability that expires after a deliberately short interval. The browser uploads to a quarantine namespace, then asks the application to commit the intent. Commit does not trust the browser's claim: it reads authoritative object metadata, compares that metadata with the intent, runs whatever content checks the organization's policy requires, and changes the database row from pending to ready. Only ready objects can receive expiring download links.
One rule matters more than the transport choice: an object key must come from the server, never from a browser-supplied tenant path. A user-visible filename belongs in metadata after normalization; it is not an authorization boundary. A random key also prevents accidental overwrite and makes one intent correspond to one candidate object. Keep the storage namespace private, deny public reads, and treat every signed link as a bearer secret until it expires.
Keep that boundary explicit.
Direct upload usually removes an application network hop and avoids tying worker capacity to body size. It can also change the cost surface because the application no longer receives and retransmits every byte. Those are architectural effects, not universal savings: storage requests, egress location, scanning, abandoned objects, retries, and observability still consume resources, while the exact bill depends on the deployment and provider. Measure from the user's region with realistic file sizes.
The proxy path is easier to reason about when regulation or internal policy says rejected content must never land in object storage, even in an isolated namespace. It can enforce a streaming size limit, calculate a digest, transform content, and make a single application response represent acceptance. The catch is that the proxy now owns backpressure, request duration, retry amplification, temporary disk or memory pressure, regional bandwidth, and capacity during a burst. It also creates a second large-body hop unless the proxy and storage placement make that hop local.
There is no universally safer path. Direct upload narrows the backend's exposure to untrusted bodies but introduces capability management and an asynchronous commit boundary; proxying centralizes inspection but expands the application data path. Security follows the controls around the path, not the arrow in an architecture diagram.
Make the upload intent the unit of correctness
An upload intent should be durable before a capability is issued. Give it an unguessable identifier, tenant and actor identifiers, an opaque object key, a policy version, expected metadata, an expiration time, and a state. A small state machine is enough: pending, validating, ready, rejected, and expired. State transitions should be conditional, so two commit requests cannot publish the same upload twice.
Exactly once is the objective at the business boundary, not a promise made by HTTP. Browsers retry after ambiguous timeouts, and a successful object write can be followed by a lost response. Make creation idempotent with a client request key scoped to the actor and operation; return the existing intent when that key repeats with the same parameters, and return 409 Conflict when it repeats with different parameters. Make commit idempotent by treating ready as a stable success result. Record each accepted transition in an append-only audit event with the intent ID, actor, prior state, next state, policy version, and correlation ID.
Retries happen.
This is the core contract in Go; the storage implementation may sign a provider request, but the application service owns every authorization decision:
package uploads
import (
"context"
"errors"
"time"
)
type Intent struct {
ID string
TenantID string
ActorID string
ObjectKey string
MediaType string
MaximumBytes int64
PolicyVersion string
ExpiresAt time.Time
State string
}
type ObjectMetadata struct {
Size int64
MediaType string
Digest string
}
type UploadCapability struct {
URL string
Method string
ExpiresAt time.Time
Headers map[string]string
}
type ObjectStore interface {
SignUpload(ctx context.Context, key string, mediaType string, expiresAt time.Time) (UploadCapability, error)
Metadata(ctx context.Context, key string) (ObjectMetadata, error)
Delete(ctx context.Context, key string) error
}
type IntentStore interface {
CreateIdempotent(ctx context.Context, intent Intent, requestKey string) (Intent, error)
Transition(ctx context.Context, id string, from string, to string, metadata ObjectMetadata) error
}
var ErrMetadataMismatch = errors.New("uploaded object does not match intent")
func ValidateMetadata(intent Intent, object ObjectMetadata) error {
if object.Size <= 0 || object.Size > intent.MaximumBytes {
return ErrMetadataMismatch
}
if object.MediaType != intent.MediaType {
return ErrMetadataMismatch
}
return nil
}
The example deliberately leaves signing syntax behind the ObjectStore interface. Providers differ in what a signed request can bind, so the adapter must return the exact method and required headers and the browser must send them unchanged. If the selected signing mechanism cannot enforce a desired size constraint before upload, the quarantine-and-commit check becomes mandatory; lifecycle cleanup then bounds the residue from abandoned or rejected objects. Amazon S3 documents lifecycle rules as a mechanism for expiring objects, and equivalent retention behavior should be verified in the chosen storage system rather than assumed.
Don't use the client-provided MIME type as a content verdict. It is useful as an expected value and as part of a signature when supported, but validation can require content detection, malware scanning, format parsing, or a checksum according to the risk model. I'm not sure which checks your compliance program will accept without its threat model and retention requirements; that decision needs input from security and legal, plus evidence from the actual scanner and storage configuration.
Treat download authorization as a fresh decision
The fact that an actor uploaded an object does not grant indefinite read access. On every download request, resolve the application resource, verify current tenant membership and resource permission, confirm the object is ready, and only then issue a short-lived read capability for that one key. Avoid persisting the signed URL as though it were the file's identity. Persist the object key and authorization relationship; generate a new capability after each successful access decision.
Revocation exposes the main limitation of expiring links: a capability already issued can remain usable until its expiry, unless an intervening control invalidates it. Keep the validity window aligned with the risk of disclosure, avoid putting capabilities into analytics fields or application logs, and set browser-facing responses so intermediaries do not cache private links unexpectedly. For especially sensitive material, a download proxy or an authenticated delivery layer may be appropriate because it can re-evaluate authorization while bytes are served. That choice gives up some delivery simplicity in exchange for tighter real-time control.
Audit issuance separately from successful retrieval. An application can prove that it authorized and generated a link, but it may need storage access logs or delivery-layer telemetry to establish that bytes were actually requested. Correlate those records with a non-secret capability or request identifier β never the full URL β and define retention according to the organization's compliance obligations. Logs themselves contain sensitive behavioral data, so access and deletion policy apply to them too.
Compare paths after defining the controls
Once the state machine, authorization boundary, and evidence requirements are explicit, the transport comparison becomes fairly mechanical.
| Decision pressure | Direct browser-to-storage | Backend proxy |
|---|---|---|
| Application capacity | Carries control requests, not file bodies | Carries control requests and every file body |
| Upload latency | Usually one large-body network leg after intent creation | Browser-to-backend plus backend-to-storage transfer |
| Pre-storage rejection | Limited to constraints supported by the signed mechanism | Can inspect a stream before storage acceptance |
| Authorization | Backend issues a narrow, expiring capability | Backend enforces authorization on the live stream |
| Failure model | Requires reconciliation of intent and object | Requires backpressure and ambiguous retry handling |
| Audit boundary | Combine application transitions with storage evidence | Application sees the stream, but durable transitions still matter |
Choose direct upload when files are large relative to ordinary API requests, the storage service is reachable from supported browsers, quarantine is acceptable, and the team can operate reconciliation and lifecycle cleanup. It is not suitable when policy prohibits unvalidated bytes from reaching storage, clients cannot reach the storage endpoint, or mandatory transformations must happen synchronously before acceptance.
Choose a proxy when inline inspection is non-negotiable, the file must be transformed as it arrives, network policy prevents direct access, or immediate revocation during downloads matters more than delivery simplicity. Stick with a proxy only after setting hard body limits, streaming rather than buffering entire files, propagating cancellation, isolating upload capacity from transaction APIs, and testing slow-client behavior. A hybrid is often coherent: direct upload into quarantine for ordinary attachments, a proxy for exceptional regulated classes, and expiring direct downloads except where per-byte authorization is required.
Cloud interfaces are not interchangeable merely because they all store objects. Amazon S3 and Google Cloud Storage each document object-storage behavior, but signing details, metadata semantics, retention controls, browser configuration, and logging must be checked against the current primary documentation for the selected service. Keep those differences in a thin adapter and test the policy contract above it; don't let provider response fields leak into business authorization.
Roll out with reconciliation before optimization
Begin with one private file class and one size ceiling. Deploy intent creation and audit events first, then direct upload to a quarantine prefix, metadata validation, explicit commit, expiring download authorization, and lifecycle deletion for abandoned objects. Run the proxy path in parallel for the classes that require inline handling rather than forcing one transport onto every policy.
Test the awkward sequence: upload succeeds but commit is never called; commit is called twice; the same idempotency key carries different metadata; authorization is removed after upload but before download; a capability expires during a retry; metadata exceeds the declared ceiling; and cleanup races with a late commit. Each case needs a deterministic state and an audit event. No guesswork.
Operationally, alert on the age and count of pending intents, validation latency, rejection reason, bytes by tenant, repeated idempotency conflicts, cleanup volume, and capability issuance failures. Reconcile database intents against object metadata on a schedule, but make reconciliation use the same conditional transitions as the request path. Only after those invariants hold should the team tune capability duration, concurrency, multipart thresholds, or regional placement using production-shaped tests.
The final decision rule is compact: keep identity and state in the backend; keep bytes out of it unless a documented control requires them there.
Further reading
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.