Secure Object Storage: Safer Pre-Signed Uploads11 min read2,174 words

Secure Object Storage: Safer Pre-Signed Uploads

Learn how to secure object storage with pre-signed URLs, tenant-scoped authorization, verified uploads, and practical tests for receipt workflows.

secure object storagepre-signed URLstenant isolationsecure file uploadsobject storage security
Secure Object Storage: Safer Pre-Signed Uploads

How to Secure Object Storage Without Building a File Proxy

If your SaaS handles receipts, invoices, or other customer files, you need a reliable way to move data between a browser and object storage - without turning every upload into an application-server job. Pre-signed URLs can solve the transfer part. They don't solve authorization.

A pre-signed URL is a temporary capability: anyone who has it can do a specific operation on a specific object until the URL expires. That's useful, but it means you still have to decide who gets the URL, what object it applies to, and what limits you'll enforce. A tenant ID or receipt ID coming from the client isn't proof the user should have access.

This guide walks through a practical multi-tenant workflow. You'll see where authorization belongs, how to structure object keys and upload records, what to verify after a transfer, and which tests catch cross-tenant failures. It also covers when a server-side proxy is worth paying for in bandwidth and latency. The point isn't to make storage fancy - it's to keep identity, tenant boundaries, and audit evidence under your control.

How do pre-signed URLs secure object storage?

A pre-signed URL lets your application authorize a user, then let the browser transfer the file bytes directly to or from object storage. The storage provider signs a request for a particular object and operation. The URL usually expires quickly, so your servers don't have to stream every file.

That split is a good fit for a small SaaS: your app handles identity and policy, and object storage handles the bytes. You also avoid building a proxy that has to scale with every uploaded or downloaded byte.

But the URL isn't an access-control system. It's a bearer capability. If someone has the URL and it hasn't expired, they can use it. It doesn't know whether the user changed jobs, lost a role, or switched tenants. So your application has to re-check authorization before it issues each URL.

What should a URL be allowed to do?

Keep each capability narrow. A URL should grant one operation on one specific server-selected object for a limited time. Don't make it a way to access a directory, a whole tenant, or a reusable session.

Before signing, determine:

  • Who is making the request: authenticate the user using your normal session or identity system.
  • Which tenant they're in right now: derive it from trusted server-side membership data, not from a request parameter.
  • Whether their role allows the operation: upload and download permissions often differ.
  • Which object is involved: select or retrieve its key on the server.
  • What constraints apply: set an expiry and, where supported, bind the request to an expected method, content type, or size policy.

Provider behavior varies. Some storage systems let you enforce constraints for uploads, while others rely on different mechanisms (for example, signed POST policies vs signed PUT requests). Don't assume a "max bytes" setting is enforced just because an adapter accepts it. Confirm what the provider actually does, and verify the stored object after upload.

A short expiry reduces the risk window, but it doesn't replace authorization. Pick an expiry that gives a real user enough time to finish a transfer under normal network conditions. Five minutes might work for a receipt upload, but treat it as an example - not a law.

How do you isolate tenants and protect original files?

Tenant isolation is a data-model and authorization problem, not something you get "for free" from object key names. A tenant prefix can make keys easier to reason about, but it won't stop a user from downloading another tenant's file if you sign the wrong key.

Generate an object key on the server using trusted identifiers. For example:

tenants/{tenantId}/receipts/{receiptId}/original

The tenant and receipt identifiers should come from your application's generated/resolved data. Don't use a browser-supplied filename as an object key, or even as the basis for authorization. Filenames can include slashes, Unicode oddities, collisions, and unexpected characters. Treat the original filename as display metadata, not as a storage path.

Repeat authorization on every read

A common mistake is to authorize during upload, then assume a receipt ID alone is enough to authorize downloads. It isn't. For every download:

  1. Load the receipt record.
  2. Compare the receipt's tenant to the authenticated user's current tenant.
  3. Check the user's current role.
  4. Only then ask your storage adapter to sign the object key.

This matters when someone leaves an organization or their access changes. An old URL might still work until it expires, but you should never use an unexpired link as evidence that the user is still authorized. If membership changes, the application must stop issuing new URLs and should refuse to serve downloads that don't match current authorization.

Keep your storage adapter behind an application-owned interface. It should receive an already-authorized object reference - not a raw tenant ID or a filename coming from the browser. That makes the boundary obvious in code and reduces the chance that a convenient download endpoint accidentally becomes a cross-tenant leak.

Preserve the original as evidence

For receipts and similar records, store the original file separately from thumbnails, extracted text, or transformed images. A preview might be helpful for your UI, but it's not a substitute for the evidence file.

Also keep a database record for each upload. Useful fields include tenant ID, receipt ID, object key, uploader, expected content type, expected size limit, upload status, and timestamps. If you generate thumbnails or run OCR, record those derived artifacts too. This gives support and audit workflows a straightforward answer to the real question: what original file was received, and what processing happened afterward?

How should you implement upload and download flows?

Treat an upload like a small state machine, not a single click. Create a pending record before issuing an upload URL. That record represents your server's intent and gives you something trusted to validate when the upload finishes.

