Course Image Isolation: 5 Private-Bucket Controls for Resizing and Signed URLs
Short answer: keep course media in a private bucket, authorize direct uploads against a server-owned tenant record, let a worker create a fixed set of thumbnails, and mint a signed URL only after the application rechecks tenant access to the finished derivative. The resize library is not the security boundary. The binding among tenant, source object, transform, and derivative is. I've been paged…
The key to securing media files lies in isolating them within a private bucket and managing uploads, transformations, and access through a series of controls. First, create a media record before allowing an upload, binding an opaque media ID to the authenticated tenant, a server-derived source key, allowed content class, and a limited set of permitted derivatives.
This central invariant ensures every subsequent operation derives storage locations from the tenant ID and media ID pair, preventing filename-based collisions and disclosure bugs.
Next, establish an authority matrix to clearly define the permissions of each actor before deciding on the physical bucket layout. This approach is more effective than relying solely on vendor feature lists, as shared credentials can undermine even the most carefully designed key schemes. Actors such as the browser uploader, resize worker, application signer, and operator each have specific roles and permissions that must be explicitly defined.
For resizing, treat each resize message as a reference to trusted state rather than a self-authorizing command. The worker should receive the tenant ID, media ID, transform name, and immutable source identity, then load the media record, recompute the source and destination keys, and only permit transformations from the allowed catalog.
Outputs must be deterministic, ensuring that for a specific immutable source identity and transform name, every delivery addresses the same derivative key. This prevents duplicate deliveries from inventing new owners or output locations, even if the same task is completed multiple times.
Finally, after the client reports completion, verify the expected source object against the existing media record before advancing the state of the media. This separation between "upload was authorized" and "the expected source is present" is crucial, as a worker must not infer ownership from a queue message or a client assertion.
The state sequence should be created, upload_authorized, source_verified, derivatives_pending, and ready, with transitions conditional on the current expected state. This approach ensures that messages can arrive multiple times or late without timing dependencies affecting authorization.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to