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(security): reject unverifiable remote DNS targets (#5864)
zhanggaoyuan589c0d1de34c
diff --git a/openviking/utils/network_guard.py b/openviking/utils/network_guard.pyindex 14121a820..0623f3ead 100644--- a/openviking/utils/network_guard.py+++ b/openviking/utils/network_guard.py@@ -127,7 +127,10 @@ def ensure_public_remote_target(source: str) -> None:resolved_addresses = _resolve_host_addresses(host)if not resolved_addresses:- return+ raise PermissionDeniedError(+ "HTTP server only accepts public remote resource targets; "+ f"host '{host}' could not be resolved to a verifiable public address."+ )non_public = sorted(addr for addr in resolved_addresses if not _is_public_ip(addr))if non_public:diff --git a/tests/misc/test_network_guard.py b/tests/misc/test_network_guard.pyindex d22f23ff2..ac7cd2be3 100644--- a/tests/misc/test_network_guard.py+++ b/tests/misc/test_network_guard.py@@ -271,10 +271,11 @@ class TestEnsurePublicRemoteTarget:ensure_public_remote_target("[email protected]:v3/org/project/repo") # should not raise@patch("openviking.utils.network_guard._resolve_host_addresses")- def test_allows_when_dns_returns_empty(self, mock_resolve) -> None:- """Unresolvable host is allowed through (fail-open for DNS)."""+ def test_rejects_when_dns_returns_empty(self, mock_resolve) -> None:+ """Unresolvable host cannot be verified as public."""mock_resolve.return_value = set()- ensure_public_remote_target("http://new-host.example.com/path") # should not raise+ with pytest.raises(PermissionDeniedError, match="could not be resolved"):+ ensure_public_remote_target("http://new-host.example.com/path")@patch("openviking.utils.network_guard._resolve_host_addresses")def test_allows_multiple_public_addresses(self, mock_resolve) -> None:diff --git a/tests/server/test_api_local_input_security.py b/tests/server/test_api_local_input_security.pyindex ecccbea84..6592a4298 100644--- a/tests/server/test_api_local_input_security.py+++ b/tests/server/test_api_local_input_security.py@@ -331,6 +331,27 @@ async def test_add_resource_rejects_private_git_ssh_url(client: httpx.AsyncClienassert body["error"]["code"] == "PERMISSION_DENIED"+async def test_add_resource_rejects_unverifiable_remote_dns(+ client: httpx.AsyncClient,+ monkeypatch: pytest.MonkeyPatch,+):+ monkeypatch.setattr(+ "openviking.utils.network_guard._resolve_host_addresses",+ lambda _host: set(),+ )++ resp = await client.post(+ "/api/v1/resources",+ json={"path": "http://new-host.example.com/doc.md", "reason": "ssrf probe"},+ )++ assert resp.status_code == 403+ body = resp.json()+ assert body["status"] == "error"+ assert body["error"]["code"] == "PERMISSION_DENIED"+ assert "could not be resolved" in body["error"]["message"]++async def test_url_detector_request_validator_blocks_loopback_head(loopback_http_url: str):detector = URLTypeDetector()