fix(mcp): validate server URLs against SSRF before connecting (#662) - #667
fix(mcp): validate server URLs against SSRF before connecting (#662)#667Tiktokaiagent wants to merge 2 commits into
Conversation
|
Hey @Tiktokaiagent! I'm also contributing here (PRs #546, #595, #597). Been through ~15+ PRs and learned a lot the hard way. Thought I'd share what I've picked up: What you're doing right:
Tips from my 15+ closed PRs:
Hope this helps! Let's both get better at landing PRs here. |
dfef117 to
f2d615c
Compare
|
Hey @kyveni, thanks for the tips — really appreciate you taking the time to share what you've learned! Great news — I'd already started implementing most of what you mentioned right before your comment landed: ✅ Regression tests — just pushed 2 tests for PR #667 that verify 169.254.169.254 is rejected and valid URLs pass through (no more monkeypatch-only testing) Point #5 (rebase to upstream/main, not origin/main) is especially useful — just rebased all 7 PRs after today's v2026.9.1 release. Appreciate the help! Let's both land some PRs here. 🚀 |
|
Hey @andreapn, quick heads-up — issue #662 (MCP SSRF validation) is still unlabelled and unassigned. All 3 affected files are patched and rebased to latest main:
35 additions across 3 files, 0 deletions. Could #662 use a triage label when you get a moment? 🙏 |
e6fb17d to
4cc6e2d
Compare
4cc6e2d to
3d19488
Compare
|
Issue #662 has been fixed by #897, which is now merged into #667 used the full Thanks for the contribution — closing this one as superseded. |
Summary
MCP SSE and Streamable HTTP transports connect to
MCPServerConfig.urlvia httpx with no SSRF validation. Every other URL-fetching path (web_fetch,http_request, skill-hub) callsvalidate_http_url_for_fetch()before connecting — the MCP transport skipped this entirely.Impact
Cloud metadata endpoints (169.254.169.254), private ranges, and unsupported schemes are reachable through MCP server config. An attacker who controls or injects the MCP server URL can exfiltrate instance credentials or redirect agent traffic to internal hosts.
Changes
src/agentos/mcp/sse.py: Addedvalidate_http_url_for_fetch(self.config.url)inMCPSSEClient.connect()src/agentos/mcp/streamable_http.py: Addedvalidate_http_url_for_fetch(self.config.url)inMCPStreamableHTTPClient.connect()tests/test_mcp/test_streamable_http_client.py: Monkeypatch SSRF validation in the transport-cleanup test that usesexample.test(which does not resolve)Tests
Fixes #662