LibreChat/packages
Sigurður Guðbrandsson ea3c61d69a
🪣 fix: Decode S3 Object Keys from URLs (#15426)
* 🔤 fix: Decode percent-encoded S3 keys so non-ASCII filenames are readable

extractKeyFromS3Url returns `URL.pathname` as the S3 object key without
decoding it. The AWS SDK percent-encodes the Key again when it signs the
request, so a file stored under `Ársreikningur.pdf` is fetched as
`%C3%81rsreikningur.pdf` and every read fails with NoSuchKey. ASCII keys are
byte-identical either way, which is why this only appears for non-English
filenames.

Decode keys derived from a URL path in all three branches (path-style
endpoint, bucket-in-path, virtual-hosted). A key passed in raw — not a URL —
still returns untouched, and a malformed escape sequence falls back to the
raw value with a warning rather than throwing.

* 🔗 fix: Percent-encode CloudFront URL keys so both URL forms agree

buildCloudFrontUrl interpolated the raw S3 key into the URL while SDK-generated
S3 URLs carry an encoded one, so the two forms of `file.filepath` disagreed
about what a `%` means. `assertS3FileName` permits `%`, so a key containing the
literal text `report%20final.pdf` produced a CloudFront URL indistinguishable
from one for a key containing a space — and decoding on extraction would then
target the wrong object on read, re-sign, and delete.

Encoding each path segment here (separators stay literal) makes both producers
consistent, which is what lets extractKeyFromS3Url decode unconditionally.

* style: sort imports in cloudfront/crud.ts (pre-existing drift)

The changed-file import-sort gate flags this file; the drift predates this PR
(the untouched upstream version fails the same check). Kept as its own commit
so it does not obscure the fix.

* 🔏 fix: Encode the CloudFront Invalidation Path Like the Viewer URL

`buildCloudFrontUrl` now percent-encodes each key segment, so the cached
viewer path for a key with a literal `%` or a non-ASCII character is the
encoded form. `deleteFileFromCloudFront` still handed the raw key to
`CreateInvalidationCommand`, so the invalidation no longer matched the
cached object and deleted content stayed served until the entry expired.
Both producers now share one `encodeKeyPath` helper.

Also asserts that `getS3FileStream` sends the decoded key to
`GetObjectCommand`, which is the call that actually failed with
`NoSuchKey`, rather than only checking the extractor.

Co-authored-by: dinershtein <228485+dinershtein@users.noreply.github.com>

---------

Co-authored-by: Danny Avila <danny@librechat.ai>
Co-authored-by: dinershtein <228485+dinershtein@users.noreply.github.com>
2026-09-07 00:23:36 -04:00
..
api 🪣 fix: Decode S3 Object Keys from URLs (#15426) 2026-09-07 00:23:36 -04:00
client 🧰 feat: Unify Tool Activity, Reasoning, Search, and Agent Workflows (#14546) 2026-09-06 14:56:50 -04:00
data-provider 🗳️ feat: Define Conversation Code Approval Modes (#15685) 2026-09-06 22:56:51 -04:00
data-schemas 🧺 fix: Contain Conversation Import and Upload Failures (#15681) 2026-09-06 22:42:46 -04:00