LibreChat/api/server
Dustin Healy 0e14d91ed9
⏱️ fix: Compile admin file-config MIME patterns on a linear-time engine (ReDoS) (#14555)
* ⏱️ fix: Compile admin file-config MIME patterns on a linear-time engine

convertStringsToRegex compiled admin-configured supportedMimeTypes with the native RegExp engine, and checkType runs those patterns against an uploaded file's Content-Type on the server event loop, so a catastrophic-backtracking pattern in fileConfig could ReDoS the whole process on upload.

The MIME-pattern compiler is now swappable. It defaults to native RegExp, which browser builds keep so no engine is added to the client bundle, and the server injects a linear-time engine (RE2JS) at startup. Only test is ever called on these matchers, so the shared type widens to a structural RegexLike with no behavior change for valid patterns. The browser stays on native because a client-side stall would only affect that one tab.

* ⏱️ fix: Wire the linear MIME compiler in the experimental entry point

api/server/experimental.js mounts the same upload routes and calls mergeFileConfig but never set the linear-time compiler, so admin MIME patterns still compiled with native RegExp there. Mirror the setup, and widen the client-side supportedMimeTypes type to the shared RegexLike so the browser typechecks against the same structural matcher.

* 🧹 refactor: Configure the file-config linear engine from a shared helper

Move the RE2 wiring out of both JS server entry points into a single
configureFileConfigRegexEngine helper exported from @librechat/api, so /api stays a thin
caller and the setup no longer has to be kept in sync across index.js and experimental.js.

Also warn loudly when compiling an endpoint's supportedMimeTypes drops every pattern (an
empty allowlist would reject all uploads), and correct the isMimeTypeSupported docstring to
say RegexLike rather than RegExp.

* fix: fail closed when every MIME pattern fails to compile

convertStringsToRegex returned [] when all configured patterns failed to
compile, and filter.ts reads an empty allowlist as no restriction, so a
restrictive config whose patterns all fail allowed every attachment.
Return a single reject-all matcher instead so every consumer fails closed.
2026-08-06 09:05:42 -04:00
..
controllers 🎟️ fix: Reconcile MCP OAuth Readiness Across Pods (#14629) 2026-08-05 19:42:26 -04:00
middleware 🔐 fix: Preserve Structured JWT Auth Context (#14652) 2026-08-06 08:12:00 -04:00
routes 🎟️ fix: Reconcile MCP OAuth Readiness Across Pods (#14629) 2026-08-05 19:42:26 -04:00
services 🎟️ fix: Reconcile MCP OAuth Readiness Across Pods (#14629) 2026-08-05 19:42:26 -04:00
utils
cleanup.js
experimental.js ⏱️ fix: Compile admin file-config MIME patterns on a linear-time engine (ReDoS) (#14555) 2026-08-06 09:05:42 -04:00
experimental.spec.js ⏱️ feat: Configurable HTTP Server Timeouts (#14481) 2026-07-28 09:10:17 -04:00
index.js ⏱️ fix: Compile admin file-config MIME patterns on a linear-time engine (ReDoS) (#14555) 2026-08-06 09:05:42 -04:00
index.metrics.spec.js
index.spec.js ⏱️ feat: Configurable HTTP Server Timeouts (#14481) 2026-07-28 09:10:17 -04:00
socialLogins.js
socialLogins.spec.js
telemetry.js
telemetry.spec.js