Summary
LibreChat's MCP server integration up to version 0.8.3 interpolates ${VAR} placeholders in user-supplied MCP server URLs against the server's process.env during Zod schema validation.
Any authenticated user can craft a malicious MCP server configuration that causes the LibreChat server to leak sensitive environment variables (such as CREDS_KEY, CREDS_IV, JWT_SECRET, and MONGO_URI) to an attacker-controlled endpoint, enabling full compromise of cryptographic keys and database credentials without admin privileges.
Affected context
This vulnerability affects LibreChat deployments that:
- Enable the Model Context Protocol (MCP) server integration, and
- Allow authenticated (non-admin) users to configure or register MCP servers, and
- Run with sensitive secrets stored in environment variables (e.g., encryption keys, JWT secrets, database URIs).
The issue occurs when user-controlled MCP server URLs are processed and validated, and the server's environment variables are interpolated directly into those URLs before any isolation or redaction is applied.
Exploit preconditions
- Attack surface: Application's HTTP interface for authenticated users (e.g., MCP server configuration UI or API).
- Required access: Any valid user account; administrative privileges are not required.
- Trigger point: Submission or update of an MCP server configuration whose URL contains
${VAR_NAME}placeholders referencing environment variables. - Why exploitation is possible: The MCP integration resolves
${VAR}placeholders against the server'sprocess.envas part of Zod schema validation, then performs an outbound request to the attacker-controlled server, embedding the expanded secrets directly into the request URL or parameters.
Why this happens
The core issue is treating sensitive server-side configuration (environment variables) as a string substitution source for user-controlled data, without segregation of trust boundaries or redaction.
During validation of user-supplied MCP server URLs, the application interpolates ${VAR} placeholders using process.env, effectively allowing untrusted users to specify arbitrary environment variable names that will be expanded. This behavior maps to CWE-200: Information Exposure, where internal secrets are unintentionally disclosed through an externally observable channel. The problem is conceptual: mixing server secrets into user-controlled URL templates and then initiating outbound requests to attacker endpoints, leaking secrets in the process.
Potential impact
- Attackers can obtain cryptographic keys (e.g.,
CREDS_KEY,CREDS_IV) and decrypt stored credentials or sensitive data. - Attackers can steal
JWT_SECRETand forge valid authentication tokens, impersonating any user or escalating privileges. - Attackers can exfiltrate
MONGO_URIand other database credentials, enabling direct database access and full data compromise. - Attackers can potentially pivot to further infrastructure compromise by abusing leaked secrets in connected services.
- Long-term integrity and confidentiality of all data in the LibreChat instance and associated systems may be lost.
General mitigation guidance
Effective mitigation focuses on enforcing a strict separation between user-controlled configuration and server-side secrets, and removing any automatic secret interpolation in user-provided URLs.
Recommended design patterns include:
- Remove secret expansion in untrusted input: Do not resolve
${VAR}placeholders fromprocess.envin any user-supplied string, especially URLs or endpoints. - Use explicit, controlled configuration: If templating is needed, restrict variable expansion to a predefined, non-sensitive set of values (e.g., fixed base URLs), not arbitrary environment variables.
- Isolate secret handling: Keep sensitive environment variables and key material confined to internal application logic and secure configuration layers; never surface them in validation, logging, or network calls derived from user inputs.
- Apply least privilege and compartmentalization: Run the application with the minimum set of secrets and permissions necessary; separate responsibilities (e.g., use dedicated service accounts or separate configs for outbound connections).
- Harden MCP configuration flows: Treat connector definitions, plugin URLs, and similar extension points as high-risk inputs, applying additional scrutiny and security reviews to any dynamic behavior.
How teams detect issues like this
Detection should focus on identifying both the vulnerable pattern in code and any indicators of secret exfiltration at runtime.
Possible strategies include:
- Static analysis and code review:
- Search for patterns where environment variables (e.g.,
process.env.*) are concatenated or interpolated into values derived from user input, especially URLs and request targets. - Flag validation logic that performs string replacement of
${VAR}-style placeholders without strict whitelisting. - Look for outbound HTTP clients that are fed user-controlled URLs after environment-based substitution.
- Configuration and policy checks:
- Enforce policies prohibiting expansion of server secrets into user-editable templates or configuration fields.
- Use secure coding guidelines and checklists for integration points like MCP servers, plugins, and webhooks.
- Runtime monitoring:
- Monitor outbound traffic for suspicious patterns, such as secrets appearing in query strings, headers, or path segments.
- Enable logging and anomaly detection on egress traffic to detect high-entropy values or known secret patterns being sent to untrusted domains.
- Automated tooling:
- Employ secret-scanning tools that inspect logs and HTTP traces for leaked secrets.
- Integrate static analysis tools in CI/CD to detect environment-variable usage in conjunction with user-controlled data.

