ManagementRouteSecurityMiddleware Bypass via connect_to_jupyter MCP Tool (SSRF & Sandbox Hijack) and Default Wildcard CORS on /mcp
Description
ManagementRouteSecurityMiddleware Bypass via connect_to_jupyter MCP Tool (SSRF & Sandbox Hijack) and Default Wildcard CORS on /mcp in datalayer/jupyter-mcp-server (verified at commit fe0a1d4f0592).
Affected Files & Lines
jupyter_mcp_server/tools/connect_jupyter_tool.py:25-49, 54-107jupyter_mcp_server/server.py:122-198, 335-346, 1756-1801
Root-Cause Analysis
- Management Route Security Bypass via
connect_to_jupyterMCP Tool (CWE-862 / CWE-918): Injupyter_mcp_server/server.py:122-198,ManagementRouteSecurityMiddlewarerestricts/api/connectusing loopback peer verification (_is_local_peer),Hostheader validation (_is_local_hostname), localOriginenforcement, and Bearer token verification. However, the identical management operation is exposed as an LLM-callable MCP toolconnect_to_jupyter(connect_jupyter_tool.py:54-107, registered atserver.py:1756-1801), which performs an unvalidatedrequests.get(f'{jupyter_url}/api/status')(SSRF with customAuthorization: token <jupyter_token>header) and callsset_config(code_sandbox_url=...)to repoint the active code execution backend at runtime. - Wildcard CORS and Missing Origin Check on
/mcp(CWE-942):MANAGEMENT_ROUTE_PATHS(server.py:122) excludes/mcp, andCORSMiddleware(server.py:340-346) setsallow_origins=cors_origins or ['*'], allowing cross-origin pages to invoke/mcptools when no token verifier is configured.
Recommended Remediation Diff
--- a/jupyter_mcp_server/server.py
+++ b/jupyter_mcp_server/server.py
@@ -122,2 +122,2 @@
-MANAGEMENT_ROUTE_PATHS = {"/api/connect", "/api/stop", "/api/healthz"}
+MANAGEMENT_ROUTE_PATHS = {"/api/connect", "/api/stop", "/api/healthz", "/mcp"}
@@ -340,5 +340,5 @@ class MCPServerWithCORS(MCPServer):
app.add_middleware(
CORSMiddleware,
- allow_origins=cors_origins or ["*"],
+ allow_origins=cors_origins or ["http://localhost", "http://127.0.0.1"],