LibreChat/api/server/middleware
Marco Beretta 2ad2c1c14b
🔑 perf: Cache JWT Users and Batch Auth-Path Reads (#17466)
* perf: Serve JWT Bearer User Lookups From the Auth User Cache

* perf: Batch Agent Permission Reads on the File Access Path

* perf: Remember a Loaded Google Service Key Across Endpoint Config Reads

* perf: Run Independent Startup, Tool, Skill and Erasure Reads Concurrently

* fix: Drop JWT User Cache Writes That Race a User Mutation

Confirm each cache write with a second read and evict when the user changed,
so an in-flight lookup cannot repopulate an entry a credential change just
evicted. The cache mode now arrives through the loader dependencies.

* refactor: Move Agent Skill Access Reads Into packages/api

The chat-completions and Responses controllers call loadSkillAccess instead of
orchestrating the three reads in CJS. The preview route spec mocks the batched
file access helper the middleware now calls.

* test: Cover Agent File Access, JWT Bursts and Remote Skill Reads End to End

* fix: Serve a Cached JWT User Only While Its updatedAt Is Current

A cache hit now reads the stored updatedAt and deletion fence instead of the
fence alone, so a document cached from a read that raced a user mutation is
never served, even when the write landed after that mutation's eviction.

* refactor: Move Startup Migration Checks Into packages/api

* refactor: Inject the Startup Migration Checks Instead of Mongoose Models

* fix: Serve Cached OpenID Users Only While Their updatedAt Is Current

Moves the freshness check into getCurrentCachedAuthUserDoc and uses it on the
OpenID bearer path as well as the local JWT one, so a document cached from a
read that raced a credential or role change is never served there either.

Fixes berry-13/LibreChat#432

* fix: Compare Authorization Fields on Every Auth Cache Hit

updatedAt has millisecond resolution, so the freshness read also compares the
token retirement stamps, role, tenant and two-factor state.

* fix: Annotate the Auth Freshness Projection for Isolated Declarations

* perf: Reuse the OpenID Cache Freshness Read for Deletion Admission

A cache hit already proved the deletion fence is clear, so only users read from
the database take the separate fence query.

* refactor: Keep the OpenID Cache Freshness and Fence Decisions in packages/api

* test: Exercise JWT Cache Freshness Against Real User Methods in MongoDB

* fix: Stamp the JWT User Lookup So the Cache Write Fence Applies

* fix: Reload a Google Service Key File When It Changes or Disappears

The availability check remembers a loaded key only while the file's mtime and
size are unchanged, and fetches URL sources every time as before.

* fix: Recheck a Service Key File After a Permission Change
2026-10-30 00:24:08 +01:00
..
__tests__ 📃 fix: Enforce Terms Acceptance on the Server and Mark Backfilled Consent (#17063) 2026-10-14 17:45:28 +02:00
accessResources 🔑 perf: Cache JWT Users and Batch Auth-Path Reads (#17466) 2026-10-30 00:24:08 +01:00
assistants ✒️ fix: Bind Assistant Avatar Updates to Authorized Owners (#17391) 2026-10-24 10:16:16 +02:00
config 💓 feat: Keep Quiet Chat Streams Alive Behind Idle-Timeout Proxies (#16904) 2026-10-09 10:29:45 +02:00
limiters ⛲ feat: Resolve Native and Langfuse Prompts by Source (#16909) 2026-10-24 13:47:52 +02:00
roles 🪦 refactor: Remove Dead Legacy API Modules and Root Tooling (#17114) 2026-10-15 12:25:24 +02:00
spec ✒️ fix: Bind Assistant Avatar Updates to Authorized Owners (#17391) 2026-10-24 10:16:16 +02:00
validate
abortMiddleware.js 🔒 fix: Restrict Stop to the Generation's Owner and Contain S3 Ingest Stream Errors (#17256) 2026-10-19 15:56:03 +02:00
abortMiddleware.spec.js 🔒 fix: Restrict Stop to the Generation's Owner and Contain S3 Ingest Stream Errors (#17256) 2026-10-19 15:56:03 +02:00
abortRun.js
blockRetiredSetupToken.js 🔐 feat: Enforce Required Two-Factor Authentication (#14731) 2026-10-01 23:39:51 +02:00
buildEndpointOption.js 📌 fix: Keep the Composer Thinking Level for the Rest of the Conversation (#17497) 2026-10-28 19:11:07 +01:00
buildEndpointOption.spec.js 🚡 fix: Restore Enforced Model Specs for Agent Continuations (#17229) 2026-10-22 11:43:19 +02:00
canAccessSharedLink.js
canDeleteAccount.js
canDeleteAccount.spec.js
checkBan.js
checkBan.spec.js
checkDomainAllowed.js
checkInviteUser.js
checkInviteUser.spec.js
checkPeoplePickerAccess.js
checkSharePublicAccess.js
checkSharePublicAccess.spec.js
denyRequest.js 📔 feat: Preserve Owner Text During PII Redaction (#16311) 2026-10-02 11:43:10 -04:00
denyRequest.privateText.spec.js 📔 feat: Preserve Owner Text During PII Redaction (#16311) 2026-10-02 11:43:10 -04:00
error.js
error.spec.js
index.js 🪦 refactor: Remove Dead Legacy API Modules and Root Tooling (#17114) 2026-10-15 12:25:24 +02:00
logHeaders.js 🙈 fix: Mask Emails and Drop Personal Identifiers From Logs (#17048) 2026-10-15 15:54:27 +02:00
messageValidation.js
moderateText.js ⏱️ fix: Bound Outbound Calls Made Inside a Request (#17263) 2026-10-21 19:10:13 +02:00
moderateText.spec.js ⏱️ fix: Bound Outbound Calls Made Inside a Request (#17263) 2026-10-21 19:10:13 +02:00
noIndex.js
oauthNavigation.js
optionalJwtAuth.js 🔐 feat: Enforce Required Two-Factor Authentication (#14731) 2026-10-01 23:39:51 +02:00
optionalJwtAuth.spec.js 🔐 feat: Enforce Required Two-Factor Authentication (#14731) 2026-10-01 23:39:51 +02:00
optionalShareFileAuth.js 🔐 feat: Enforce Required Two-Factor Authentication (#14731) 2026-10-01 23:39:51 +02:00
optionalShareFileAuth.spec.js 🔐 feat: Enforce Required Two-Factor Authentication (#14731) 2026-10-01 23:39:51 +02:00
requireJwtAuth.js 📃 fix: Enforce Terms Acceptance on the Server and Mark Backfilled Consent (#17063) 2026-10-14 17:45:28 +02:00
requireLdapAuth.js
requireLocalAuth.js
requireSameOrigin.js
setHeaders.js
setTwoFactorTempUser.js 🔐 feat: Enforce Required Two-Factor Authentication (#14731) 2026-10-01 23:39:51 +02:00
specs.spec.js 🚡 fix: Restore Enforced Model Specs for Agent Continuations (#17229) 2026-10-22 11:43:19 +02:00
uaParser.js
validateEmailLogin.js
validateImageRequest.js 🪦 refactor: Remove Dead Legacy API Modules and Root Tooling (#17114) 2026-10-15 12:25:24 +02:00
validateMessageReq.js
validateModel.js
validatePasswordReset.js
validateRegistration.js