LibreChat/api/server/controllers
Marco Beretta 18b6937da3
🧯 fix: Outlast Failed Auth Cache Eviction on Credential Changes (#16435)
* fix: outlast failed auth cache eviction on credential changes

A credential change committed to MongoDB could report success while a
cached auth user document without the new credentialsChangedAt stayed
readable, so an old OpenID access token kept authorizing until the
cache TTL. The Redis-backed auth cache swallowed every failure (Keyv and
KeyvRedis resolve a failed GET as a miss and a failed DEL as a no-op), and
the eviction helpers stopped at the first error.

- The AUTH_USER_DOC namespace opts into throwOnErrors so a failed read or
  delete is visible; every caller of that namespace already catches.
- evictAuthUserDocs attempts every delete even when another fails and
  reports whether a document may still be served; the data-schemas and
  packages/api invalidation paths share it.
- updateUser waits out AUTH_USER_DOC_CACHE_TTL_MS before returning a
  credential change whose eviction was incomplete, so the change is only
  confirmed once no pre-change document can be served. Other updates stay
  best effort, and later revocations are delayed, never skipped.

* fix: record the reverse index before caching an auth user document

A document written before its reverse-index entry was cached without an
index naming it when the index write failed, so eviction could not find
it. Write the index first with a TTL that outlives the documents it names,
and skip the document when the index write fails.

* test: keep real data-schemas helpers in the pinned order spec

* fix: settle the auth cache after revoking reset credentials

Waiting out the cache TTL inside updateUser held the reset before its
session and passkey revocations, so a live refresh token or passkey could
mint an access token issued after credentialsChangedAt during the wait.
updateUser is best effort again; awaitAuthUserDocEviction retries the
eviction and waits one TTL only when it is still incomplete, and both the
web reset controller and the reset CLI call it after revoking sessions and
passkeys, before confirming the reset.

* fix: settle the credential barrier with a margin and on CLI revocation errors

Timers can fire a millisecond early, so the eviction barrier now waits the
cache TTL plus a 100 ms margin. The reset CLI also settles the barrier when
revoking passkeys or sessions throws, since the password is already changed.

* fix: treat an auth cache that cannot delete as not evicted

* fix: keep the reverse index until every document it names is evicted

A failed eviction still deleted the reverse index, so the credential
barrier's retry found no index and reported the cache clear while the
documents an unreadable index or a failed delete left behind stayed
cached. The index is now deleted only after it was read and every document
it names is gone, so a retry can still find what remains.

* fix: treat a malformed auth reverse index as unreadable

* fix: treat a reverse index with a non-string entry as unreadable
2026-09-28 21:21:53 +02:00
..
__tests__ 🔑 feat: Passkey Authentication with WebAuthn Sign-In and Management (#14715) 2026-09-23 13:19:32 -04:00
agents 🛶 chore: Merge Latest Dev Fixes into Canary Sync 2026-09-28 01:42:05 +00:00
assistants 🔔 feat: Unseen Reply Indicators, Reply Notifications, and Mark as Unread (#15025) 2026-09-23 13:19:32 -04:00
auth ⚙️ feat: Make the Per-User Passkey Cap Configurable (#16259) 2026-09-25 11:34:06 +02:00
AuthController.js 🧯 fix: Outlast Failed Auth Cache Eviction on Credential Changes (#16435) 2026-09-28 21:21:53 +02:00
AuthController.spec.js 🧯 fix: Outlast Failed Auth Cache Eviction on Credential Changes (#16435) 2026-09-28 21:21:53 +02:00
avatar.contentFilter.spec.js 🛍️ fix: Discover Managed Agents in Marketplace Search (#16324) 2026-09-24 22:48:56 -04:00
Balance.js
Balance.spec.js
EndpointController.js
FavoritesController.js
FavoritesController.spec.js
mcp.js 🫗 fix: Bound MCP App Responses and In-Flight Work (#16300) 2026-09-24 22:53:15 -04:00
mcpApps.js 🫗 fix: Bound MCP App Responses and In-Flight Work (#16300) 2026-09-24 22:53:15 -04:00
mcpApps.test.js 🫗 fix: Bound MCP App Responses and In-Flight Work (#16300) 2026-09-24 22:53:15 -04:00
ModelController.js ⚡ perf: Reduce Agent Chat Startup Latency (#14423) 2026-07-25 07:58:20 -04:00
ModelController.spec.js ⚡ perf: Reduce Agent Chat Startup Latency (#14423) 2026-07-25 07:58:20 -04:00
PermissionsController.js 🚥 fix: Preserve Insights With Guarded ACL Role Updates (#16170) 2026-09-21 23:40:52 -04:00
PluginController.js 🙋 feat: ask_user_question - agent-initiated questions with durable pause/resume (#14139) 2026-07-08 15:31:05 -04:00
PluginController.spec.js 🙋 feat: ask_user_question - agent-initiated questions with durable pause/resume (#14139) 2026-07-08 15:31:05 -04:00
SkillStatesController.js
TokenConfigController.js 🗂️ fix: Scope Token Config Cache (#13770) 2026-06-15 15:25:19 -04:00
tools.js ⏳ fix: Separate Temporary and General Chat Retention (#15734) 2026-09-08 11:22:54 -04:00
TwoFactorController.js
UserController.js 🔑 feat: Passkey Authentication with WebAuthn Sign-In and Management (#14715) 2026-09-23 13:19:32 -04:00
UserController.spec.js 🔑 feat: Passkey Authentication with WebAuthn Sign-In and Management (#14715) 2026-09-23 13:19:32 -04:00