Short answer: Send large generated report images from the browser straight to object storage with a short-lived presigned PUT, but issue that permission only after authenticating the customer and selecting the correct US or EU bucket. Treat CORS as a browser permission check, signing as an exact-request contract, and regional placement as a separate data-control decision. Mixing those three planes is what makes this incident drag on.
The operational rule is direct: reproduce the failing preflight first, then compare the eventual PUT byte for byte with what the signing service authorized. Don't widen CORS until the upload works. A broad policy can hide an origin or header mismatch while also expanding who can attempt writes.
For a gaming SaaS, the object here is a generated customer report: perhaps a large match-analysis image or a rendered season summary. The application authorizes access; object storage moves the bytes. Keep those responsibilities apart.
How can we test browser CORS for a presigned PUT of generated images?
Start in the browser network panel and find the OPTIONS request that precedes the PUT. If OPTIONS fails, investigate the storage CORS policy and the requested origin, method, and headers. If OPTIONS succeeds but PUT returns 403, move to the signing contract: URL, method, expiry, region, canonical headers, and any signed content type. A 400 commonly points to request shape rather than browser permission. Record the response body and request ID when the storage service exposes them; the status alone isn't enough for a useful incident note.
This distinction matters because the browser enforces CORS while the storage service verifies the signature. The preflight asks whether an origin may send a method with a given header set. It doesn't prove that the later request carries a valid signature. Conversely, a presigned URL can be valid outside a browser and still fail in a page whose origin isn't allowed.
Use a compact decision table during triage:
| Observed signal | First check | Do not do yet |
|---|---|---|
No OPTIONS request |
Browser console, mixed content, URL construction | Change bucket permissions |
OPTIONS rejected |
Exact page origin, PUT, requested headers |
Regenerate signing keys |
OPTIONS passes; PUT is 403
|
Signed method, region, expiry, headers | Set an allow-all origin |
| Upload completes; app can't display it | Read authorization, object metadata, GET CORS | Reissue the write URL |
| Only EU or US tenants fail | Tenant-to-region mapping and endpoint host | Add a cross-region retry |
One trap deserves a longer note. A test client can upload successfully while the browser fails, because a command-line client doesn't enforce browser CORS. The reverse can also confuse the trace: preflight may pass, yet the actual PUT differs from the signed request because the browser added a content type that the signer didn't include, or the UI changed that value after ticket issuance. Capture the intended headers in the upload ticket, return them to the client, and send exactly those headers. Don't let two layers independently guess metadata.
Keep the planes separate.
Implement the Go ticket around byte flow
The application endpoint should authenticate the customer, authorize access to the report, choose the regional bucket, reserve a non-user-controlled object key, and return a short-lived upload ticket. The browser should receive only what it needs: the presigned URL, the exact headers to send, an expiry timestamp, and an opaque object ID. It should never choose an arbitrary bucket or overwrite path.
The object key also carries an idempotency decision. A retry after a lost response is normal, so tie the key to a stable report-generation ID rather than creating a fresh object on every click. If replacement is allowed, define it deliberately. If it isn't, the metadata row should reject a second completed upload. This is the same reflex used for duplicate queue delivery: retries are expected; duplicate side effects are the bug class to contain.
Here is the server-side boundary in Go. The Presigner is deliberately generic; its implementation can target the team's object store without leaking vendor code into authorization logic.
package upload
import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"
)
type PutRequest struct {
Bucket string
Key string
ContentType string
ExpiresIn time.Duration
}
type Ticket struct {
ObjectID string `json:"object_id"`
URL string `json:"url"`
Headers map[string]string `json:"headers"`
Expires time.Time `json:"expires_at"`
}
type Presigner interface {
SignPut(context.Context, PutRequest) (string, error)
}
type Server struct {
Signer Presigner
Now func() time.Time
}
func (s *Server) IssueTicket(w http.ResponseWriter, r *http.Request) {
customerID, ok := authenticatedCustomer(r.Context())
if !ok {
http.Error(w, "unauthorized", http.StatusUnauthorized)
return
}
reportID := r.URL.Query().Get("report_id")
region, ok := authorizedReportRegion(r.Context(), customerID, reportID)
if !ok {
http.Error(w, "report not found", http.StatusNotFound)
return
}
contentType := "image/png"
key := fmt.Sprintf("customers/%s/reports/%s.png", customerID, reportID)
expiresIn := 10 * time.Minute
url, err := s.Signer.SignPut(r.Context(), PutRequest{
Bucket: regionalBucket(region), Key: key,
ContentType: contentType, ExpiresIn: expiresIn,
})
if err != nil {
http.Error(w, "could not issue upload ticket", http.StatusServiceUnavailable)
return
}
ticket := Ticket{
ObjectID: reportID, URL: url,
Headers: map[string]string{"Content-Type": contentType},
Expires: s.Now().Add(expiresIn),
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(ticket)
}
The fixed ten-minute lifetime is an example policy, not a universal optimum. Large files, slow client uplinks, and storage-specific expiry semantics affect the right value; your mileage may vary. Measure ticket age at upload start and completion before tightening it. I'm not sure a team can choose a defensible expiry without that distribution.
A direct PUT also needs size control. Presigning authorizes a request, but the full enforcement options depend on the storage API and upload mechanism. If a hard upper bound cannot be bound into the request, validate the generated report size before issuing the ticket, inspect the stored object before marking it ready, and remove rejected objects through a controlled cleanup path. For very large reports or unreliable networks, multipart or resumable upload may be the better protocol. A single PUT is not suitable when restarting the whole transfer would violate the recovery-time target.
What cost and throughput budget should each regional upload meet?
Start with bytes, not request counts. Build a size distribution for generated report images, separate US and EU tenants, and combine it with concurrent upload starts and observed retry volume. The useful capacity question is how much ingress each region must accept during the busiest window, including bytes resent after interrupted single-part PUTs. A dashboard that counts only completed objects erases the expensive part of a bad network path.
Direct upload keeps those large bytes off the application fleet, but it doesn't remove the need for admission control. Limit how many generation jobs a customer can move into the upload phase, expire abandoned pending records, and ensure the selected storage path can absorb the intended concurrency. When a report is large enough that a full restart dominates recovery time, use a multipart or resumable protocol and track completed parts under the same stable report ID. The catch is added state: part expiry, abort cleanup, checksum verification, and idempotent completion all enter the runbook.
CORS should list the web application origins that may make browser requests; it shouldn't decide where customer data lives. The signing service must derive placement from trusted tenant configuration and select the corresponding regional endpoint before signing. That mapping belongs in auditable application state. A request field such as region=eu is only a hint until server-side authorization confirms it. Capacity must be reviewed per region as well, because spare US headroom cannot satisfy an EU report's placement rule.
For EU data that may be transferred to a third country, GDPR Chapter V sets conditions for those transfers. This article can't determine whether a particular report contains personal data or whether a transfer mechanism is valid. Legal classification, subprocessors, backup locations, support access, and deletion behavior need review outside the upload handler. The engineering contribution is to make placement explicit, observable, and hard to bypass.
Cross-region fallback is tempting during an incident. Resist automatic fallback unless the data policy explicitly permits it. A healthy US bucket is not a valid recovery target for an EU tenant merely because it makes the alert green. Stick with an application-mediated upload when customer policy requires content inspection before storage, strict synchronous size enforcement, or transformations that must happen before persistence; direct browser PUT is the wrong boundary in those cases.
Cost is another operational input, though it isn't the architecture's main argument. Model stored bytes, write requests, retrieval, retry traffic, and data transfer for the actual report lifecycle, then verify the current terms for the chosen service. Direct upload moves the large-file data path away from the application fleet, while storage and network usage remain part of the capacity review.
Operate retries and rollback as one failure domain
Use a small release matrix that crosses origin, tenant region, file size, and browser family. Include the production US and EU origins, not just localhost. Test a normal image, an image near the supported limit, an expired ticket, a changed content type, and a retry of the same report ID. Expected failures should be specific: an expired or mutated request must be rejected, while a permitted request must create exactly the intended object.
Observe both halves of the transaction. The application should log ticket ID, tenant region, object ID, expiry, and signing outcome without logging the signed query string. The completion path should record object size, checksum when available, and the transition from pending to ready. Browser telemetry should separate preflight failure, network failure, timeout, and storage rejection. Never put the presigned URL in analytics; it is a temporary credential.
For throughput, test over realistic uplinks with report sizes drawn from production-like fixtures. Track upload duration, retry count, bytes restarted, and time from ticket issuance to PUT start. Averages blur the users most likely to hit expiry. Percentiles and a size-bucketed view tell the on-call engineer whether the fix improved the slow path. No invented benchmark can replace that workload-specific evidence.
The deployment sequence is boring on purpose:
- Add telemetry and the regional mapping check before changing CORS.
- Apply the narrow origin, method, and header policy to a test bucket.
- Exercise positive and negative cases from the real application origin.
- Roll out by region and watch preflight success, PUT rejection, and duplicate completion rates.
- Stop the rollout if either region diverges from its baseline.
Rollback should restore the last known CORS document and signing configuration as a pair. Keep both versioned, because rolling back only one can recreate the mismatch. Previously issued URLs may remain usable until their configured expiry, so a rollback note must include that exposure window and the decision on whether object access needs revocation.
Fast rollback beats clever diagnosis during impact.
Top comments (0)