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): gate setup-host subnet check on tunnel-on bind only

cyh6f6b010c479c
diff --git a/tests/test_ui_remote_access_auth.py b/tests/test_ui_remote_access_auth.py
index 242cda878..072e46cd0 100644
--- a/tests/test_ui_remote_access_auth.py
+++ b/tests/test_ui_remote_access_auth.py
@@ -972,6 +972,70 @@ def test_setup_host_ipv6_with_64_prefix_excludes_peer_outside_64(monkeypatch, tm
assert response.get_json()["error"] == "remote_access_host_mismatch"
+def _save_config_tunnel_off_with_setup_host(tmp_path, host: str) -> V2Config:
+ config = _save_config(tmp_path)
+ config.remote_access.vibe_cloud.enabled = False
+ config.ui.setup_host = host
+ config.save()
+ return config
+
+
+def test_setup_host_tunnel_off_allows_routed_peer_outside_interface_subnet(monkeypatch, tmp_path):
+ """When the tunnel is off, the UI binds directly to setup_host and the
+ kernel already enforces interface filtering — a routed peer reaching
+ setup_host across a /16 corporate or campus net must have been routed
+ legitimately, so the application layer should not add a second-pass
+ subnet gate (regression noted in Codex review of #252)."""
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
+ _save_config_tunnel_off_with_setup_host(tmp_path, "10.1.2.3")
+ _mock_interface(monkeypatch, "10.1.2.3", 24)
+
+ response = app.test_client().get(
+ "/health",
+ base_url="http://10.1.2.3:5123",
+ environ_base={"REMOTE_ADDR": "10.50.0.5"},
+ )
+
+ assert response.status_code == 200
+
+
+def test_setup_host_tunnel_off_still_rejects_public_peer(monkeypatch, tmp_path):
+ """Tunnel-off relaxation of the subnet gate must not relax the
+ private-peer requirement: a public peer is still untrusted."""
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
+ _save_config_tunnel_off_with_setup_host(tmp_path, "10.1.2.3")
+
+ response = app.test_client().get(
+ "/dashboard",
+ base_url="http://10.1.2.3:5123",
+ environ_base={"REMOTE_ADDR": "8.8.8.8"},
+ follow_redirects=False,
+ )
+
+ assert response.status_code == 503
+ assert response.get_json()["error"] == "remote_access_host_mismatch"
+
+
+def test_setup_host_tunnel_on_still_enforces_subnet_gate(monkeypatch, tmp_path):
+ """Mirror of the tunnel-off test above: with the tunnel on, the
+ wildcard bind requires the application-layer subnet gate, so the same
+ cross-subnet peer that is allowed when the tunnel is off must be
+ rejected when the tunnel is on."""
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
+ _save_config_with_setup_host(tmp_path, "10.1.2.3")
+ _mock_interface(monkeypatch, "10.1.2.3", 24)
+
+ response = app.test_client().get(
+ "/dashboard",
+ base_url="http://10.1.2.3:5123",
+ environ_base={"REMOTE_ADDR": "10.50.0.5"},
+ follow_redirects=False,
+ )
+
+ assert response.status_code == 503
+ assert response.get_json()["error"] == "remote_access_host_mismatch"
+
+
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 d20da3ac0..fb4dcd14f 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -495,11 +495,24 @@ def _is_setup_host_request(config: V2Config | None) -> bool:
return False
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)
+ # When the Vibe Cloud tunnel is on, the UI binds to a wildcard so the
+ # local cloudflared origin can reach setup_host regardless of which
+ # interface it lives on. Wildcard means the kernel no longer drops
+ # cross-interface traffic, so we have to re-enforce "peer shares the
+ # setup_host interface subnet" at the application layer to prevent a
+ # peer on a different interface from spoofing Host=<setup_host>. When
+ # the tunnel is off, the kernel binds to setup_host directly and that
+ # interface filtering is already in force; adding the subnet gate
+ # here would just block legitimate routed peers (e.g. a 10.50/16
+ # client reaching setup_host=10.1.2.3 across a routed corporate net).
+ if _is_tunnel_wildcard_bind(config):
+ return _peer_shares_setup_host_network(setup_address)
+ return True
+
+
+def _is_tunnel_wildcard_bind(config: V2Config) -> bool:
+ cloud = getattr(getattr(config, "remote_access", None), "vibe_cloud", None)
+ return bool(cloud is not None and cloud.enabled)
def _is_local_request(config: V2Config | None = None) -> bool: