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(webui): parse modern tailscale whois Node payload for peer trust (#944)

0xharlany5a9178aad3ee
diff --git a/tests/test_ui_remote_access_auth.py b/tests/test_ui_remote_access_auth.py
index c7ef47dd2..37b98ca5e 100644
--- a/tests/test_ui_remote_access_auth.py
+++ b/tests/test_ui_remote_access_auth.py
@@ -49,7 +49,11 @@ def _mock_tailscale_whois(
*,
addresses: list[str] | None = None,
allowed_ips: list[str] | None = None,
+ payload_key: str = "Node",
) -> None:
+ """Stub ``_tailscale_whois`` with the modern ``Node`` payload shape by
+ default (host-CIDR address strings, as emitted by current ``tailscale
+ whois --json``); pass ``payload_key="Machine"`` for the legacy shape."""
peer_address = ipaddress.ip_address(peer)
prefix = peer_address.max_prefixlen
monkeypatch.setattr(ui_server, "_TAILSCALE_PEER_CACHE", {})
@@ -57,8 +61,8 @@ def _mock_tailscale_whois(
ui_server,
"_tailscale_whois",
lambda address: {
- "Machine": {
- "Addresses": addresses or [str(peer_address)],
+ payload_key: {
+ "Addresses": addresses or [f"{peer_address}/{prefix}"],
"AllowedIPs": allowed_ips or [f"{peer_address}/{prefix}"],
}
}
@@ -2705,6 +2709,65 @@ def test_setup_host_wildcard_rejects_tailscale_subnet_router_peer(monkeypatch, t
assert response.get_json()["error"] == "remote_access_host_mismatch"
+def test_trusted_tailscale_peer_accepts_modern_node_whois_payload(monkeypatch):
+ """Current ``tailscale whois --json`` nests the peer under ``Node`` with
+ host-CIDR address strings; the top-level ``Machine`` object is gone."""
+ peer = ipaddress.ip_address("100.97.103.5")
+ monkeypatch.setattr(ui_server, "_TAILSCALE_PEER_CACHE", {})
+ monkeypatch.setattr(
+ ui_server,
+ "_tailscale_whois",
+ lambda address: {
+ "Node": {
+ "Name": "iphone.example.ts.net.",
+ "Machine": "mkey:0123456789abcdef",
+ "Addresses": ["100.97.103.5/32", "fd7a:115c:a1e0::5/128"],
+ "AllowedIPs": ["100.97.103.5/32", "fd7a:115c:a1e0::5/128"],
+ },
+ "UserProfile": {"LoginName": "[email protected]"},
+ "CapMap": {},
+ },
+ )
+
+ assert ui_server._is_trusted_tailscale_peer(peer) is True
+
+
+def test_trusted_tailscale_peer_accepts_legacy_machine_whois_payload(monkeypatch):
+ peer = ipaddress.ip_address("100.97.103.5")
+ _mock_tailscale_whois(
+ monkeypatch,
+ "100.97.103.5",
+ addresses=["100.97.103.5"],
+ payload_key="Machine",
+ )
+
+ assert ui_server._is_trusted_tailscale_peer(peer) is True
+
+
+def test_trusted_tailscale_peer_rejects_node_payload_with_subnet_route(monkeypatch):
+ peer = ipaddress.ip_address("100.97.103.5")
+ _mock_tailscale_whois(
+ monkeypatch,
+ "100.97.103.5",
+ allowed_ips=["100.97.103.5/32", "192.168.50.0/24"],
+ )
+
+ assert ui_server._is_trusted_tailscale_peer(peer) is False
+
+
+def test_trusted_tailscale_peer_ignores_non_host_address_entries(monkeypatch):
+ """Address entries that are not host CIDRs must not satisfy the peer
+ match, so a payload claiming a whole range cannot vouch for the peer."""
+ peer = ipaddress.ip_address("100.97.103.5")
+ _mock_tailscale_whois(
+ monkeypatch,
+ "100.97.103.5",
+ addresses=["100.97.103.0/24"],
+ )
+
+ assert ui_server._is_trusted_tailscale_peer(peer) is False
+
+
def test_setup_host_wildcard_does_not_trust_unconfigured_tailscale_host(monkeypatch, tmp_path):
monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
_save_config_with_setup_host(tmp_path, "0.0.0.0")
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index d89fbfa3f..a0fcde780 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -1137,14 +1137,23 @@ def _is_trusted_tailscale_peer(peer_address: ipaddress._BaseAddress) -> bool:
payload = _tailscale_whois(peer_address)
trusted = False
if payload is not None:
- machine = payload.get("Machine") or payload.get("machine") or {}
+ # Modern `tailscale whois --json` nests the peer record under "Node"
+ # (where "Machine" is just the machine-key string); older builds used a
+ # top-level "Machine" object. Accept a dict from either shape.
+ machine = payload.get("Machine") or payload.get("machine")
+ if not isinstance(machine, dict):
+ machine = payload.get("Node") or payload.get("node") or {}
if isinstance(machine, dict):
addresses = set()
for raw_address in _json_list(machine, "Addresses", "addresses"):
+ # "Node" payloads list addresses as host CIDRs ("100.64.0.2/32");
+ # older "Machine" payloads used bare IPs.
try:
- addresses.add(ipaddress.ip_address(str(raw_address)))
+ interface = ipaddress.ip_interface(str(raw_address))
except ValueError:
continue
+ if interface.network.prefixlen == interface.network.max_prefixlen:
+ addresses.add(interface.ip)
allowed_networks = []
for raw_network in _json_list(machine, "AllowedIPs", "allowedIPs", "allowedIps"):
try: