Skip to content

HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.

Checked connections: local sockets, real limits, and plugin vendors (#434)

github-actions[bot]822550ea8847
diff --git a/gateway/app.py b/gateway/app.py
index f22179ba..eed3f6e8 100644
--- a/gateway/app.py
+++ b/gateway/app.py
@@ -11075,6 +11075,8 @@ async def _sql_peer_check(addr: str) -> str | None:
normal case there, as it is for the check made when the connection is saved."""
if _pool_is_local():
return None
+ if not addr:
+ return "the address it reached could not be read"
try:
return "it is on a private, local or metadata network" if _ip_internal(addr) else None
except ValueError:
@@ -11093,15 +11095,26 @@ def _checked_http(always: bool = False) -> httpx.AsyncClient:
the name itself, and the check would be about the proxy."""
c = _checked_clients.get(always)
if c is None:
- transport = httpx.AsyncHTTPTransport()
- transport._pool._network_backend = _CheckedNetwork(always)
+ # Limits belong to the transport: httpx applies a client's own only to a transport it builds.
c = _checked_clients[always] = httpx.AsyncClient(
- transport=transport, follow_redirects=False,
- timeout=httpx.Timeout(connect=30, read=600, write=120, pool=60),
- limits=httpx.Limits(max_connections=200, max_keepalive_connections=40))
+ transport=_checked_transport(always, httpx.Limits(max_connections=200, max_keepalive_connections=40)),
+ follow_redirects=False, timeout=httpx.Timeout(connect=30, read=600, write=120, pool=60))
return c
+def _checked_transport(always: bool, limits: httpx.Limits | None = None) -> httpx.AsyncHTTPTransport:
+ transport = httpx.AsyncHTTPTransport(limits=limits or httpx.Limits())
+ transport._pool._network_backend = _CheckedNetwork(always)
+ return transport
+
+
+# The plugin vendors' client (plugs_plane.client) opens its connections the same way: a plug's
+# address can be one a member typed (an InsForge backend), and its answer goes back to the agent.
+# On a shared deployment that was a way into the private network; GitHub, Vercel and Microsoft are
+# public and pass the same check.
+plugs_plane.checked_transport = lambda: _checked_transport(False)
+
+
async def _mcp_list_tools(url: str, token: str) -> dict:
"""Probe a remote MCP server: initialize → notifications/initialized → tools/list. Returns
{ok, server, tools:[{name,description}]} or {ok:false, error}. Used by the config UI's
diff --git a/gateway/plugs_plane.py b/gateway/plugs_plane.py
index ea08f04b..188016d5 100644
--- a/gateway/plugs_plane.py
+++ b/gateway/plugs_plane.py
@@ -38,10 +38,15 @@ TEXT_CAP = 200_000 # the most text one tool result carries back to t
# Tests set an httpx transport here so every vendor call is exercised and nothing is spent.
transport: httpx.BaseTransport | None = None
+# Set by the gateway: a transport whose connections go only to an address it classified in the
+# same step, so a vendor address a member typed cannot reach the private network on a shared
+# deployment, a redirect included (every connection, redirected or not, goes through it).
+checked_transport = None
def client() -> httpx.AsyncClient:
- return httpx.AsyncClient(timeout=CALL_TIMEOUT_S, transport=transport, follow_redirects=True)
+ t = transport if transport is not None else (checked_transport() if checked_transport else None)
+ return httpx.AsyncClient(timeout=CALL_TIMEOUT_S, transport=t, follow_redirects=True)
class PlugToolError(RuntimeError):
diff --git a/gateway/sql_plane.py b/gateway/sql_plane.py
index f99b5a22..cfda36c3 100644
--- a/gateway/sql_plane.py
+++ b/gateway/sql_plane.py
@@ -169,10 +169,11 @@ def _peer_of(conn) -> str:
async def _vet_peer(conn) -> None:
+ """The gateway decides, including for an address that could not be read: on a self-hosted box
+ that is a database on a local socket, the normal case there (0.32.1 refused it)."""
if PEER_CHECK is None:
return
- addr = _peer_of(conn)
- why = await PEER_CHECK(addr) if addr else "the address it reached could not be read"
+ why = await PEER_CHECK(_peer_of(conn))
if why:
raise SqlError(f"This server cannot use that database: {why}.")
diff --git a/gateway/tests/test_pinned_address.py b/gateway/tests/test_pinned_address.py
index 01d97ac6..0644131a 100644
--- a/gateway/tests/test_pinned_address.py
+++ b/gateway/tests/test_pinned_address.py
@@ -169,3 +169,74 @@ def test_a_database_outside_runs_and_a_self_hosted_one_inside_runs_too(monkeypat
ran = _fake_pg(monkeypatch, "127.0.0.1")
asyncio.run(sql_plane.run_query("postgres", "postgres://u:p@localhost/app", "SELECT 1"))
assert len(ran) == 1
+
+
+def test_a_self_hosted_database_on_a_local_socket_runs(monkeypatch):
+ """A Unix socket has no peer address. 0.32.1 refused it everywhere; only a shared deployment
+ should, where an address that cannot be read is not one this server vouches for."""
+ import sql_plane
+ monkeypatch.setattr(gw, "_pool_is_local", lambda: True)
+ ran = _fake_pg(monkeypatch, "")
+ asyncio.run(sql_plane.run_query("postgres", "postgres://u:p@/app?host=/var/run/postgresql", "SELECT 1"))
+ assert len(ran) == 1
+ monkeypatch.setattr(gw, "_pool_is_local", lambda: False)
+ ran = _fake_pg(monkeypatch, "")
+ with pytest.raises(sql_plane.SqlError):
+ asyncio.run(sql_plane.run_query("postgres", "postgres://u:p@/app?host=/var/run/postgresql", "SELECT 1"))
+ assert ran == []
+
+
+def test_the_checked_clients_limits_are_the_ones_applied():
+ pool = gw._checked_http()._transport._pool
+ assert pool._max_connections == 200 and pool._max_keepalive_connections == 40
+
+
+def test_a_plugin_vendor_address_a_member_typed_cannot_reach_inside_even_by_redirect(monkeypatch):
+ """An InsForge plug names its backend by a typed url, and the answer goes back to the agent."""
+ import plugs_plane
+ monkeypatch.setattr(plugs_plane, "transport", None)
+ monkeypatch.setattr(gw, "_pool_is_local", lambda: False)
+
+ async def classify(host, port):
+ return (["127.0.0.1"], None) if host == "public.test" else ([], "target resolves to a disallowed (internal) address")
+ monkeypatch.setattr(gw, "_classify_target", classify)
+
+ async def go():
+ inside, iport, iseen = await _server()
+
+ async def bounce(reader, writer):
+ await reader.readuntil(b"\r\n\r\n")
+ writer.write(f"HTTP/1.1 302 Found\r\nlocation: http://inside.test:{iport}/api/secrets\r\n"
+ f"content-length: 0\r\nconnection: close\r\n\r\n".encode())
+ await writer.drain()
+ writer.close()
+ outside = await asyncio.start_server(bounce, "127.0.0.1", 0)
+ oport = outside.sockets[0].getsockname()[1]
+ errors = []
+ for url in (f"http://inside.test:{iport}/api/health", f"http://public.test:{oport}/api/health"):
+ try:
+ async with plugs_plane.client() as c:
+ await c.get(url)
+ except httpx.ConnectError as e:
+ errors.append(str(e))
+ inside.close()
+ outside.close()
+ return iseen, errors
+ seen, errors = asyncio.run(go())
+ assert len(errors) == 2 and all("cannot be used" in e for e in errors)
+ assert seen["connections"] == 0
+
+
+def test_a_self_hosted_plugin_vendor_on_the_boxs_own_network_still_works(monkeypatch):
+ import plugs_plane
+ monkeypatch.setattr(plugs_plane, "transport", None)
+ monkeypatch.setattr(gw, "_pool_is_local", lambda: True)
+
+ async def go():
+ srv, port, seen = await _server()
+ async with plugs_plane.client() as c:
+ r = await c.get(f"http://127.0.0.1:{port}/api/health")
+ srv.close()
+ return r, seen
+ r, seen = asyncio.run(go())
+ assert r.status_code == 200 and seen["connections"] == 1