Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(ui_server): scope setup-host trust to peer's private network block

cyh820939a572b2
diff --git a/tests/test_ui_remote_access_auth.py b/tests/test_ui_remote_access_auth.py
index 78151572d..e8dc9ab48 100644
--- a/tests/test_ui_remote_access_auth.py
+++ b/tests/test_ui_remote_access_auth.py
@@ -735,6 +735,56 @@ def test_setup_host_with_public_peer_is_not_local(monkeypatch, tmp_path):
assert response.get_json()["error"] == "remote_access_host_mismatch"
+def test_setup_host_lan_peer_with_tailscale_setup_is_not_local(monkeypatch, tmp_path):
+ """Wildcard-bind regression guard: a LAN peer cannot inherit setup-host
+ trust by spoofing the Host header to a Tailscale setup_host that lives
+ in a different private block."""
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
+ _save_config_with_setup_host(tmp_path, "100.97.103.112")
+
+ response = app.test_client().get(
+ "/dashboard",
+ base_url="http://100.97.103.112:5123",
+ environ_base={"REMOTE_ADDR": "192.168.1.5"},
+ follow_redirects=False,
+ )
+
+ assert response.status_code == 503
+ assert response.get_json()["error"] == "remote_access_host_mismatch"
+
+
+def test_setup_host_tailscale_peer_with_lan_setup_is_not_local(monkeypatch, tmp_path):
+ """Inverse of the LAN-vs-Tailscale check: a Tailscale peer cannot inherit
+ setup-host trust by spoofing the Host header to a LAN setup_host."""
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
+ _save_config_with_setup_host(tmp_path, "192.168.2.3")
+
+ response = app.test_client().get(
+ "/dashboard",
+ base_url="http://192.168.2.3:5123",
+ environ_base={"REMOTE_ADDR": "100.97.103.5"},
+ follow_redirects=False,
+ )
+
+ assert response.status_code == 503
+ assert response.get_json()["error"] == "remote_access_host_mismatch"
+
+
+def test_setup_host_tailscale_peer_with_tailscale_setup_is_local(monkeypatch, tmp_path):
+ """Same-block trust still works: a Tailscale peer can inherit setup-host
+ trust when setup_host is also in 100.64/10."""
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
+ _save_config_with_setup_host(tmp_path, "100.97.103.112")
+
+ response = app.test_client().get(
+ "/health",
+ base_url="http://100.97.103.112:5123",
+ environ_base={"REMOTE_ADDR": "100.97.103.5"},
+ )
+
+ assert response.status_code == 200
+
+
def test_setup_host_mismatched_host_header_is_not_local(monkeypatch, tmp_path):
monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
_save_config_with_setup_host(tmp_path, "192.168.2.3")
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index 89b73b394..774aa6c36 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -258,6 +258,27 @@ def _is_loopback_host(value: str | None) -> bool:
# setup-host peers when the request's Host header otherwise matches.
_SHARED_ADDRESS_SPACE = ipaddress.ip_network("100.64.0.0/10")
+# Private/CGNAT/link-local blocks used to gate setup-host trust. Pre-tunnel
+# the UI bound only to ``ui.setup_host`` so the kernel filtered out peers
+# from other interfaces; the ``Host`` match + private-peer pair was scoped
+# by the network layer. The tunnel-on path widens the bind to a wildcard,
+# so an attacker on a different private subnet could otherwise reach the
+# socket and spoof ``Host: <setup_host>`` to inherit local trust. We
+# restore the network scoping at the application layer by requiring the
+# peer's IP to share setup_host's block. Order is most-specific first so
+# the tightest block that still contains setup_host wins.
+_PRIVATE_NETWORKS_V4 = (
+ ipaddress.IPv4Network("100.64.0.0/10"),
+ ipaddress.IPv4Network("169.254.0.0/16"),
+ ipaddress.IPv4Network("192.168.0.0/16"),
+ ipaddress.IPv4Network("172.16.0.0/12"),
+ ipaddress.IPv4Network("10.0.0.0/8"),
+)
+_PRIVATE_NETWORKS_V6 = (
+ ipaddress.IPv6Network("fc00::/7"),
+ ipaddress.IPv6Network("fe80::/10"),
+)
+
def _is_private_address(address: ipaddress._BaseAddress) -> bool:
if address.is_loopback or address.is_private or address.is_link_local:
@@ -281,6 +302,32 @@ def _is_private_peer() -> bool:
return False
+def _peer_shares_setup_host_network(setup_address: ipaddress._BaseAddress) -> bool:
+ """Require the peer to be in the same private/CGNAT block as setup_host.
+
+ Compensates for the wildcard bind in the tunnel-on path. Without this,
+ a 192.168/16 LAN peer could spoof ``Host=<tailscale_setup_host>`` on
+ a different interface and inherit setup-host trust.
+ """
+ remote_addr = (request.remote_addr or "").strip()
+ if not remote_addr or remote_addr == "localhost":
+ return False
+ try:
+ peer = ipaddress.ip_address(remote_addr)
+ except ValueError:
+ return False
+ if peer.version != setup_address.version:
+ mapped = getattr(peer, "ipv4_mapped", None)
+ if mapped is None or mapped.version != setup_address.version:
+ return False
+ peer = mapped
+ candidates = _PRIVATE_NETWORKS_V4 if setup_address.version == 4 else _PRIVATE_NETWORKS_V6
+ for net in candidates:
+ if setup_address in net:
+ return peer in net
+ return False
+
+
def _env_flag_enabled(name: str) -> bool:
return os.environ.get(name, "").lower() in {"1", "true", "yes", "on"}
@@ -357,7 +404,13 @@ def _is_setup_host_request(config: V2Config | None) -> bool:
# the actual client, so refuse the setup-host trust path entirely.
if _has_forwarded_metadata():
return False
- return _is_private_peer()
+ if not _is_private_peer():
+ return False
+ # See _peer_shares_setup_host_network: the tunnel-on path widens the
+ # UI bind, so we have to enforce setup_host's network scoping at the
+ # application layer instead of relying on the kernel to drop traffic
+ # from peers on other interfaces.
+ return _peer_shares_setup_host_network(setup_address)
def _is_local_request(config: V2Config | None = None) -> bool: