Summary
LibreChat's MCP OAuth callback endpoint fails to verify that the user completing an OAuth flow is the same user who initiated it.
This allows an attacker to trick a victim into completing an OAuth authorization sequence and have the victim's tokens bound to the attacker's LibreChat account, enabling takeover of the victim's MCP-linked services.
Affected context
The vulnerability occurs in LibreChat deployments using the Model Context Protocol (MCP) integrations with third-party identity or service providers (e.g., Atlassian, Outlook).
It affects instances where:
- Users can initiate OAuth flows for MCP-linked services, and
- The OAuth callback endpoint stores access/refresh tokens based solely on the flow identifier, without verifying session identity or login state.
The risk is present when users can be induced to click on attacker-provided OAuth authorization URLs.
Exploit preconditions
- Attack surface: Public-facing MCP OAuth callback endpoint on a LibreChat instance.
- Required attacker access: Ability to create an account on the target LibreChat instance and initiate an OAuth flow for an MCP integration.
- Victim involvement: Victim must be willing (or tricked) into following a crafted authorization URL and completing the OAuth consent with the third-party provider while logged into that provider.
- Trigger point: When the identity provider redirects back to the LibreChat OAuth callback endpoint with authorization codes/tokens.
- Why exploitation is possible: The callback logic associates the returned OAuth tokens with the user who initiated the flow, without confirming that the browser/session completing the flow is the same user or even authenticated to the intended LibreChat account.
Why this happens
This issue stems from missing authentication and improper binding between the OAuth authorization response and the authenticated user session in LibreChat.
Instead of validating that:
- a browser accessing the OAuth callback is currently logged into LibreChat, and
- the logged-in user matches the user who initiated the OAuth flow,
the implementation assumes that whoever completes the OAuth redirect can safely have tokens stored against the original initiator's account.
This maps to CWE-306: Missing Authentication for Critical Function, as a critical operation—binding OAuth tokens to an account—is performed without enforcing proper authentication and session correlation at the callback stage.
Potential impact
- Attacker may gain access to a victim's MCP-linked services (e.g., Atlassian, Outlook) via stolen OAuth tokens.
- Attacker could read, modify, or delete data in third-party services tied to the victim's identity.
- Attacker can act as the victim in integrated systems, potentially escalating to broader organizational compromise depending on the privileges of the victim's external accounts.
- Long-lived refresh tokens, if present, can allow persistent access even if the immediate session is invalidated.
General mitigation guidance
Robust mitigation focuses on securing OAuth flows and tightening identity binding:
- Require an authenticated LibreChat session at the OAuth callback and verify that the logged-in user matches the user who initiated the OAuth flow.
- Use server-side state parameters or correlation identifiers tied to the user's session and validate them at the callback before storing tokens.
- Treat token storage and account linking as a sensitive operation that demands explicit user identity confirmation and CSRF protection.
- Minimize token scope and lifetime; prefer least-privilege access and short-lived tokens where supported.
- Clearly separate initiation and completion of OAuth flows so that tokens are only bound after all identity checks pass.
How teams detect issues like this
Detection efforts can focus on both code-level and behavioral indicators:
- Static analysis / code review:
- Look for OAuth callback handlers that store tokens or bind accounts without verifying the current authenticated user.
- Flag flows that rely solely on client-side parameters (e.g., query strings) to decide which account to associate tokens with.
- Review use of OAuth
stateand session identifiers to ensure they are validated and bound to the initiator's session. - Runtime and logging:
- Monitor logs for OAuth flows where the initiating user and the logged-in user at callback differ, or where callbacks occur without a valid session.
- Alert on unusual patterns such as a single LibreChat account collecting tokens for multiple distinct third-party identities.
- Policy and CI/CD checks:
- Enforce security design reviews for new or modified authentication/OAuth integration code paths.
- Integrate automated review tools that highlight authentication/authorization gaps around callback endpoints and token handling.