A typical flow looks like this:

  1. Authenticate the user and resolve their current tenant and role.
  2. Create a pending receipt record with a server-generated receipt ID and object key.
  3. Ask the storage signer for a short-lived upload capability, using provider-supported constraints.
  4. Return the URL and any required request details to the browser.
  5. After the browser reports completion, verify the object using storage metadata or a trusted storage event.
  6. Compare what you verified with the pending record, then mark the receipt complete.

A browser success message isn't proof the expected file landed in storage. Check the object exists and validate size and content type. If your workflow needs stronger integrity, calculate or verify a checksum. Keep verification and the state update in one idempotent completion step so retries don't create competing "original" files.

Keep signing behind a small interface

Your application should own policy. The storage adapter should deal with provider mechanics. For example, a minimal TypeScript contract could be:

type StorageSigner = {

signUpload(input: {

key: string;

contentType: string;

expiresInSeconds: number;

}): Promise<{ url: string; expiresAt: string }>;

signDownload(input: {

key: string;

expiresInSeconds: number;

}): Promise<{ url: string; expiresAt: string }>;

};

function receiptKey(tenantId: string, receiptId: string): string {

return `tenants/${tenantId}/receipts/${receiptId}/original`;

}

Your app checks permission and builds the key before calling signUpload. If the provider supports size constraints in its signing mechanism, include them there. If not, enforce limits during your upload verification and reject objects that exceed the pending record's limits.

Downloads follow the same boundary, even if the flow is shorter: load the receipt, authorize the actor against the receipt's tenant and their current role, then sign the stored key. Issue a fresh URL per request rather than keeping a long-lived download link around "because it's convenient."

Don't log the full URL. Query strings often include the signature, so application logs can accidentally become a capability leak. Log the actor ID, tenant ID, receipt ID, operation, the authorization result, and a safe object-key reference instead. That gives useful audit context without copying the bearer token into your logs.

What should you test, and when is a proxy better?

The most valuable tests aren't "it uploads successfully." They're the tests that prove one tenant can't obtain a capability for another tenant's object - especially when inputs are stale, unexpected, or just wrong.

Create two tenants and a receipt in each. Then test that a member of Tenant A cannot get a download URL for Tenant B's receipt. Repeat with:

  • a client-supplied receipt ID (that doesn't belong to them),
  • a changed filename,
  • a user whose membership was revoked.

Also test expired upload intents, content-type mismatches, oversized objects, missing objects, and repeated completion requests.

In unit tests, use a fake signer. Record the key, operation, and expiry so the test can assert that your application selected the right object and applied the expected policy. In integration tests, run against a non-production storage environment to check provider-specific behavior, especially upload constraints and object metadata. Never ship production credentials into tests.

In production, monitor signing failures, authorization denials, abandoned pending records, and object-verification failures. Use tenant-safe dimensions for metrics. Avoid raw filenames and signed URLs in labels, logs, or tracing data - those can expose sensitive information and also explode metric cardinality.

When should you proxy file transfers?

Direct transfer is usually the default when your app only needs to authorize the operation and verify the result. A proxy can be the better choice when:

  • a legacy client can't upload directly,
  • every byte must pass through an inspection service,
  • you need to transform content synchronously before it reaches storage.

The trade-off is operational. A proxy adds application bandwidth and latency, and it creates a scaling path that grows with file volume. It can also make a required inspection/transform boundary easier to enforce. If compliance or product requirements demand that you examine every byte before anything becomes durable storage, the extra cost may be worth it.

This isn't "pre-signed URLs are always safer." It's about whether direct transfer fits your trust and inspection model. For a normal browser receipt workflow: authorize in the application, sign one narrow operation, verify what was stored, and keep the original. Use a proxy when a concrete requirement makes that separation insufficient.

Conclusion

Pre-signed URLs are a practical way to move files without forcing your application server to carry every byte. The security comes from what your application does before signing: authenticate the actor, resolve current tenant membership, check permissions, and choose a server-owned object key.

For a receipt workflow, keep it small and explicit: create a pending record, issue a narrow and short-lived capability, verify the stored original, and re-authorize every download. Test tenant boundaries as a first-class requirement. If you must inspect every byte before storage, accept the proxy cost. Otherwise, let object storage handle transfer while your application stays responsible for identity, policy, and audit evidence.

Frequently Asked Questions

They can be secure when the application authenticates the user, checks tenant and role permissions, and signs a single operation for a server-selected object with a short expiry. They are bearer capabilities, so anyone who obtains a valid URL may use it until it expires. Avoid logging or exposing the full URL unnecessarily.
The object key can include a server-generated tenant prefix, but a tenant ID sent by the browser is not authorization. Resolve the tenant from the authenticated user’s current membership, check their role, and derive the object key on the server before creating a URL.
Set an expiry long enough for a legitimate upload under expected network conditions, but short enough to limit exposure if the URL leaks. Five minutes is a reasonable example for some receipt workflows, not a fixed rule. Consider file size, connection quality, retries, and provider behavior when choosing a value.
Use a proxy when a client cannot upload directly or when every byte must pass through inspection or synchronous transformation. Otherwise, direct uploads usually reduce application bandwidth and scaling work. The right choice depends on your security boundary and product requirements, not on a blanket preference for one transfer pattern.

Related articles