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(remote-access): fail closed during disabled tunnel

cyh4d4c48ee13c4
diff --git a/tests/test_ui_remote_access_auth.py b/tests/test_ui_remote_access_auth.py
index 948fb5c2d..7ef7f1e22 100644
--- a/tests/test_ui_remote_access_auth.py
+++ b/tests/test_ui_remote_access_auth.py
@@ -80,3 +80,44 @@ def test_remote_host_fails_closed_when_config_load_fails(monkeypatch):
assert response.status_code == 503
assert response.get_json()["error"] == "remote_access_config_unavailable"
+
+
+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 = False
+ config.save()
+
+ response = app.test_client().get("/dashboard", base_url="https://alex.vibe.io", follow_redirects=False)
+
+ assert response.status_code == 503
+ assert response.get_json()["error"] == "remote_access_disabled"
+
+
+def test_remote_callback_rejects_nonce_mismatch(monkeypatch, tmp_path):
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
+ config = _save_config(tmp_path)
+ client = app.test_client()
+
+ with app.test_request_context("/dashboard", base_url="https://alex.vibe.io"):
+ redirect = ui_server._redirect_to_vibe_cloud_login(config)
+ oauth_cookie = redirect.headers["Set-Cookie"].split(";", 1)[0].split("=", 1)[1]
+ client.set_cookie(ui_server.REMOTE_OAUTH_COOKIE_NAME, oauth_cookie, domain="alex.vibe.io")
+
+ monkeypatch.setattr(
+ remote_access,
+ "exchange_oauth_code",
+ lambda cfg, code, verifier: {
+ "claims": {
+ "email": "[email protected]",
+ "sub": "user-1",
+ "nonce": "wrong-nonce",
+ }
+ },
+ )
+
+ state = ui_server._read_oauth_cookie(config.remote_access.vibe_cloud.session_secret, oauth_cookie)["state"]
+ response = client.get(f"/auth/callback?code=test-code&state={state}", base_url="https://alex.vibe.io")
+
+ assert response.status_code == 400
+ assert response.get_json()["error"] == "invalid_oauth_nonce"
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index 3ae0e73a9..1cc8aa59a 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -205,7 +205,7 @@ def _normalized_host(value: str | None) -> str:
def _is_remote_access_request(config: V2Config) -> bool:
cloud = config.remote_access.vibe_cloud
- if not cloud.enabled or not cloud.public_url:
+ if not cloud.public_url:
return False
public_host = _normalized_host(urlparse(cloud.public_url).netloc)
return bool(public_host and _normalized_host(request.host) == public_host)
@@ -289,6 +289,8 @@ def enforce_remote_access_cookie():
return None
from vibe import remote_access
+ if not config.remote_access.vibe_cloud.enabled:
+ return jsonify({"ok": False, "error": "remote_access_disabled"}), 503
if remote_access.validate_session_cookie(config, request.cookies.get(remote_access.SESSION_COOKIE_NAME)):
return None
if request.method == "GET":
@@ -613,6 +615,8 @@ def remote_access_auth_callback():
claims = result["claims"]
except Exception as exc:
return jsonify({"error": "oauth_exchange_failed", "detail": str(exc)}), 400
+ if claims.get("nonce") != oauth_state.get("nonce"):
+ return jsonify({"error": "invalid_oauth_nonce"}), 400
response = Response(status=302)
response.headers["Location"] = str(oauth_state.get("next") or "/")
response.set_cookie(