LibreChat/api/server/services/Files
Danny Avila f67bbb2bc5
🧹 fix: Sanitize Artifact Filenames in Code Execution Output (#12222)
* fix: sanitize artifact filenames to prevent path traversal in code output

* test: Mock sanitizeFilename function in process.spec.js to return the original filename

- Added a mock implementation for the `sanitizeFilename` function in the `process.spec.js` test file to return the original filename, ensuring that tests can run without altering the filename during the testing process.

* fix: use path.relative for traversal check, sanitize all filenames, add security logging

- Replace startsWith with path.relative pattern in saveLocalBuffer, consistent
  with deleteLocalFile and getLocalFileStream in the same file
- Hoist sanitizeFilename call before the image/non-image branch so both code
  paths store the sanitized name in MongoDB
- Log a warning when sanitizeFilename mutates a filename (potential traversal)
- Log a specific warning when saveLocalBuffer throws a traversal error, so
  security events are distinguishable from generic network errors in the catch

* test: improve traversal test coverage and remove mock reimplementation

- Remove partial sanitizeFilename reimplementation from process-traversal tests;
  use controlled mock returns to verify processCodeOutput wiring instead
- Add test for image branch sanitization
- Use mkdtempSync for test isolation in crud-traversal to avoid parallel worker
  collisions
- Add prefix-collision bypass test case (../user10/evil vs user1 directory)

* fix: use path.relative in isValidPath to prevent prefix-collision bypass

Pre-existing startsWith check without path separator had the same class
of prefix-collision vulnerability fixed in saveLocalBuffer.
2026-03-14 03:09:26 -04:00
..
Audio 🔊 fix: Validate language format for OpenAI STT model (#10875) 2025-12-09 22:25:45 -05:00
Azure 🔧 feat: deleteRagFile utility for Consistent RAG API document deletion (#11493) 2026-02-14 13:57:01 -05:00
Citations 🔍 fix: Display File Search Citations Based on Permissions (#9454) 2025-09-05 09:14:55 -04:00
Code 🧹 fix: Sanitize Artifact Filenames in Code Execution Output (#12222) 2026-03-14 03:09:26 -04:00
Firebase 🔧 feat: deleteRagFile utility for Consistent RAG API document deletion (#11493) 2026-02-14 13:57:01 -05:00
images 🔥 fix: Firebase Support for Nano Banana Tool (#11228) 2026-01-06 11:19:38 -05:00
Local 🧹 fix: Sanitize Artifact Filenames in Code Execution Output (#12222) 2026-03-14 03:09:26 -04:00
OpenAI 🧹 chore: Cleanup Logger and Utility Imports (#9935) 2025-10-01 23:30:47 -04:00
S3 🪣 fix: S3 path-style URL support for MinIO, R2, and custom endpoints (#11894) 2026-02-21 18:36:48 -05:00
VectorDB 📎 feat: Upload as Text Support for Plaintext, STT, RAG, and Token Limits (#8868) 2025-08-27 03:44:39 -04:00
index.js 🏪 feat: Agent Marketplace 2025-08-13 16:24:18 -04:00
permissions.js 🗃️ refactor: File Access via Agent; Deny Deletion if not Editor, Allow Viewer (#9357) 2025-08-28 21:16:23 -04:00
process.js 🧩 feat: OpenDocument Format File Upload and Native ODS Parsing (#11959) 2026-02-26 14:39:49 -05:00
process.spec.js 🧩 feat: OpenDocument Format File Upload and Native ODS Parsing (#11959) 2026-02-26 14:39:49 -05:00
strategies.js 📄 feat: Local Text Extraction for PDF, DOCX, and XLS/XLSX (#11900) 2026-02-22 14:22:45 -05:00