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(server): reject local-trust paths whenever any proxy header is present

cyh29ce80271f2f
diff --git a/tests/test_ui_remote_access_auth.py b/tests/test_ui_remote_access_auth.py
index 83cbbaef4..18c71ede6 100644
--- a/tests/test_ui_remote_access_auth.py
+++ b/tests/test_ui_remote_access_auth.py
@@ -779,3 +779,25 @@ def test_setup_host_with_cloudflare_metadata_is_not_local(monkeypatch, tmp_path)
assert response.status_code == 503
assert response.get_json()["error"] == "remote_access_host_mismatch"
+
+
+def test_setup_host_with_reverse_proxy_header_is_not_local(monkeypatch, tmp_path):
+ """A non-Cloudflare reverse proxy on the same host (nginx, Caddy, ...)
+ fronts vibe and an attacker spoofs Host=setup_host. Flask sees a private
+ peer (the proxy) and the Host matches setup_host, so the host+peer pair
+ looks "local" — but X-Forwarded-For (or any other forwarded header) tells
+ us the actual client is unknown, so the request must not be trusted.
+ """
+ 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": "127.0.0.1"},
+ headers={"X-Forwarded-For": "203.0.113.10"},
+ follow_redirects=False,
+ )
+
+ assert response.status_code == 503
+ assert response.get_json()["error"] == "remote_access_host_mismatch"
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index 65456b17b..242baa3ca 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -204,6 +204,30 @@ def _has_cloudflare_forwarded_metadata() -> bool:
)
+def _has_forwarded_metadata() -> bool:
+ """Detect any sign that the request traversed a reverse proxy.
+
+ When any forwarded header is set, request.remote_addr no longer reliably
+ identifies the actual client (a same-host proxy makes external attackers
+ look like loopback / private peers), so authorization paths that lean on a
+ private/loopback peer must refuse the request unless we have an explicit
+ trusted-proxy chain.
+ """
+ forwarded_headers = (
+ "Forwarded",
+ "X-Forwarded-For",
+ "X-Forwarded-Host",
+ "X-Forwarded-Proto",
+ "X-Forwarded-Port",
+ "X-Real-IP",
+ "X-Original-Forwarded-For",
+ "True-Client-IP",
+ )
+ if any(request.headers.get(header) for header in forwarded_headers):
+ return True
+ return _has_cloudflare_forwarded_metadata()
+
+
def _is_loopback_peer() -> bool:
remote_addr = (request.remote_addr or "").strip()
if remote_addr == "localhost":
@@ -300,7 +324,7 @@ def _is_trusted_docker_loopback_probe() -> bool:
return False
if request.path not in {"/health", "/status"}:
return False
- if _has_cloudflare_forwarded_metadata():
+ if _has_forwarded_metadata():
return False
if not _is_loopback_host(request.host):
return False
@@ -328,13 +352,16 @@ def _is_setup_host_request(config: V2Config | None) -> bool:
return False
if _normalized_host(request.host) != setup_host:
return False
- if _has_cloudflare_forwarded_metadata():
+ # Any forwarded header (including non-Cloudflare proxies like nginx /
+ # Caddy / Traefik) means we cannot trust request.remote_addr to identify
+ # the actual client, so refuse the setup-host trust path entirely.
+ if _has_forwarded_metadata():
return False
return _is_private_peer()
def _is_local_request(config: V2Config | None = None) -> bool:
- if _has_cloudflare_forwarded_metadata():
+ if _has_forwarded_metadata():
return False
if _is_loopback_peer() and _is_loopback_host(request.host):
return True