/

CVE-2025-41258

Severity:

HIGH RISK

(8.0)

Improper Access Control in LibreChat RAG API JWT Secret

CVE-2025-41258

Analyzed

Vulnerability type

Category:

Improper Access Control

CWE:

CWE-284

Impact:

Authentication Bypass of Service-Level RAG API Controls

Severity:

HIGH RISK

(8.0)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

LibreChat 0.8.1-rc2 reuses the same JWT secret for both regular user sessions and the Retrieval-Augmented Generation (RAG) API, weakening isolation between user-facing authentication and service-level authentication.

If an attacker can obtain or forge a valid user JWT, they may be able to interact with the RAG API as if they possessed a dedicated service credential, bypassing intended service-level access controls.

Affected context

This vulnerability occurs in LibreChat deployments that:

  • Run version 0.8.1-rc2
  • Use JSON Web Tokens (JWT) for user session management
  • Expose a RAG API that is expected to be protected by its own service-level authentication
  • Configure a single shared JWT secret for both user sessions and the RAG API

Under these conditions, boundaries between end-user authentication and internal/service authentication become blurred, reducing the effectiveness of API-level authorization.

Exploit preconditions

  • Attack surface: LibreChat RAG API endpoints that rely on JWT-based authentication
  • Required access: Ability to obtain, intercept, or forge a valid user JWT (e.g., via compromised account, XSS, stolen tokens, or other weaknesses)
  • Trigger point: Presentation of a user JWT to the RAG API where a distinct service credential or API-specific token should be required
  • Why exploitation is possible: The same cryptographic secret validates both user session tokens and RAG API tokens, so the API cannot reliably distinguish between end-user and service-level credentials.

Why this happens

The underlying issue is a failure to enforce proper separation of authentication domains, aligning with CWE-284: Improper Access Control.

LibreChat uses a single JWT signing secret for both user sessions and the RAG API, effectively treating tokens intended for one trust boundary as valid in another.

This breaks the principle of least privilege and compartmentalization: credentials intended for end-user browser sessions become usable as higher-privilege or differently scoped credentials for backend-like RAG operations.

The insecure pattern is the reuse of shared cryptographic material (JWT secret) across distinct authentication roles and services without explicit scoping or audience restrictions.

Potential impact

  • Attackers may be able to call RAG API endpoints using user tokens instead of dedicated service credentials.
  • RAG operations that should be restricted to trusted services or specific roles could be triggered by ordinary users.
  • Unauthorized access to RAG backends, knowledge bases, or augmented data sources may occur.
  • Escalation of privileges within the application's data access layer is possible, depending on how RAG responses are used.
  • Abuse of infrastructure resources (e.g., excessive RAG queries, model usage) leading to denial of service or cost overruns.

General mitigation guidance

Effective mitigation focuses on strong isolation of authentication secrets and scopes:

  • Use distinct JWT signing secrets (or key pairs) for different authentication domains such as user sessions and internal/service APIs.
  • Introduce explicit token scoping using claims like aud, iss, and scope so services reject tokens not intended for them.
  • Apply role- and permission-based authorization checks on RAG endpoints, ensuring they do not rely solely on token validity.
  • Limit RAG API exposure, preferring private network paths or API gateways that enforce separate credentials and policies.
  • Follow least-privilege design, ensuring that user-level tokens cannot implicitly grant access to higher-trust services.

How teams detect issues like this

Detection can be approached at both configuration and code levels:

  • Review application configuration for reuse of the same JWT secret across multiple subsystems (user auth, admin APIs, internal APIs).
  • During code review, flag patterns where different logical services verify JWTs using shared keys without audience/scope checks.
  • Use static analysis or policy-as-code (e.g., Open Policy Agent, custom linters) to enforce that each service/API has its own key material or validation rules.
  • Monitor RAG API logs for unexpected token audiences, unusual calling patterns from user contexts, or spikes in usage originating from user-facing paths.
  • Incorporate automated security tests that attempt to use user session tokens against service-only endpoints to validate isolation.

Sources

SourceLink
github.comgithub.com/danny-avila/LibreChat
github.comgithub.com/sbaresearch/advisories/tree/public/2025/SBA-ADV-20251205-01_LibreChat_RAG_API_Authentication_Bypass

Frequently asked

questions

Yes. If an attacker can obtain or generate a valid user JWT, they can attempt to use it directly against the RAG API over the network, without needing local access to the server.

They need access to a valid user token or the ability to sign tokens with the shared secret. This could arise from compromised user accounts, token theft, or other application-layer issues that expose JWTs.

Separate authentication concerns by using distinct JWT secrets or key pairs for each logical service, and strictly verify token audience, issuer, and scopes on the RAG API so only appropriately scoped tokens are accepted.

Adopt a service-oriented authentication design where each API has its own credentials and clear trust boundaries, enforce least privilege with role- and scope-based claims, and include configuration/key separation checks as part of security reviews and CI pipelines.

Find out what's already
exploitable in your codebase.