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): close disabled session gaps

cyh076da07504ce
diff --git a/tests/test_remote_access_vibe_cloud.py b/tests/test_remote_access_vibe_cloud.py
index f1b995f39..ea8f8cf6f 100644
--- a/tests/test_remote_access_vibe_cloud.py
+++ b/tests/test_remote_access_vibe_cloud.py
@@ -124,6 +124,31 @@ def test_stop_preserves_pid_file_when_process_stop_fails(monkeypatch, tmp_path)
assert remote_access._state_path().exists()
+def test_start_returns_failure_when_remote_access_is_disabled(monkeypatch, tmp_path) -> None:
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
+ config = _config()
+ config.remote_access.vibe_cloud.enabled = False
+
+ monkeypatch.setattr(remote_access, "stop", lambda: {"ok": True, "stopped": False})
+
+ result = remote_access.start(config)
+
+ assert result["ok"] is False
+ assert result["error"] == "remote_access_disabled"
+
+
+def test_reconcile_stops_when_remote_access_is_disabled(monkeypatch, tmp_path) -> None:
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
+ config = _config()
+ config.remote_access.vibe_cloud.enabled = False
+
+ monkeypatch.setattr(remote_access, "stop", lambda: {"ok": True, "stopped": True})
+
+ result = remote_access.reconcile(config)
+
+ assert result == {"ok": True, "stopped": True}
+
+
def test_start_restarts_when_runtime_signature_changes(monkeypatch, tmp_path) -> None:
monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
config = _config()
diff --git a/tests/test_ui_remote_access_auth.py b/tests/test_ui_remote_access_auth.py
index 7ef7f1e22..35541acbe 100644
--- a/tests/test_ui_remote_access_auth.py
+++ b/tests/test_ui_remote_access_auth.py
@@ -1,6 +1,7 @@
from __future__ import annotations
from config.v2_config import AgentsConfig, PlatformsConfig, RemoteAccessConfig, RuntimeConfig, SlackConfig, UiConfig, V2Config
+from tests.ui_server_test_helpers import csrf_headers
from vibe import remote_access
from vibe import ui_server
from vibe.ui_server import app
@@ -50,6 +51,16 @@ def test_remote_host_with_explicit_port_still_requires_login(monkeypatch, tmp_pa
assert response.headers["Location"].startswith("https://backend.test/oauth/authorize?")
+def test_remote_host_with_trailing_dot_still_requires_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.vibe.io.", follow_redirects=False)
+
+ assert response.status_code == 302
+ assert response.headers["Location"].startswith("https://backend.test/oauth/authorize?")
+
+
def test_localhost_does_not_require_remote_access_cookie(monkeypatch, tmp_path):
monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
_save_config(tmp_path)
@@ -94,6 +105,28 @@ def test_remote_host_fails_closed_when_disabled_but_hostname_still_matches(monke
assert response.get_json()["error"] == "remote_access_disabled"
+def test_config_post_rotates_session_secret_when_remote_access_is_disabled(monkeypatch, tmp_path):
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
+ config = _save_config(tmp_path)
+ old_secret = config.remote_access.vibe_cloud.session_secret
+ client = app.test_client()
+
+ monkeypatch.setattr(remote_access, "reconcile", lambda next_config: {"ok": True, "stopped": True})
+
+ response = client.post(
+ "/config",
+ json={"remote_access": {"vibe_cloud": {"enabled": False}}},
+ headers=csrf_headers(client, "http://127.0.0.1:5123"),
+ base_url="http://127.0.0.1:5123",
+ )
+ saved = V2Config.load()
+
+ assert response.status_code == 200
+ assert saved.remote_access.vibe_cloud.enabled is False
+ assert saved.remote_access.vibe_cloud.session_secret
+ assert saved.remote_access.vibe_cloud.session_secret != old_secret
+
+
def test_remote_callback_rejects_nonce_mismatch(monkeypatch, tmp_path):
monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
config = _save_config(tmp_path)
diff --git a/vibe/remote_access.py b/vibe/remote_access.py
index 821a13b36..8307c18de 100644
--- a/vibe/remote_access.py
+++ b/vibe/remote_access.py
@@ -245,12 +245,18 @@ def stop() -> dict[str, Any]:
return {**status(), "ok": True, "stopped": stopped}
+def rotate_session_secret(config: V2Config) -> None:
+ config.remote_access.vibe_cloud.session_secret = secrets.token_urlsafe(32)
+ config.save()
+
+
def start(config: V2Config | None = None) -> dict[str, Any]:
with _CONNECTOR_LOCK:
config = config or V2Config.load()
cloud = config.remote_access.vibe_cloud
if not cloud.enabled:
- return stop()
+ stop_result = stop()
+ return {**stop_result, "ok": False, "error": "remote_access_disabled"}
if not cloud.tunnel_token:
stop_result = stop()
return {**stop_result, "ok": False, "error": "missing_tunnel_token"}
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index 1cc8aa59a..8688d12de 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -197,10 +197,14 @@ def _is_local_request_host() -> bool:
def _normalized_host(value: str | None) -> str:
- raw_host = (value or "").lower()
+ raw_host = (value or "").lower().strip()
if raw_host.startswith("[") and "]" in raw_host:
- return raw_host[1 : raw_host.index("]")]
- return raw_host.split(":", 1)[0]
+ host = raw_host[1 : raw_host.index("]")]
+ elif raw_host.count(":") > 1:
+ host = raw_host
+ else:
+ host = raw_host.split(":", 1)[0]
+ return host.rstrip(".")
def _is_remote_access_request(config: V2Config) -> bool:
@@ -211,6 +215,14 @@ def _is_remote_access_request(config: V2Config) -> bool:
return bool(public_host and _normalized_host(request.host) == public_host)
+def _should_rotate_remote_session_secret(previous: V2Config | None, current: V2Config, payload: dict) -> bool:
+ if "remote_access" not in payload or previous is None:
+ return False
+ previous_cloud = previous.remote_access.vibe_cloud
+ current_cloud = current.remote_access.vibe_cloud
+ return bool(previous_cloud.enabled and not current_cloud.enabled and current_cloud.session_secret)
+
+
def _remote_auth_exempt_path() -> bool:
path = request.path
return (
@@ -555,8 +567,11 @@ def config_post():
from vibe import remote_access
payload = request.json or {}
+ previous_config = _load_remote_access_config() if "remote_access" in payload else None
config = api.save_config(payload)
if "remote_access" in payload:
+ if _should_rotate_remote_session_secret(previous_config, config, payload):
+ remote_access.rotate_session_secret(config)
result = remote_access.reconcile(config)
if result.get("ok") is False:
return jsonify({"ok": False, "error": result.get("error", "remote_access_reconcile_failed"), "remote_access": result, "config": api.config_to_payload(config)}), 500