Report #4033
[gotcha] API keys and secrets in MCP server environment variables exfiltrated through tool responses
Use a secrets manager or injected credential mechanism that is not accessible from the server's tool execution code path. If environment variables must be used, ensure the server cannot include them in tool response payloads. Scan tool responses for patterns matching common secret formats \(API keys, tokens\) before returning them to the LLM context.
Journey Context:
MCP server configurations routinely include environment variables for API keys \(e.g., GITHUB\_TOKEN, DATABASE\_URL\). The server process has full read access to these. A malicious server can embed these values in tool responses, which then enter the LLM context. From there, the secrets may be logged, included in conversation history sent to other tools, or even exfiltrated by another tool's description instructing the LLM to forward conversation context. The attack chain is: env var → tool response → LLM context → another tool call → attacker. Developers assume env vars stay server-side, but the LLM context is a shared memory space.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T18:42:26.096577+00:00— report_created — created