fix: reject proxied pinned web fetches
This commit is contained in:
@@ -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
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@@ -147,6 +147,19 @@ async def test_safe_redirect_requests_use_independent_pinned_dns_concurrently(mo
|
||||
assert calls == {"a.example": 2, "b.example": 2}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_web_fetch_rejects_proxy_because_upstream_dns_cannot_be_pinned():
|
||||
tool = WebFetchTool(proxy="http://proxy.example:8080")
|
||||
|
||||
with patch("nanobot.security.network.socket.getaddrinfo", _fake_resolve_public):
|
||||
result = await tool.execute(url="https://example.com/page")
|
||||
|
||||
data = json.loads(result)
|
||||
assert "error" in data
|
||||
assert "proxy" in data["error"].lower()
|
||||
assert "dns-pinned" in data["error"].lower()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_web_fetch_can_skip_jina_and_use_custom_user_agent(monkeypatch):
|
||||
tool = WebFetchTool(
|
||||
|
||||
Reference in New Issue
Block a user