Web App Report Upload Control: Presigned URLs or Proxy Backend (An SRE Runbook)
Short answer: Use a presigned URL for browser upload when the backend can authorize the object before receipt and verify it before publication; use a proxy backend when security policy requires synchronous inspection of every byte.
Keep upload and delivery separate. A successful object write is not proof that the report is safe, complete, or owned by the current tenant. The customer-facing download path should consult application metadata and issue a separate, short-lived read capability only after the object has passed validation.
That is the operational recommendation. The rest is the runbook.
How should a beginner choose a presigned URL or proxy backend for web app file upload?
Choose by asking where byte-level enforcement must happen, not by starting with cost or latency. A presigned URL makes the browser send the report directly to object storage; the backend remains the control plane. A proxy makes the backend both control plane and data plane, so it can inspect the stream before accepting it but must also absorb upload bandwidth, connection duration, buffering pressure, and retry behavior.
For a developer tool that creates a report in the browser and later serves it to authenticated customers, direct-to-storage is the usual baseline when four conditions hold:
- the backend can generate an unguessable object key,
- the upload capability is narrow and short-lived,
- the object remains unpublished until server-side verification finishes,
- and content scanning can happen after receipt.
The catch is that this is not suitable when regulation or internal policy forbids uninspected bytes from entering the storage boundary. In that case, stick with a proxy or a dedicated inspection service in the data path.
A proxy is also reasonable for small reports when one request-response transaction is more valuable than reducing backend load. It gives the application immediate control over content parsing and rejection. It also concentrates failure: a slow client now occupies application capacity, and an application deployment can interrupt in-flight transfers. Presigned upload moves that failure domain away from the API fleet, but it introduces a two-step workflow that must be modeled explicitly.
Don't treat the signed URL as authentication for the customer-facing report. It is a bearer capability. Anyone who obtains it can exercise the permissions encoded in it until it expires, subject to the storage service's validation rules. The application still needs its own authorization check before issuing that capability, and it must bind the resulting object to the tenant and report record it selected.
Make publication a state transition, not an upload side effect
Use a small state machine: pending, verifying, ready, and rejected. Create the database row first, with the authenticated tenant ID and a server-generated object key such as tenants/<tenant-id>/reports/<report-id>/source. Then issue permission to write only that key. The browser never supplies a final bucket name, tenant prefix, or public ACL.
The important invariant is blunt: only ready reports can be delivered.
After the browser uploads, it calls a completion endpoint with the report ID, not an arbitrary object key. The backend reads object metadata from storage, checks the expected size and media type, and moves the record to verifying. A scanner or parser can then validate the contents. Publication changes the database state to ready; it does not make the storage container public. Downloads start with a normal authenticated request, an ownership check against the report row, and either a short-lived read URL or a controlled response stream.
This ordering closes a common authorization gap: if the client can declare both the object key and the tenant association after upload, it may point a report row at an object it does not own. If a storage event alone marks the report ready, an incomplete multipart upload, an unexpected media type, or an object written through another authorized path can bypass the application decision. Storage events are useful signals, but the application record remains the authority for customer access.
CORS is narrower than access control. Browser CORS policy decides which origins may read a response; it doesn't replace authorization, constrain what a leaked bearer URL can do outside a browser, or validate report contents. Configure only the required origin, methods, and headers, but keep the tenant check in the backend.
The cost model follows the byte path
With a proxy, the same upload bytes enter the application tier before going to storage, while direct upload removes that application data transfer and long-lived request work. Actual charges vary by provider, region, operation class, and network route, so I'm not sure a generic dollar estimate helps. Measure with your traffic distribution. For tiny files, control-plane requests and engineering complexity may matter more than bandwidth; for large or bursty reports, connection occupancy tends to become an explicit capacity concern.
Issue and finalize uploads through a narrow Go interface
Keep vendor-specific signing behind an interface. This example deliberately omits a storage SDK implementation; each provider signs requests differently, while the authorization and state transitions belong to the application. The API accepts the report ID and declared properties, then derives the object key from trusted records.
package reports
import (
"context"
"errors"
"fmt"
"time"
)
type UploadRequest struct {
ReportID string `json:"report_id"`
Size int64 `json:"size"`
MediaType string `json:"media_type"`
}
type SignedUpload struct {
URL string `json:"url"`
Method string `json:"method"`
Headers map[string]string `json:"headers"`
ExpiresAt time.Time `json:"expires_at"`
}
type ObjectMetadata struct {
Size int64
MediaType string
ETag string
}
type Signer interface {
SignPut(ctx context.Context, key, mediaType string, size int64, expires time.Time) (SignedUpload, error)
Head(ctx context.Context, key string) (ObjectMetadata, error)
}
type Store interface {
PendingReport(ctx context.Context, tenantID, reportID string) (key string, expectedSize int64, expectedType string, err error)
MarkVerifying(ctx context.Context, tenantID, reportID, etag string) error
}
type Service struct {
signer Signer
store Store
now func() time.Time
}
func (s *Service) Begin(ctx context.Context, tenantID string, in UploadRequest) (SignedUpload, error) {
key, expectedSize, expectedType, err := s.store.PendingReport(ctx, tenantID, in.ReportID)
if err != nil {
return SignedUpload{}, err
}
if in.Size != expectedSize || in.MediaType != expectedType {
return SignedUpload{}, errors.New("declared report properties do not match")
}
expires := s.now().Add(10 * time.Minute)
return s.signer.SignPut(ctx, key, expectedType, expectedSize, expires)
}
func (s *Service) Complete(ctx context.Context, tenantID, reportID string) error {
key, expectedSize, expectedType, err := s.store.PendingReport(ctx, tenantID, reportID)
if err != nil {
return err
}
meta, err := s.signer.Head(ctx, key)
if err != nil {
return fmt.Errorf("read uploaded report metadata: %w", err)
}
if meta.Size != expectedSize || meta.MediaType != expectedType {
return errors.New("uploaded report properties do not match")
}
return s.store.MarkVerifying(ctx, tenantID, reportID, meta.ETag)
}
Ten minutes is an example policy value, not a universal default. Set expiry from observed time-to-start, not total upload duration assumptions, and test the exact behavior of the selected storage service. Your mileage may vary for mobile clients and very large reports. If uploads routinely start late because report generation is slow, sign only after generation completes rather than extending every capability.
The completion operation must be idempotent. A browser can lose the response and retry; a queue can deliver twice. Repeating Complete for the same tenant, report, object version, and metadata should return the existing state instead of launching duplicate scans or publishing twice. I want a unique database constraint on the verification job's report ID, because a comment saying βdeduplicatedβ has never stopped a duplicate delivery.
For large objects, use the storage provider's multipart or resumable protocol instead of inventing chunk semantics in the application. The same control rules still apply: the server creates the upload session for one derived key, records its identifier, limits part operations, and finalizes only the expected session. Abort abandoned sessions through a documented lifecycle policy so partial uploads don't accumulate indefinitely.
Verify the path before shifting production traffic
Test authorization failures as seriously as the happy path. A useful pre-deployment matrix includes two tenants, an expired capability, a mismatched media type, an oversized declaration, a completion retry, and a report that fails scanning. Tenant B must be unable to begin, complete, or download Tenant A's report even if it knows the report ID. A rejected report must remain unavailable through the delivery endpoint.
Watch state transitions, not just request rates. Track pending age, verification age, completion retry count, rejected objects by reason, abandoned upload sessions, and ready reports whose object metadata no longer matches the recorded version. Alert on age against the user-visible report SLO. A count of successful signing calls can look healthy while every browser upload is failing at the storage boundary.
Log capability metadata without logging the capability itself. Record the report ID, tenant ID, derived object-key hash, expiry, requested method, trace ID, and final state. URLs and query strings often contain credentials, so redact them at the edge, application logger, tracing exporter, and support tooling. Short expiry reduces exposure; it doesn't make log leakage acceptable.
Deployment should be reversible. Put the selected upload mode on the server-owned report policy, then canary direct uploads for a small cohort. Keep already-issued capabilities valid during a rollback, stop issuing new ones, and let pending records either complete through the old state machine or expire into cleanup. Do not switch a pending report's object key halfway through. Rollback to the proxy path when direct-upload completion success falls outside the established baseline, pending age breaches the SLO, or authorization tests fail. Roll back publication independently when verification is unhealthy: uploads may continue into a private quarantine area while delivery stays closed. That distinction matters during an incident because accepting bytes and granting customer access have different risk.
One more limitation: signed direct upload isn't a good fit when the backend must transform the stream synchronously, apply a data-loss-prevention decision before storage, or produce a single transactional result with another system that cannot tolerate later reconciliation. Keep the proxy for those report classes. Mixed mode is legitimate when the policy is explicit and observable.
Access first. Bytes second.
References
- https://cheatsheetseries.owasp.org/cheatsheets/File_Upload_Cheat_Sheet.html
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS
- https://www.rfc-editor.org/rfc/rfc9110
- https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-presigned-url.html
- https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lifecycle-mgmt.html
- https://cloud.google.com/storage/docs/access-control/signed-urls
- https://cloud.google.com/storage/docs/resumable-uploads
Comments
No comments yet. Start the discussion.