Private Image Storage for AI Apps: Signed Download Links and Tenant Exports
Short answer: for a fintech AI app, the cheapest private image storage is the design that keeps every object private, binds each signed download link to a tenant and export, and expires it quickly; an S3-compatible bucke
Short answer: for a fintech AI app, the cheapest private image storage is the design that keeps every object private, binds each signed download link to a tenant and export, and expires it quickly; an S3-compatible bucket, R2-style object store, or a self-hosted alternative can all work when those controls live above the storage API.
I treat storage as an authorization problem first. The application stores product images generated for several financial tenants, then produces a tenant-scoped export for a review or audit job. A public bucket is not an optimization. It is an accidental data-sharing feature.
That boundary matters.
Start with the export boundary, not the bucket
Give each object a key whose first component is an internal tenant identifier, but never trust that prefix by itself. The export service should load the export record, verify the caller's tenant, and select an allowlisted set of object IDs. This prevents a path traversal bug in application code from becoming a cross-tenant read.
A signed URL is a bearer capability. Treat it like a short-lived credential: keep its lifetime close to the download window, sign the exact object key, and include the response disposition you expect. Do not put a tenant ID in a URL and call that authorization. The object store still needs to remain private, while the API logs who requested the grant and which export it served.
The awkward edge case is revocation. A URL already issued to a browser cannot usually be recalled at the storage layer. For sensitive exports, put a download endpoint in front of storage, check an export status on every request, and stream the object only while the grant is valid. For ordinary product previews, a direct signed link is a reasonable trade.
What should a private image storage export check before signing links?
There are four checks worth making explicit: tenant ownership, export membership, object media type, and expiry. I keep the signing function small so it is easy to test with a fake object-store client.
from datetime import datetime, timedelta, timezone
class ExportDenied(Exception):
pass
def signed_download(store, export_record, requester_tenant, object_id):
if export_record["tenant_id"] != requester_tenant:
raise ExportDenied("tenant mismatch")
item = next((x for x in export_record["items"] if x["id"] == object_id), None)
if item is None or item["media_type"] not in {"image/png", "image/jpeg"}:
raise ExportDenied("object is not in export")
expires = datetime.now(timezone.utc) + timedelta(minutes=5)
return store.create_presigned_get(
key=item["key"],
expires_at=expires,
response_content_type=item["media_type"],
response_content_disposition=item["filename"]
)
Five minutes is an example policy, not a universal number. Your mileage may vary for a batch export that takes an hour to review. The important part is that the lifetime is deliberate, observable, and shorter than the retention period.
Comparing object storage alternatives on isolation and operations
S3 and R2 expose familiar private-object and presigned-request patterns. A self-hosted S3-compatible service can keep data in your own network, but then your team owns upgrades, disk failure handling, replication, and incident response. A cloud object store reduces those chores, while egress behavior, regional controls, and account-level limits still need review.
| Approach | Isolation work left to the app | Operational trade-off |
|---|---|---|
| Managed S3-compatible store | IAM policy, key layout, export checks | Less hardware work; review egress and region policy |
| R2-style object store | Tenant authorization and signed-link policy | Simple HTTP surface; check lifecycle and egress semantics |
| Self-hosted alternative | All authorization plus cluster and disk security | More placement control; more on-call responsibility |
None of these choices makes a public bucket acceptable for regulated product images. The differentiator is the enforcement point and the audit trail, not the brand on the endpoint.
Failure modes that make a cheap design expensive
The first failure is signing before checking membership. The second is reusing one long-lived link in an email or ticket. The third is letting a background cleanup job delete an object while an export is still open. I use an export state machine (queued, ready, expired, revoked) and make cleanup honor ready exports until their retention deadline.
Upload paths deserve the same attention. Validate content type and size before accepting bytes, record a checksum, and write an immutable event for the tenant and object ID. Browser progress can be reported with standard XMLHttpRequest upload events, but progress is not proof that the bytes are safe or that the caller belongs to the tenant.
Cache headers can leak more than a bucket policy. Set Cache-Control: private, no-store on responses carrying sensitive images unless a documented preview cache is acceptable; MDN's header reference explains how shared caches interpret those directives. Also strip metadata that could contain a user's location before an image enters an export.
Freeze new public writes, inventory every key, and classify each object by tenant and retention requirement. Copy into private keys with a server-side job, verify checksums, then switch reads to the authorization path. Keep the old path returning a measured denial rather than silently redirecting.
The catch is that a self-hosted store is not suitable when your team cannot staff storage rotation, replication tests, and incident response; stick with a managed option in that case. Conversely, a managed store may be the wrong fit when data residency requires a location it cannot provide. I am not sure which constraint will dominate for your organization until legal, risk, and operations sign off on the region and retention policy.
Start with one tenant, replay denied-access tests, and watch logs for cross-tenant key requests. Cost follows from bytes, requests, retention, and egress, but an inexpensive line item is still a bad deal if an export crosses a tenant boundary.
Ship it carefully.
References
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.