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): tighten loopback proxy host gating

cyh553de70d6bd9
diff --git a/tests/test_ui_remote_access_auth.py b/tests/test_ui_remote_access_auth.py
index 8c65ac70a..05326f067 100644
--- a/tests/test_ui_remote_access_auth.py
+++ b/tests/test_ui_remote_access_auth.py
@@ -345,6 +345,40 @@ def test_loopback_proxy_with_public_host_mismatch_fails_closed(monkeypatch, tmp_
assert response.get_json()["error"] == "remote_access_host_mismatch"
+def test_loopback_proxy_with_partial_forwarded_metadata_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://old-alex.avibe.bot",
+ environ_base={"REMOTE_ADDR": "127.0.0.1"},
+ headers={"X-Real-IP": "203.0.113.10"},
+ follow_redirects=False,
+ )
+
+ assert response.status_code == 503
+ assert response.get_json()["error"] == "remote_access_host_mismatch"
+
+
+def test_loopback_origin_proxy_with_loopback_host_is_allowed(monkeypatch, tmp_path):
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
+ _save_config(tmp_path)
+
+ response = app.test_client().get(
+ "/dashboard",
+ base_url="http://127.0.0.1:15131",
+ environ_base={"REMOTE_ADDR": "127.0.0.1"},
+ headers={
+ "X-Forwarded-Proto": "https",
+ "X-Forwarded-Host": "vibe.example",
+ },
+ follow_redirects=False,
+ )
+
+ assert response.status_code != 503
+
+
def test_remote_host_allows_valid_remote_session(monkeypatch, tmp_path):
monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
config = _save_config(tmp_path)
diff --git a/tests/test_ui_server_mutation_protection.py b/tests/test_ui_server_mutation_protection.py
index e73a04a04..49a0f8bc8 100644
--- a/tests/test_ui_server_mutation_protection.py
+++ b/tests/test_ui_server_mutation_protection.py
@@ -81,7 +81,7 @@ def test_config_post_allows_forwarded_origin(monkeypatch, tmp_path):
agents=AgentsConfig(),
).save()
client = app.test_client()
- headers = csrf_headers(client, "http://internal:15131")
+ headers = csrf_headers(client, "http://127.0.0.1:15131")
headers["Origin"] = "https://vibe.example"
headers["X-Forwarded-Proto"] = "https"
headers["X-Forwarded-Host"] = "vibe.example"
@@ -99,7 +99,7 @@ def test_config_post_allows_forwarded_origin(monkeypatch, tmp_path):
},
},
headers=headers,
- base_url="http://internal:15131",
+ base_url="http://127.0.0.1:15131",
)
assert response.status_code == 200
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index 9e58f0a5b..e307e1c60 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -207,6 +207,23 @@ def _has_forwarded_metadata() -> bool:
return _has_cloudflare_forwarded_metadata()
+def _is_loopback_origin_proxy_request() -> bool:
+ if not _is_loopback_peer() or not _is_loopback_host(request.host):
+ return False
+ if request.headers.get("Forwarded") or request.headers.get("X-Forwarded-For"):
+ return False
+ client_ip_headers = (
+ "X-Real-IP",
+ "X-Original-Forwarded-For",
+ "True-Client-IP",
+ )
+ if any(request.headers.get(header) for header in client_ip_headers):
+ return False
+ if _has_cloudflare_forwarded_metadata():
+ return False
+ return bool(request.headers.get("X-Forwarded-Host") or request.headers.get("X-Forwarded-Proto"))
+
+
def _is_loopback_peer() -> bool:
remote_addr = (request.remote_addr or "").strip()
if remote_addr == "localhost":
@@ -908,14 +925,7 @@ def enforce_remote_access_cookie():
return jsonify({"ok": False, "error": "remote_access_public_url_invalid"}), 503
remote_request = _is_remote_access_request(config)
if not remote_request:
- if (
- _has_forwarded_metadata()
- and _is_loopback_peer()
- and "X-Forwarded-For" not in request.headers
- and "Forwarded" not in request.headers
- and _normalized_host(request.host) not in {"127.0.0.1", "localhost", "::1"}
- and not _is_setup_host_request(config)
- ):
+ if _is_loopback_origin_proxy_request():
return None
if not local_request and not docker_probe_request:
return jsonify({"ok": False, "error": "remote_access_host_mismatch"}), 503