#18050·langfuse

bug: media download URLs can be signed for a different bucket

Author: dakjdakdCreated Sep 29, 2026Updated Sep 29, 2026
Labelsbugfeat-multimodal-media

Describe the bug

The web application can retain media records from more than one object-storage bucket, for example after a media bucket migration or a staged configuration change. Media records store their own bucketName and bucketPath, but the web process currently keeps one process-wide media storage client.

web/src/features/media/server/getMediaStorageClient.ts initializes that client with the first bucketName passed to it and returns the same instance for every later call. The underlying storage service is constructed for that bucket, so later requests for a different bucket are still signed through the first bucket's client.

The batch media path has a second version of the same problem. mediaRouter.getByTraceOrObservationId queries bucket_name for every row, then creates one client from media[0].bucket_name and uses it to sign every media object in the result.

Steps to reproduce

  1. Have a deployment with a current upload bucket langfuse-media-v2 and retained media records in langfuse-media-v1 from an earlier configuration. Both sets of records remain available to the new web process.
  2. Request a media URL for a record in langfuse-media-v1; this initializes the process-level client for that bucket.
  3. Request a media URL for a record whose bucketName is langfuse-media-v2, or request all media for a trace containing rows from both buckets.
  4. Inspect the bucket targeted by each signed URL and download the objects.

The request uses the correct database row and path, but the signing client is still bound to the first bucket seen by the process. In the mixed trace case, every returned URL is signed by the first row's bucket.

Expected behavior

Each media object should be signed with a storage client configured for that object's recorded bucketName. A process may serve media from multiple buckets at the same time, and the result should not depend on request order.

When several media objects share a bucket, the client can still be reused for that bucket. Objects from different buckets must use separate clients.

Impact

Media previews and downloads can fail after a bucket rotation, migration, or any deployment that serves old and new media records together. The issue is particularly visible on traces with media attached to more than one bucket: one item can determine the signing configuration for all other items in the response.

The public response shape does not need to change; only the bucket used to generate each presigned URL is incorrect.

Proposed fix

Cache media storage clients by bucketName instead of keeping one global client. In the batch media resolver, obtain the client for each row's bucket_name before generating its URL.

Add regression coverage for:

  • two bucket names returning two distinct cached clients;
  • repeated requests for the same bucket reusing its client;
  • a mixed-bucket media list signing each object with its own bucket.

Relevant code

  • web/src/features/media/server/getMediaStorageClient.ts — process-level client cache.
  • web/src/features/media/server/mediaService.ts — single-media download URL generation.
  • web/src/server/api/routers/media.ts — trace/observation media URL generation.

What the response contains today

For a mixed result such as:

media[0] -> bucket: langfuse-media-v1, path: project-a/old.png
media[1] -> bucket: langfuse-media-v2, path: project-a/new.png

the router creates its signer from langfuse-media-v1 and uses it for both paths. The second URL therefore carries the signing configuration for the wrong bucket even though its database row contains the correct bucket name.

Langfuse Cloud or self-hosted?

Self-hosted

If self-hosted, what version are you running?

Reproduced from source on main at 81e065bb0 (4.47.0); no live deployment was used.

Additional information

Related work

The open external-download-endpoint work in PR #14300 changes the endpoint used for download presigning. It does not make the client cache bucket-aware, so the bucket-selection fix should remain an independent change and be applied alongside that work if both are merged.

Are you interested in contributing a fix for this bug?

Yes