AIStudio2API
AIStudio2API copied to clipboard
[Security/Bug] connectMCP lacks SSRF/IP validation and leaks http.Transport connections, while resolveMCPTools clobbers ServerSideInvocations for google_search
发生了什么 / What happened
Summary
internal/api/mcp_tools.go has three concrete bugs still present in v0.3.14 (ae59eba):
- Unvalidated SSRF with attacker-controlled headers (
lines 163-190): Unlikeinternal/api/remote_media.go(which blocks loopback, private, link-local, and multicast IPs viacheckRemoteMediaHost/checkRemoteMediaAddress),connectMCPaccepts arbitraryserver.URLandserver.Headersfrom public API requests (/v1/responses,/v1/messages) and dials directly using a clonedhttp.DefaultTransportwith no scheme/IP validation and no HTTP client timeout. WhenADMIN_AUTH_ENABLED=false(default local mode), a caller can pass"server_url": "http://127.0.0.1:<port>/api/control/stop"(orhttp://169.254.169.254/...), causingAIStudio2APIto issue loopbackPOSTrequests with noOrigin/Sec-Fetch-Siteheaders (bypassingloopbackMiddleware+sameOriginMiddleware) and reflect connection/HTTP errors back in the 400 response. - Leaked
http.Transportidle connections (line 164): EverylistMCPTools/callMCPToolclones a brand-newhttp.DefaultTransportand never callsbase.CloseIdleConnections()whensession.Close()runs. resolveMCPToolsoverwritesServerSideInvocations(lines 157-159):
If a request enables bothrequest.Tools.MCPServers = servers request.Tools.ToolConfig.ServerSideInvocations = len(servers) > 0web_search(google_search) and an MCP server whoseread_only/disabled_toolsfilter leaveslen(servers) == 0, line158overwritesServerSideInvocationsfromtruetofalse, silently droppinggoogle_searchserver-side tool invocations/results.
Suggested Fix
- Reuse the
remote_media.goSSRF guard (http/httpsonly,checkRemoteMediaHost,DialContext.Control/CheckRedirect, bounded timeout) when dialing MCP servers directly withoutEgressProxy, and callbase.CloseIdleConnections()when closing the MCP session. - In
resolveMCPTools, preserveServerSideInvocationswhengoogle_search(orGoogleSearch/FileSearch) is enabled.
版本 / Version
v0.3.14
每人最多同时打开 3 个 Issue,这个 Issue 已自动关闭。请等已有的 Issue 处理完再提,或把内容补充到已有的 Issue 里。
Each user can have at most 3 open issues at a time, so this one was closed automatically. Please wait until your existing issues are resolved, or add this to one of them.