🌐 fix: Percent-encode X-File-Metadata header for Unicode filenames (#12983)

* 🌐 fix: Percent-encode X-File-Metadata header for Unicode filenames

After #12977 preserved Unicode in filenames, the download route
crashes with ERR_INVALID_CHAR because JSON.stringify(file) now
contains non-ASCII characters that Node.js rejects in HTTP headers
per RFC 7230.

Wrap the header value in encodeURIComponent on the server and
decodeURIComponent on the client before JSON.parse.

* fix: Update file route tests after dev merge

---------

Co-authored-by: Danny Avila <danny@librechat.ai>
This commit is contained in:
Joseph Licata 2026-05-06 21:01:25 -04:00 committed by GitHub
parent 5c338a4642
commit 5efbcb8b93
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 11 deletions

View file

@ -96,7 +96,9 @@ export const useFileDownload = (
const blob = response.data;
const downloadURL = window.URL.createObjectURL(blob);
try {
const metadata: t.TFile | undefined = JSON.parse(response.headers['x-file-metadata']);
const metadata: t.TFile | undefined = JSON.parse(
decodeURIComponent(response.headers['x-file-metadata']),
);
if (!metadata) {
console.warn('No metadata found for file download', response.headers);
return downloadURL;