AstrBot icon indicating copy to clipboard operation
AstrBot copied to clipboard

[Security] MCP Client core: SSRF and environment variable leakage beyond existing CVE-2026-15500/15501

Open Correctover opened this issue 4 months ago • 3 comments

Summary

I've identified 4 vulnerabilities in AstrBot v4.25.2's MCP client core module. VULN-1 and VULN-2 are separate code paths from the recently disclosed CVE-2026-15500 and CVE-2026-15501, meaning those CVEs' fixes alone won't address these issues.

I want to acknowledge that AstrBot has made significant progress in MCP security hardening (STDIO command allowlist, denylist, shell metacharacter blocking, inline code prevention). The findings below are in the areas that still need attention.

# Severity Type Location Relation to existing CVE
1 HIGH SSRF (Client Core) mcp_client.py → _quick_test_mcp_connection() / _do_connect() Separate code path from CVE-2026-15501
2 HIGH Environment Variable Leakage mcp_client.py → _merge_environment_variables() New issue
3 MEDIUM npx Arbitrary Package Execution mcp_client.py → _validate_stdio_args() New issue
4 MEDIUM MCP Response Content Injection mcp_client.py → MCPTool.call() New issue

I'm using Correctover, an MCP runtime security verification engine, to systematically audit MCP integrations across the ecosystem.


VULN-1: MCP Client Core HTTP/SSE SSRF (HIGH)

File: astrbot/core/agent/mcp_client.py Functions: _quick_test_mcp_connection(), _do_connect()

CVE-2026-15501 addressed SSRF in the dashboard's test_mcp_connection endpoint (astrbot/dashboard/routes/tools.py). However, the MCP client core has a separate code path that also makes HTTP/SSE requests to user-configured URLs without any SSRF validation.

_quick_test_mcp_connection() runs before every MCP server connection:

async def _quick_test_mcp_connection(config: dict) -> tuple[bool, str]:
    url = cfg["url"]  # no SSRF validation
    async with aiohttp.ClientSession() as session:
        async with session.post(url, ...) as response:  # no URL check
            ...
        async with session.get(url, ...) as response:  # no URL check
            ...

_do_connect() then connects to the URL via sse_client() or streamable_http_client():

self._streams_context = sse_client(url=cfg["url"], ...)  # no URL validation
self._streams_context = streamable_http_client(url=cfg["url"], ...)  # no URL validation

No validation against private IP ranges (RFC 1918), loopback, link-local, or cloud metadata endpoints.

Attack scenario:

  1. Compromised dashboard access (e.g., via CVE-2025-55449 JWT bypass) allows configuring a malicious MCP URL
  2. Every connection to this MCP server triggers requests to attacker-controlled or internal network addresses
  3. Cloud metadata (169.254.169.254), internal services (10.x, 172.16.x), or localhost endpoints become accessible

Note: Even if CVE-2026-15501 is patched in the dashboard endpoint, the core client path remains unprotected.

Suggested fix: Add URL validation against private/reserved IP ranges in _quick_test_mcp_connection() and _do_connect(), ideally as a shared utility function.


VULN-2: STDIO Environment Variables Full Leakage (HIGH)

File: astrbot/core/agent/mcp_client.py Functions: _prepare_stdio_env(), _merge_environment_variables()

While the STDIO command allowlist is a good security measure, environment variables are leaked in full to MCP subprocesses.

On Windows, _merge_environment_variables() explicitly inherits ALL os.environ:

def _merge_environment_variables(env: dict) -> dict:
    merged = env.copy()
    for sys_key, sys_value in os.environ.items():  # ALL env vars
        sys_key_lower = sys_key.lower()
        if sys_key_lower not in user_keys_lower:
            merged[sys_key] = sys_value
    return merged

On non-Windows, when cfg has no env field, mcp.StdioServerParameters(**cfg) inherits the parent process environment by default (standard mcp library behavior).

Impact: All API keys are leaked to MCP subprocesses: OPENAI_API_KEY, ANTHROPIC_API_KEY, GITHUB_TOKEN, AZURE_OPENAI_API_KEY, etc. Combined with allowed commands like npx @package (see VULN-3), these secrets can be exfiltrated.

Suggested fix:

  • Default to passing NO environment variables to MCP subprocesses
  • Only pass explicitly configured env fields from the MCP config
  • Filter sensitive patterns: *_KEY, *_SECRET, *_TOKEN, *_PASSWORD
  • At minimum: pass PATH, HOME, NODE_PATH only

VULN-3: npx Arbitrary Package Execution (MEDIUM)

File: astrbot/core/agent/mcp_client.py Function: _validate_stdio_args()

npx is in the command allowlist (appropriate — many MCP servers are launched via npx), but its arguments have no restrictions. An attacker can configure:

{"command": "npx", "args": ["@malicious/scope@latest"]}

This downloads and executes arbitrary npm packages. Unlike the inline code flags that are properly blocked (-c, -e), npx package execution is unrestricted.

Impact: Combined with VULN-2 (environment leakage), an attacker can execute arbitrary npm packages that read all API keys from the environment.

Suggested fix:

  • Add a package allowlist for npx (similar to the command allowlist)
  • Or require local file paths for npx packages
  • Or add ASTRBOT_MCP_NPX_ALLOWED_PACKAGES env var

VULN-4: MCP Tool Response Content Injection (MEDIUM)

File: astrbot/core/agent/mcp_client.py Class: MCPTool

MCP server responses (CallToolResult) are passed directly to the agent without any content safety filtering:

class MCPTool(FunctionTool, Generic[TContext]):
    async def call(self, context, **kwargs) -> mcp.types.CallToolResult:
        return await self.mcp_client.call_tool_with_reconnect(
            tool_name=self.mcp_tool.name,
            arguments=kwargs,
            read_timeout_seconds=...,
        )

A malicious or compromised MCP server can inject:

  • Prompt injection payloads in tool response text
  • Malicious URLs in resource content
  • Oversized data for memory exhaustion

Suggested fix:

  • Add content length limits
  • Consider a content safety filter layer for MCP responses
  • Log suspicious patterns (e.g., system instruction mimicry)

What AstrBot Does Well

To be fair, AstrBot has done significant security hardening that most MCP integrations lack:

  • ✅ STDIO command allowlist with env-configurable extension
  • ✅ Comprehensive command denylist (bash, sh, curl, wget, ssh, sudo, etc.)
  • ✅ Shell metacharacter detection in command field
  • ✅ Inline code prevention (Python -c, JS -e/--eval)
  • ✅ Docker argument hardening
  • ✅ Control character validation in args

These measures significantly raise the bar for direct RCE. The vulnerabilities above are in the areas that complement these existing protections.


Environment

  • AstrBot version: 4.25.2 (latest)
  • Python: 3.10+
  • Identified via: Correctover MCP runtime security audit

Suggested Priority

VULN-1 (core SSRF) and VULN-2 (env leakage) should be addressed first. VULN-3 and VULN-4 are medium severity.

I'm happy to submit PRs with fixes if the maintainers are interested.

Correctover avatar Jul 17 '26 12:07 Correctover

老外?

mjy1113451 avatar Jul 17 '26 13:07 mjy1113451