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): trust loopback-bound docker access (#511)

Call White4ce5a074c476
diff --git a/AGENTS.md b/AGENTS.md
index 984863927..eca948337 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -108,6 +108,8 @@ Standard path:
Rules:
- do **not** use `--reset-config` or `--reset-all` unless the user explicitly requests reset behavior
+- do **not** disable or overwrite preserved `remote_access` / Avibe Cloud pairing state just to make local probes pass; the regression environment is also used to test remote access, so preserve and fix the host/binding path instead
+- when Avibe Cloud remote access is enabled in regression, prefer binding the Docker UI port to loopback for local maintenance access (`THREE_REGRESSION_PORT_BIND_HOST=127.0.0.1`) while keeping the remote public URL active for product testing
- do **not** use `--no-build` when code changes must take effect; it is only for restarting with the existing image
- after running the script, verify the service is healthy before handing back to the user
- prefer Docker regression over local `vibe` whenever validating cross-platform behavior, setup wizard behavior, or user-facing IM flows
diff --git a/docker-compose.three-regression.yml b/docker-compose.three-regression.yml
index bc89a5aea..d8258da24 100644
--- a/docker-compose.three-regression.yml
+++ b/docker-compose.three-regression.yml
@@ -14,6 +14,7 @@ services:
VIBE_UI_PORT: 5123
VIBE_REMOTE_ALLOW_DOCKER_LOOPBACK_PEERS: "1"
VIBE_REMOTE_DOCKER_LOOPBACK_BIND_HOST: "${THREE_REGRESSION_PORT_BIND_HOST:-127.0.0.1}"
+ VIBE_REMOTE_DOCKER_LOOPBACK_PEER_IPS: "${THREE_REGRESSION_DOCKER_LOOPBACK_PEER_IPS:-}"
VIBE_SHOW_RUNTIME_SOURCE: "${THREE_REGRESSION_SHOW_RUNTIME_SOURCE:-github-source}"
VIBE_SHOW_RUNTIME_GITHUB_REPO: "${THREE_REGRESSION_SHOW_RUNTIME_GITHUB_REPO:-https://github.com/avibe-bot/vibe-show-runtime.git}"
VIBE_SHOW_RUNTIME_GITHUB_REF: "${THREE_REGRESSION_SHOW_RUNTIME_GITHUB_REF:-main}"
diff --git a/tests/test_ui_remote_access_auth.py b/tests/test_ui_remote_access_auth.py
index 5e9dd63de..caab1a4c0 100644
--- a/tests/test_ui_remote_access_auth.py
+++ b/tests/test_ui_remote_access_auth.py
@@ -272,6 +272,7 @@ def test_docker_loopback_health_probe_is_allowed_when_explicitly_trusted(monkeyp
monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
monkeypatch.setenv("VIBE_REMOTE_ALLOW_DOCKER_LOOPBACK_PEERS", "1")
monkeypatch.setenv("VIBE_REMOTE_DOCKER_LOOPBACK_BIND_HOST", "127.0.0.1")
+ monkeypatch.setenv("VIBE_REMOTE_DOCKER_LOOPBACK_PEER_IPS", "172.17.0.1")
_save_config(tmp_path)
response = app.test_client().get(
@@ -287,6 +288,7 @@ def test_docker_loopback_status_probe_is_allowed_when_explicitly_trusted(monkeyp
monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
monkeypatch.setenv("VIBE_REMOTE_ALLOW_DOCKER_LOOPBACK_PEERS", "1")
monkeypatch.setenv("VIBE_REMOTE_DOCKER_LOOPBACK_BIND_HOST", "127.0.0.1")
+ monkeypatch.setenv("VIBE_REMOTE_DOCKER_LOOPBACK_PEER_IPS", "172.17.0.1")
_save_config(tmp_path)
response = app.test_client().get(
@@ -302,6 +304,7 @@ def test_docker_loopback_probe_accepts_ipv4_mapped_peer(monkeypatch, tmp_path):
monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
monkeypatch.setenv("VIBE_REMOTE_ALLOW_DOCKER_LOOPBACK_PEERS", "1")
monkeypatch.setenv("VIBE_REMOTE_DOCKER_LOOPBACK_BIND_HOST", "127.0.0.1")
+ monkeypatch.setenv("VIBE_REMOTE_DOCKER_LOOPBACK_PEER_IPS", "172.17.0.1")
_save_config(tmp_path)
response = app.test_client().get(
@@ -317,6 +320,7 @@ def test_docker_loopback_trust_does_not_bypass_ui_auth(monkeypatch, tmp_path):
monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
monkeypatch.setenv("VIBE_REMOTE_ALLOW_DOCKER_LOOPBACK_PEERS", "1")
monkeypatch.setenv("VIBE_REMOTE_DOCKER_LOOPBACK_BIND_HOST", "127.0.0.1")
+ monkeypatch.setenv("VIBE_REMOTE_DOCKER_LOOPBACK_PEER_IPS", "172.17.0.1")
_save_config(tmp_path)
response = app.test_client().get(
@@ -325,8 +329,8 @@ def test_docker_loopback_trust_does_not_bypass_ui_auth(monkeypatch, tmp_path):
environ_base={"REMOTE_ADDR": "172.17.0.1"},
)
- assert response.status_code == 503
- assert response.get_json()["error"] == "remote_access_host_mismatch"
+ assert response.status_code == 200
+ assert "<!doctype html>" in response.text
def test_docker_loopback_trust_requires_loopback_port_binding(monkeypatch, tmp_path):
@@ -345,6 +349,22 @@ def test_docker_loopback_trust_requires_loopback_port_binding(monkeypatch, tmp_p
assert response.get_json()["error"] == "remote_access_host_mismatch"
+def test_docker_loopback_ui_requires_loopback_port_binding(monkeypatch, tmp_path):
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
+ monkeypatch.setenv("VIBE_REMOTE_ALLOW_DOCKER_LOOPBACK_PEERS", "1")
+ monkeypatch.setenv("VIBE_REMOTE_DOCKER_LOOPBACK_BIND_HOST", "0.0.0.0")
+ _save_config(tmp_path)
+
+ response = app.test_client().get(
+ "/dashboard",
+ base_url="http://127.0.0.1:15130",
+ environ_base={"REMOTE_ADDR": "172.17.0.1"},
+ )
+
+ assert response.status_code == 503
+ assert response.get_json()["error"] == "remote_access_host_mismatch"
+
+
def test_docker_loopback_trust_still_rejects_non_local_host(monkeypatch, tmp_path):
monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
monkeypatch.setenv("VIBE_REMOTE_ALLOW_DOCKER_LOOPBACK_PEERS", "1")
@@ -377,17 +397,100 @@ def test_docker_loopback_trust_rejects_untrusted_peer(monkeypatch, tmp_path):
assert response.get_json()["error"] == "remote_access_host_mismatch"
-def test_docker_loopback_trust_supports_configured_peer_cidrs(monkeypatch, tmp_path):
+def test_docker_loopback_trust_requires_configured_peer_ip(monkeypatch, tmp_path):
monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
monkeypatch.setenv("VIBE_REMOTE_ALLOW_DOCKER_LOOPBACK_PEERS", "1")
monkeypatch.setenv("VIBE_REMOTE_DOCKER_LOOPBACK_BIND_HOST", "127.0.0.1")
- monkeypatch.setenv("VIBE_REMOTE_DOCKER_LOOPBACK_PEER_CIDRS", "100.64.0.0/10")
+ monkeypatch.setenv("VIBE_REMOTE_DOCKER_LOOPBACK_PEER_IPS", "172.17.0.1")
_save_config(tmp_path)
response = app.test_client().get(
"/health",
base_url="http://127.0.0.1:15130",
- environ_base={"REMOTE_ADDR": "100.97.103.112"},
+ environ_base={"REMOTE_ADDR": "172.17.0.1"},
+ )
+
+ assert response.status_code == 200
+
+
+def test_docker_loopback_trust_accepts_runtime_default_gateway(monkeypatch, tmp_path):
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
+ monkeypatch.setenv("VIBE_REMOTE_ALLOW_DOCKER_LOOPBACK_PEERS", "1")
+ monkeypatch.setenv("VIBE_REMOTE_DOCKER_LOOPBACK_BIND_HOST", "127.0.0.1")
+ monkeypatch.delenv("VIBE_REMOTE_DOCKER_LOOPBACK_PEER_IPS", raising=False)
+ monkeypatch.setattr(
+ ui_server,
+ "_docker_route_table_lines",
+ lambda: [
+ "Iface\tDestination\tGateway \tFlags\tRefCnt\tUse\tMetric\tMask\t\tMTU\tWindow\tIRTT",
+ "eth0\t00000000\t010013AC\t0003\t0\t0\t0\t00000000\t0\t0\t0",
+ ],
+ )
+ _save_config(tmp_path)
+
+ response = app.test_client().get(
+ "/dashboard",
+ base_url="http://127.0.0.1:15130",
+ environ_base={"REMOTE_ADDR": "172.19.0.1"},
+ )
+
+ assert response.status_code == 200
+ assert "<!doctype html>" in response.text
+
+
+def test_docker_loopback_trust_rejects_same_network_container_peer(monkeypatch, tmp_path):
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
+ monkeypatch.setenv("VIBE_REMOTE_ALLOW_DOCKER_LOOPBACK_PEERS", "1")
+ monkeypatch.setenv("VIBE_REMOTE_DOCKER_LOOPBACK_BIND_HOST", "127.0.0.1")
+ monkeypatch.setenv("VIBE_REMOTE_DOCKER_LOOPBACK_PEER_IPS", "172.17.0.1")
+ _save_config(tmp_path)
+
+ response = app.test_client().get(
+ "/dashboard",
+ base_url="http://127.0.0.1:15130",
+ environ_base={"REMOTE_ADDR": "172.17.0.2"},
+ )
+
+ assert response.status_code == 503
+ assert response.get_json()["error"] == "remote_access_host_mismatch"
+
+
+def test_docker_loopback_trust_rejects_non_gateway_peer_on_dynamic_bridge(monkeypatch, tmp_path):
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
+ monkeypatch.setenv("VIBE_REMOTE_ALLOW_DOCKER_LOOPBACK_PEERS", "1")
+ monkeypatch.setenv("VIBE_REMOTE_DOCKER_LOOPBACK_BIND_HOST", "127.0.0.1")
+ monkeypatch.delenv("VIBE_REMOTE_DOCKER_LOOPBACK_PEER_IPS", raising=False)
+ monkeypatch.setattr(
+ ui_server,
+ "_docker_route_table_lines",
+ lambda: [
+ "Iface\tDestination\tGateway \tFlags\tRefCnt\tUse\tMetric\tMask\t\tMTU\tWindow\tIRTT",
+ "eth0\t00000000\t010013AC\t0003\t0\t0\t0\t00000000\t0\t0\t0",
+ ],
+ )
+ _save_config(tmp_path)
+
+ response = app.test_client().get(
+ "/dashboard",
+ base_url="http://127.0.0.1:15130",
+ environ_base={"REMOTE_ADDR": "172.19.0.2"},
+ )
+
+ assert response.status_code == 503
+ assert response.get_json()["error"] == "remote_access_host_mismatch"
+
+
+def test_docker_loopback_trust_accepts_ipv4_mapped_configured_peer(monkeypatch, tmp_path):
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
+ monkeypatch.setenv("VIBE_REMOTE_ALLOW_DOCKER_LOOPBACK_PEERS", "1")
+ monkeypatch.setenv("VIBE_REMOTE_DOCKER_LOOPBACK_BIND_HOST", "127.0.0.1")
+ monkeypatch.setenv("VIBE_REMOTE_DOCKER_LOOPBACK_PEER_IPS", "172.17.0.1")
+ _save_config(tmp_path)
+
+ response = app.test_client().get(
+ "/health",
+ base_url="http://127.0.0.1:15130",
+ environ_base={"REMOTE_ADDR": "::ffff:172.17.0.1"},
)
assert response.status_code == 200
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index 49a1ba9e3..be6d7ac92 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -574,6 +574,45 @@ def _has_loopback_only_docker_port_binding() -> bool:
return _is_loopback_host(bind_host)
+def _trusted_docker_loopback_peer_addresses() -> set[ipaddress._BaseAddress]:
+ addresses: set[ipaddress._BaseAddress] = set()
+ for raw_address in os.environ.get("VIBE_REMOTE_DOCKER_LOOPBACK_PEER_IPS", "").split(","):
+ raw_address = raw_address.strip()
+ if not raw_address:
+ continue
+ try:
+ address = ipaddress.ip_address(raw_address)
+ except ValueError:
+ continue
+ addresses.add(getattr(address, "ipv4_mapped", None) or address)
+ addresses.update(_docker_default_gateway_addresses())
+ return addresses
+
+
+def _docker_default_gateway_addresses() -> set[ipaddress._BaseAddress]:
+ addresses: set[ipaddress._BaseAddress] = set()
+ for line in _docker_route_table_lines()[1:]:
+ fields = line.split()
+ if len(fields) < 3 or fields[1] != "00000000":
+ continue
+ try:
+ gateway_int = int(fields[2], 16)
+ gateway = ipaddress.ip_address(gateway_int.to_bytes(4, byteorder="little"))
+ except (ValueError, OverflowError):
+ continue
+ if gateway.is_unspecified:
+ continue
+ addresses.add(gateway)
+ return addresses
+
+
+def _docker_route_table_lines() -> list[str]:
+ try:
+ return Path("/proc/net/route").read_text(encoding="utf-8").splitlines()
+ except OSError:
+ return []
+
+
def _is_trusted_docker_peer() -> bool:
if not _env_flag_enabled("VIBE_REMOTE_ALLOW_DOCKER_LOOPBACK_PEERS"):
return False
@@ -587,25 +626,10 @@ def _is_trusted_docker_peer() -> bool:
return False
address = getattr(address, "ipv4_mapped", None) or address
- cidrs = os.environ.get("VIBE_REMOTE_DOCKER_LOOPBACK_PEER_CIDRS", "172.16.0.0/12,192.168.65.0/24")
- for raw_network in cidrs.split(","):
- raw_network = raw_network.strip()
- if not raw_network:
- continue
- try:
- network = ipaddress.ip_network(raw_network, strict=False)
- except ValueError:
- continue
- if address in network:
- return True
- return False
+ return address in _trusted_docker_loopback_peer_addresses()
-def _is_trusted_docker_loopback_probe() -> bool:
- if request.method not in {"GET", "HEAD"}:
- return False
- if request.path not in {"/health", "/status"}:
- return False
+def _is_trusted_docker_loopback_request() -> bool:
if _has_forwarded_metadata():
return False
if not _is_loopback_host(request.host):
@@ -613,6 +637,14 @@ def _is_trusted_docker_loopback_probe() -> bool:
return _is_trusted_docker_peer()
+def _is_trusted_docker_loopback_probe() -> bool:
+ if request.method not in {"GET", "HEAD"}:
+ return False
+ if request.path not in {"/health", "/status"}:
+ return False
+ return _is_trusted_docker_loopback_request()
+
+
def _has_docker_loopback_probe_shape() -> bool:
return (
request.method in {"GET", "HEAD"}
@@ -866,6 +898,8 @@ def _is_local_request(config: V2Config | None = None) -> bool:
return False
if _is_loopback_peer() and _is_loopback_host(request.host):
return True
+ if _is_trusted_docker_loopback_request():
+ return True
return _is_setup_host_request(config)
@@ -1476,6 +1510,8 @@ def _websocket_is_local_request(websocket: WebSocket, config: V2Config | None =
client_address = None
if client_address is not None and client_address.is_loopback and _is_loopback_host(websocket.headers.get("host")):
return True
+ if _websocket_is_trusted_docker_loopback_request(websocket):
+ return True
return _websocket_is_setup_host_request(websocket, config)
@@ -1516,6 +1552,26 @@ def _websocket_peer_address(websocket: WebSocket) -> ipaddress._BaseAddress | No
return mapped or address
+def _websocket_is_trusted_docker_peer(websocket: WebSocket) -> bool:
+ if not _env_flag_enabled("VIBE_REMOTE_ALLOW_DOCKER_LOOPBACK_PEERS"):
+ return False
+ if not _has_loopback_only_docker_port_binding():
+ return False
+ address = _websocket_peer_address(websocket)
+ if address is None:
+ return False
+
+ return address in _trusted_docker_loopback_peer_addresses()
+
+
+def _websocket_is_trusted_docker_loopback_request(websocket: WebSocket) -> bool:
+ if _websocket_has_forwarded_metadata(websocket):
+ return False
+ if not _is_loopback_host(websocket.headers.get("host")):
+ return False
+ return _websocket_is_trusted_docker_peer(websocket)
+
+
def _websocket_is_private_peer(websocket: WebSocket) -> bool:
address = _websocket_peer_address(websocket)
return address is not None and _is_private_address(address)