LibreChat/api/server/services/Files
Danny Avila 8e8fb01d18
🧱 fix: Enforce Agent Access Control on Context and OCR File Loading (#12253)
* 🔏 fix: Apply agent access control filtering to context/OCR resource loading

The context/OCR file path in primeResources fetched files by file_id
without applying filterFilesByAgentAccess, unlike the file_search and
execute_code paths. Add filterFiles dependency injection to primeResources
and invoke it after getFiles to enforce consistent access control.

* fix: Wire filterFilesByAgentAccess into all agent initialization callers

Pass the filterFilesByAgentAccess function from the JS layer into the TS
initializeAgent → primeResources chain via dependency injection, covering
primary, handoff, added-convo, and memory agent init paths.

* test: Add access control filtering tests for primeResources

Cover filterFiles invocation with context/OCR files, verify filtering
rejects inaccessible files, and confirm graceful fallback when filterFiles,
userId, or agentId are absent.

* fix: Guard filterFilesByAgentAccess against ephemeral agent IDs

Ephemeral agents have no DB document, so getAgent returns null and the
access map defaults to all-false, silently blocking all non-owned files.
Short-circuit with isEphemeralAgentId to preserve the pass-through
behavior for inline-built agents (memory, tool agents).

* fix: Clean up resources.ts and JS caller import order

Remove redundant optional chain on req.user.role inside user-guarded
block, update primeResources JSDoc with filterFiles and agentId params,
and reorder JS imports to longest-to-shortest per project conventions.

* test: Strengthen OCR assertion and add filterFiles error-path test

Use toHaveBeenCalledWith for the OCR filtering test to verify exact
arguments after the OCR→context merge step. Add test for filterFiles
rejection to verify graceful degradation (logs error, returns original
tool_resources).

* fix: Correct import order in addedConvo.js and initialize.js

Sort by total line length descending: loadAddedAgent (91) before
filterFilesByAgentAccess (84), loadAgentTools (91) before
filterFilesByAgentAccess (84).

* test: Add unit tests for filterFilesByAgentAccess and hasAccessToFilesViaAgent

Cover every branch in permissions.js: ephemeral agent guard, missing
userId/agentId/files early returns, all-owned short-circuit, mixed
owned + non-owned with VIEW/no-VIEW, agent-not-found fail-closed,
author path scoped to attached files, EDIT gate on delete, DB error
fail-closed, and agent with no tool_resources.

* test: Cover file.user undefined/null in permissions spec

Files with no user field fall into the non-owned path and get run
through hasAccessToFilesViaAgent. Add two cases: attached file with
no user field is returned, unattached file with no user field is
excluded.
2026-03-15 23:02:36 -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 🧱 fix: Enforce Agent Access Control on Context and OCR File Loading (#12253) 2026-03-15 23:02:36 -04:00
permissions.spec.js 🧱 fix: Enforce Agent Access Control on Context and OCR File Loading (#12253) 2026-03-15 23:02:36 -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