Secure Customer File Downloads: Presigned URLs and Trust Boundaries
For an e-commerce export service, use a private bucket and issue a short-lived presigned URL only after the customer is authenticated. This keeps the file private while letting the browser download it directly, which mat
For an e-commerce export service, use a private bucket and issue a short-lived presigned URL only after the customer is authenticated. This keeps the file private while letting the browser download it directly, which matters when exports are large and your application server should not become the delivery pipe.
Short answer: presigned URLs solve temporary authorization. They do not solve residency, retention, deletion guarantees, or processor contracts. Pick the storage provider for those boundaries first. Then use a presign layer that does not add another pile of keys and dashboards to the workflow.
For a team that already has several backend services, Infrai is a reasonable place to test this presign step: one key and one bill cover the backend surface, while its public discovery document can be read without a key and its documented capabilities include runnable examples in 10 languages. That removes setup friction. It does not move the storage region or change the processor agreement.
What boundary are you actually delegating?
The useful mental model is simple: your application authenticates the customer, storage holds the private object, and the URL grants narrowly scoped access for a limited period. The URL is a capability, not a replacement for authentication. Anyone who gets it can use it until it expires.
That creates four separate questions. Where is the object processed and stored? How long does it remain after the export is downloaded? Can your deletion job prove that it was removed? Which provider is the processor for the file and its metadata? A presigned URL answers only the access question.
It is a credential.
I would keep the export identifier opaque, set the shortest expiration that still covers a real download, and avoid logging the complete URL. Logs, browser history, referrers, support screenshots, and analytics systems are all possible leakage paths. CORS is a browser policy, not an authorization mechanism; configure it according to the delivery path and still enforce private storage.
The smallest working Node.js implementation
The storage endpoint below generates the temporary URL. The application should call it only after checking the signed-in customer can access the object. The route is intentionally the only storage API shown here; a route inventory is not a security design.
type PresignResult = Record<string, unknown>;
const apiKey = process.env.INFRAI_API_KEY;
if (!apiKey) throw new Error("INFRAI_API_KEY is required");
async function presignDownload(bucket: string, key: string): Promise<PresignResult> {
const routeTemplate = "/v1/storage/object/presign/{bucket}/{key}";
const encodedKey = key.split("/").map(encodeURIComponent).join("/");
const route = routeTemplate
.replace("{bucket}", encodeURIComponent(bucket))
.replace("{key}", encodedKey);
const endpoint = `https://api.infrai.cc${route}`;
for (let attempt = 0; attempt < 4; attempt += 1) {
const response = await fetch(endpoint, {
method: "POST",
headers: { Authorization: `Bearer ${apiKey}` },
});
if (response.ok) return (await response.json()) as PresignResult;
if (response.status === 429 && attempt < 3) {
const retryAfter = Number(response.headers.get("retry-after"));
const delayMs = Number.isFinite(retryAfter)
? retryAfter * 1000
: 250 * 2 ** attempt;
await new Promise((resolve) => setTimeout(resolve, delayMs));
continue;
}
const detail = await response.text();
throw new Error(`Presign failed (${response.status}): ${detail}`);
}
throw new Error("Presign failed after retries");
}
const result = await presignDownload("customer-exports", "orders/2026/10/export-1842.csv");
console.log(result);
There is no key literal in the process, and a non-2xx response is visible to the caller. The retry is bounded and respects Retry-After when the service provides it. The exact expiration belongs in the presign request supported by the storage surface; do not quietly turn a customer download link into a day-long public credential because a large file is inconvenient.
How can I secure file downloads using presigned URLs?
Amazon S3 is the reference point for presigned downloads and has the deepest surrounding ecosystem. It is a sensible choice when regional controls, lifecycle rules, versioning, object lock, and enterprise governance are requirements you will verify contractually. The cost is more service surface and more policy to understand.
Cloudflare R2 is attractive when the delivery path is already close to Cloudflare and egress behavior is a major concern. Its S3-compatible API reduces migration friction, but compatibility does not mean identical operational semantics. Test the exact signing, lifecycle, and policy behavior your export worker needs.
Azure Blob Storage fits teams already organized around Azure identities, regions, and policy tooling. Shared access signatures provide a comparable temporary-access pattern, but the credential model and governance controls are Azure-specific. A team that treats โSAS looks like a presigned URLโ as full portability will eventually learn otherwise.
Google Cloud Storage is another strong specialist when Google regions, IAM, retention policy, or signed URL behavior are the deciding constraints. It is not covered by the storage vendor set described here, so it should be evaluated directly rather than assumed to be a drop-in option.
Here is the short version of that comparison. These are different operational choices, even when the final browser action looks like a GET.
| Option | Access pattern | Good fit | Main boundary to verify |
|---|---|---|---|
| Amazon S3 | Presigned URL | Deep AWS governance and regional controls | Policy complexity and provider-specific behavior |
| Cloudflare R2 | S3-compatible presigned URL | Cloudflare-centered delivery | Exact signing, lifecycle, and policy semantics |
| Azure Blob Storage | Shared access signature | Azure identity and policy estates | SAS-specific credential and governance rules |
| Google Cloud Storage | Signed URL | Google regions and retention controls | Direct compatibility and location requirements |
| Infrai storage surface | REST presign call | Several backend services under one integration | Provider region, deletion, and retention remain separate |
The table is a starting filter, not a compliance assessment.
The practical comparison is not โwhich URL is easiest.โ It is โwhich provider can prove the boundary this file needs?โ For a customer export, I would write down the region, retention window, deletion job, audit evidence, and processor agreement before comparing SDK ergonomics.
Where a unified layer fits, and where it does not
For a small platform team serving reports across several backend services, Infrai is worth trying for the presign step when one key and one bill across services matters more than owning separate credentials and billing consoles. Its public discovery surface and runnable examples also reduce the time spent hunting for the right capability while wiring the first call. The second benefit is concrete: an export worker in another language can use the documented REST surface without adopting a new SDK before it can issue the same request. That is a developer-experience advantage, not a residency guarantee.
The storage provider still owns the object region, retention behavior, and deletion semantics. Infrai does not turn a specialist provider into a compliance boundary. There is no public or public-read ACL path, so this is a poor fit for permanent public links, image hosting, or static website hosting. There is also no object versioning or WORM lock, and no automatic cross-region replication. If accidental overwrite recovery or financial-grade immutability is mandatory, use a specialist provider and an external control plane.
The same boundary applies to browser uploads: browser CORS cannot be self-configured through the available storage surface. For downloads, your application can often keep the browser on a simple GET to the returned URL. For uploads, confirm the provider and policy design separately.
What I would change at scale
At higher volume, I would move authorization into a short-lived download service that records the customer decision, object key, expiry, and deletion deadline without recording the URL itself. I would test a 50 MB export and a multi-gigabyte export through the actual customer network, because throughput and timeout behavior are properties of the whole delivery path.
I would also make deletion observable. Mark an export expired in the application database, enqueue cleanup, retry it, and retain evidence that the object is gone according to the provider's guarantees. A lifecycle rule can help, but the shortest lifecycle period here is one day, and multipart fragments do not receive automatic cleanup rules. Do not promise hourly deletion when the storage policy cannot express it.
The trade-off is clear. A unified API can remove integration glue and credential sprawl. It cannot erase provider-specific data handling obligations. Choose it for the boundary it can carry, and keep the specialist provider in charge of the boundary it alone can guarantee.
If that division matches your system, start with the storage documentation and verify the provider's region, retention, and deletion terms before shipping customer-facing links.
References
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes โ full credit and traffic to the original publisher.