fix: reject proxied pinned web fetches

This commit is contained in:
hamb1y
2026-07-07 15:40:53 +08:00
committed by Xubin Ren
parent 97e3b360c2
commit b68ae4f9bc
5 changed files with 38 additions and 12 deletions
+10
View File
@@ -2,6 +2,7 @@
from __future__ import annotations
import asyncio
import socket
from unittest.mock import MagicMock, patch
import pytest
@@ -41,6 +42,15 @@ async def test_probe_uses_default_port_for_http():
assert await _probe_http_url("http://unreachable-host.test/mcp") is False
@pytest.mark.asyncio
async def test_probe_rejects_public_name_resolving_to_loopback():
def _resolver(hostname, port, family=0, type_=0):
return [(socket.AF_INET, socket.SOCK_STREAM, 0, "", ("127.0.0.1", 0))]
with patch("nanobot.security.network.socket.getaddrinfo", _resolver):
assert await _probe_http_url("http://example.com:8765/mcp") is False
# ---------------------------------------------------------------------------
# connect_mcp_servers skips unreachable HTTP servers
# ---------------------------------------------------------------------------