Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
fix(server): map wildcard bind host to loopback for client URLs (#2856) (#2868)
Kevin Hou83011af4381b
diff --git a/openviking/server/config.py b/openviking/server/config.pyindex 3457849df..bc0e7393b 100644--- a/openviking/server/config.py+++ b/openviking/server/config.py@@ -200,6 +200,30 @@ class ServerConfig(BaseModel):return AuthMode.DEV.value+def map_bind_host_to_loopback(host: str) -> str:+ """Map a server *bind* host to a client-connectable *loopback* host.++ ``server.host`` configures the address the server binds/listens on. A+ wildcard bind address such as ``0.0.0.0`` (or IPv6 ``::``) is valid to+ listen on but is *not* a destination a client can connect to. Clients that+ derive a connect URL from the configured host (the bot proxy, the bot's+ own config loader, ``doctor``) must translate the wildcard to loopback:++ - ``"0.0.0.0"``, ``""``, ``"*"`` -> ``"127.0.0.1"``+ - ``"::"``, ``"::0"``, ``"[::]"`` -> ``"[::1]"``+ - bare IPv6 literals (e.g. ``"::1"``) are bracketed for URL syntax+ - everything else passes through unchanged+ """+ host = str(host or "").strip()+ if host in ("0.0.0.0", "", "*"):+ return "127.0.0.1"+ if host in ("::", "::0", "[::]"):+ return "[::1]"+ if ":" in host and not (host.startswith("[") and host.endswith("]")):+ return f"[{host}]"+ return host++def get_server_url_from_server_data(server_data: object) -> str:"""Return the loopback URL clients use for the configured OpenViking server."""if isinstance(server_data, dict):@@ -208,9 +232,7 @@ def get_server_url_from_server_data(server_data: object) -> str:else:host_value = getattr(server_data, "host", None)port_value = getattr(server_data, "port", None)- host = str(host_value or "127.0.0.1").strip()- if ":" in host and not (host.startswith("[") and host.endswith("]")):- host = f"[{host}]"+ host = map_bind_host_to_loopback(str(host_value or "127.0.0.1"))port = str(port_value or "1933").strip()return f"http://{host}:{port}"diff --git a/openviking/server/mcp_endpoint.py b/openviking/server/mcp_endpoint.pyindex 51da9491d..dfce249b8 100644--- a/openviking/server/mcp_endpoint.py+++ b/openviking/server/mcp_endpoint.py@@ -435,7 +435,10 @@ def _resolve_public_base_url() -> tuple[str, str]:return f"http://{host_hdr}", "host"if config is not None:- return f"http://{config.host}:{config.port}", "listen"+ from openviking.server.config import map_bind_host_to_loopback++ host = map_bind_host_to_loopback(config.host)+ return f"http://{host}:{config.port}", "listen"return "http://127.0.0.1:1933", "listen"diff --git a/tests/test_server_config_loader.py b/tests/test_server_config_loader.pyindex edd5a263a..61314eafa 100644--- a/tests/test_server_config_loader.py+++ b/tests/test_server_config_loader.py@@ -10,6 +10,7 @@ from openviking.server.config import (get_server_url_from_server_data,load_bot_gateway_token,load_server_config,+ map_bind_host_to_loopback,)@@ -128,6 +129,50 @@ def test_get_server_url_from_server_config_brackets_ipv6_literal():assert get_server_url_from_server_data(config) == "http://[::1]:1944"+ "host, expected",+ [+ # IPv4 wildcard bind addresses are not connectable -> loopback.+ ("0.0.0.0", "127.0.0.1"),+ ("", "127.0.0.1"),+ ("*", "127.0.0.1"),+ # IPv6 wildcard bind addresses -> IPv6 loopback (bracketed for URLs).+ ("::", "[::1]"),+ ("::0", "[::1]"),+ ("[::]", "[::1]"),+ # Real IPv6 literals are bracketed but otherwise preserved.+ ("::1", "[::1]"),+ ("[::1]", "[::1]"),+ # Concrete reachable hosts pass through untouched.+ ("127.0.0.1", "127.0.0.1"),+ ("192.168.1.10", "192.168.1.10"),+ ("openviking.local", "openviking.local"),+ ],+)+def test_map_bind_host_to_loopback(host, expected):+ assert map_bind_host_to_loopback(host) == expected+++def test_get_server_url_from_server_data_maps_ipv4_wildcard_to_loopback():+ # Regression for issue #2856: server.host "0.0.0.0" is a bind address, not a+ # destination the bot/client can connect to.+ server = {"host": "0.0.0.0", "port": 1933}++ assert get_server_url_from_server_data(server) == "http://127.0.0.1:1933"+++def test_get_server_url_from_server_config_maps_ipv4_wildcard_to_loopback():+ config = ServerConfig(host="0.0.0.0", port=1933)++ assert get_server_url_from_server_data(config) == "http://127.0.0.1:1933"+++def test_get_server_url_from_server_data_maps_ipv6_wildcard_to_loopback():+ server = {"host": "::", "port": 1933}++ assert get_server_url_from_server_data(server) == "http://[::1]:1933"++def test_load_server_config_preserves_metrics_account_dimension_fields(tmp_path):config_path = tmp_path / "ov.conf"config_path.write_text(