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.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(remote-access): stop trusting host for local bypass
cyh47afd6599527
diff --git a/tests/test_ui_remote_access_auth.py b/tests/test_ui_remote_access_auth.pyindex 70bfa3c83..7cd974430 100644--- a/tests/test_ui_remote_access_auth.py+++ b/tests/test_ui_remote_access_auth.py@@ -33,11 +33,24 @@ def _save_config(tmp_path) -> V2Config:return config+def _remote_peer() -> dict[str, str]:+ return {"REMOTE_ADDR": "203.0.113.10"}+++def _cloudflare_headers() -> dict[str, str]:+ return {"CF-Connecting-IP": "198.51.100.10", "CF-Ray": "test-ray"}++def test_remote_host_redirects_to_vibe_cloud_login(monkeypatch, tmp_path):monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))_save_config(tmp_path)- response = app.test_client().get("/dashboard", base_url="https://alex.avibe.bot", follow_redirects=False)+ response = app.test_client().get(+ "/dashboard",+ base_url="https://alex.avibe.bot",+ environ_base=_remote_peer(),+ follow_redirects=False,+ )assert response.status_code == 302assert response.headers["Location"].startswith("https://backend.test/oauth/authorize?")@@ -76,7 +89,12 @@ def test_unmatched_non_local_host_fails_closed_when_remote_access_enabled(monkeymonkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))_save_config(tmp_path)- response = app.test_client().get("/dashboard", base_url="https://old-alex.avibe.bot", follow_redirects=False)+ response = app.test_client().get(+ "/dashboard",+ base_url="https://old-alex.avibe.bot",+ environ_base=_remote_peer(),+ follow_redirects=False,+ )assert response.status_code == 503assert response.get_json()["error"] == "remote_access_host_mismatch"@@ -99,7 +117,12 @@ def test_remote_host_fails_closed_when_config_load_fails(monkeypatch):monkeypatch.setattr(ui_server.V2Config, "load", fail_load)- response = app.test_client().get("/dashboard", base_url="https://alex.avibe.bot", follow_redirects=False)+ response = app.test_client().get(+ "/dashboard",+ base_url="https://alex.avibe.bot",+ environ_base=_remote_peer(),+ follow_redirects=False,+ )assert response.status_code == 503assert response.get_json()["error"] == "remote_access_config_unavailable"@@ -111,19 +134,61 @@ def test_host_starting_with_127_but_not_ip_is_not_local_when_config_load_fails(mmonkeypatch.setattr(ui_server.V2Config, "load", fail_load)- response = app.test_client().get("/dashboard", base_url="https://127.attacker.example", follow_redirects=False)+ response = app.test_client().get(+ "/dashboard",+ base_url="https://127.attacker.example",+ environ_base=_remote_peer(),+ follow_redirects=False,+ )++ assert response.status_code == 503+ assert response.get_json()["error"] == "remote_access_config_unavailable"+++def test_spoofed_loopback_host_is_not_local_when_peer_is_remote(monkeypatch):+ def fail_load():+ raise ValueError("corrupt config")++ monkeypatch.setattr(ui_server.V2Config, "load", fail_load)++ response = app.test_client().get(+ "/dashboard",+ base_url="https://127.0.0.1",+ environ_base=_remote_peer(),+ follow_redirects=False,+ )assert response.status_code == 503assert response.get_json()["error"] == "remote_access_config_unavailable"+def test_cloudflare_forwarded_request_with_loopback_host_fails_closed(monkeypatch, tmp_path):+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))+ _save_config(tmp_path)++ response = app.test_client().get(+ "/dashboard",+ base_url="https://127.0.0.1",+ headers=_cloudflare_headers(),+ follow_redirects=False,+ )++ assert response.status_code == 503+ assert response.get_json()["error"] == "remote_access_host_mismatch"++def test_remote_host_fails_closed_when_disabled_but_hostname_still_matches(monkeypatch, tmp_path):monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))config = _save_config(tmp_path)config.remote_access.vibe_cloud.enabled = Falseconfig.save()- response = app.test_client().get("/dashboard", base_url="https://alex.avibe.bot", follow_redirects=False)+ response = app.test_client().get(+ "/dashboard",+ base_url="https://alex.avibe.bot",+ environ_base=_remote_peer(),+ follow_redirects=False,+ )assert response.status_code == 503assert response.get_json()["error"] == "remote_access_disabled"@@ -135,7 +200,12 @@ def test_remote_host_fails_closed_when_public_url_is_invalid(monkeypatch, tmp_paconfig.remote_access.vibe_cloud.public_url = "alex.avibe.bot"config.save()- response = app.test_client().get("/dashboard", base_url="https://alex.avibe.bot", follow_redirects=False)+ response = app.test_client().get(+ "/dashboard",+ base_url="https://alex.avibe.bot",+ environ_base=_remote_peer(),+ follow_redirects=False,+ )assert response.status_code == 503assert response.get_json()["error"] == "remote_access_public_url_invalid"@@ -147,7 +217,12 @@ def test_remote_host_fails_closed_when_public_url_contains_userinfo(monkeypatch,config.remote_access.vibe_cloud.public_url = "https://user:[email protected]"config.save()- response = app.test_client().get("/dashboard", base_url="https://alex.avibe.bot", follow_redirects=False)+ response = app.test_client().get(+ "/dashboard",+ base_url="https://alex.avibe.bot",+ environ_base=_remote_peer(),+ follow_redirects=False,+ )assert response.status_code == 503assert response.get_json()["error"] == "remote_access_public_url_invalid"@@ -159,7 +234,12 @@ def test_remote_host_fails_closed_when_public_url_is_empty(monkeypatch, tmp_pathconfig.remote_access.vibe_cloud.public_url = ""config.save()- response = app.test_client().get("/dashboard", base_url="https://alex.avibe.bot", follow_redirects=False)+ response = app.test_client().get(+ "/dashboard",+ base_url="https://alex.avibe.bot",+ environ_base=_remote_peer(),+ follow_redirects=False,+ )assert response.status_code == 503assert response.get_json()["error"] == "remote_access_public_url_invalid"diff --git a/vibe/ui_server.py b/vibe/ui_server.pyindex f05dbf3c9..877df24c5 100644--- a/vibe/ui_server.py+++ b/vibe/ui_server.py@@ -192,14 +192,34 @@ def _load_remote_access_config() -> V2Config | None:return None-def _is_local_request_host() -> bool:- host = _normalized_host(request.host)- if host == "localhost":+def _has_cloudflare_forwarded_metadata() -> bool:+ return any(+ request.headers.get(header)+ for header in (+ "CF-Connecting-IP",+ "CF-Ray",+ "CF-Visitor",+ "CF-IPCountry",+ )+ )+++def _is_loopback_peer() -> bool:+ remote_addr = (request.remote_addr or "").strip()+ if remote_addr == "localhost":return Truetry:- return ipaddress.ip_address(host).is_loopback+ address = ipaddress.ip_address(remote_addr)except ValueError:return False+ if address.is_loopback:+ return True+ mapped = getattr(address, "ipv4_mapped", None)+ return bool(mapped and mapped.is_loopback)+++def _is_local_request() -> bool:+ return _is_loopback_peer() and not _has_cloudflare_forwarded_metadata()def _normalized_host(value: str | None) -> str:@@ -340,7 +360,7 @@ def _redirect_to_vibe_cloud_login(config: V2Config):@app.before_requestdef enforce_remote_access_cookie():config = _load_remote_access_config()- local_request = _is_local_request_host()+ local_request = _is_local_request()if config is None:if local_request:return None