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(security): close remaining release gate gaps

Max11346e5dddf7
diff --git a/docs/plans/2026-08-04-org-master-conservative-harness-gate.md b/docs/plans/2026-08-04-org-master-conservative-harness-gate.md
index 953c5a252..0c20c2115 100644
--- a/docs/plans/2026-08-04-org-master-conservative-harness-gate.md
+++ b/docs/plans/2026-08-04-org-master-conservative-harness-gate.md
@@ -36,8 +36,9 @@ entitlement mirror before remote recurring execution can be enabled.
1. The signed HTTP session projects remote `can_chat`, terminal, file, and
system execution capabilities as false.
2. The UI server rejects remote message dispatch, Show-event Agent dispatch,
- terminal sockets, file operations, and Harness definition mutations before
- invoking their underlying services.
+ Agent-definition and instruction mutations, service control, local
+ installers, terminal sockets, file operations, and Harness definition
+ mutations before invoking their underlying services.
3. The durable Delivery owner retires remote-origin queue entries before the
FIFO claim that starts an Agent turn.
4. Task and Watch stores reject explicit remote definition writes.
@@ -64,6 +65,10 @@ substitute for either dependency.
- Remote Workbench message and Show dispatch do not reserve or start a turn.
- Remote terminal and file requests fail closed; trusted-local requests retain
existing behavior.
+- Remote service control, installers, and Agent-definition mutations fail before
+ reaching their local runtime services.
+- Paired Project synchronization never forwards the device secret through an
+ HTTP redirect.
- Remote Task and Watch add/update calls produce no definition write.
- Existing remote-origin Tasks and Watches are disabled before command, waiter,
or Agent dispatch.
diff --git a/main.py b/main.py
index f50844a8d..914bac8ba 100644
--- a/main.py
+++ b/main.py
@@ -130,16 +130,6 @@ def _stop_macos_session_diagnostics(monitor: Any) -> None:
logging.getLogger(__name__).debug("macOS session diagnostics cleanup failed")
-def _request_controller_loop_stop(controller: Any) -> bool:
- """Ask a running controller loop to exit so its finally block can clean up."""
-
- loop = getattr(controller, "_loop", None)
- if loop is None or loop.is_closed() or not loop.is_running():
- return False
- loop.call_soon_threadsafe(loop.stop)
- return True
-
-
def main():
"""Main entry point"""
lock_acquired = False
@@ -203,9 +193,6 @@ def main():
logger.info("Shutting down after signal %s", signum)
except Exception:
pass
- if _request_controller_loop_stop(controller):
- return
- _stop_macos_session_diagnostics(macos_session_diagnostics)
controller.request_shutdown(f"signal {signum}")
signal.signal(signal.SIGTERM, _handle_shutdown)
diff --git a/tests/test_macos_session_diagnostics.py b/tests/test_macos_session_diagnostics.py
index 0a4698a02..4a2451da2 100644
--- a/tests/test_macos_session_diagnostics.py
+++ b/tests/test_macos_session_diagnostics.py
@@ -352,11 +352,25 @@ def test_service_main_owns_monitor_shutdown(monkeypatch) -> None:
def stop(self) -> None:
calls.append("diagnostics.stop")
+ class FakeRunningLoop:
+ def is_closed(self) -> bool:
+ return False
+
+ def is_running(self) -> bool:
+ return True
+
+ def stop(self) -> None:
+ calls.append("loop.stop")
+
+ def call_soon_threadsafe(self, callback) -> None:
+ calls.append("loop.stop.scheduled")
+
class FakeController:
service_lock_safe_to_release = True
def __init__(self, config) -> None:
calls.append("controller.init")
+ self._loop = FakeRunningLoop()
def run(self) -> None:
calls.append("controller.run")
@@ -400,5 +414,6 @@ def test_service_main_owns_monitor_shutdown(monkeypatch) -> None:
assert calls.index("controller.shutdown:signal 15") < calls.index(
"controller.after-signal"
)
+ assert "loop.stop.scheduled" not in calls
assert calls.index("controller.run") < calls.index("diagnostics.stop")
assert calls.index("controller.after-signal") < calls.index("lock.release")
diff --git a/tests/test_project_access_sync.py b/tests/test_project_access_sync.py
index fc648e2c2..7cc2feb5a 100644
--- a/tests/test_project_access_sync.py
+++ b/tests/test_project_access_sync.py
@@ -2,6 +2,7 @@ from __future__ import annotations
from dataclasses import dataclass
+import pytest
import requests
from config.v2_config import (
@@ -103,6 +104,7 @@ def test_sync_publishes_applies_and_acks_exact_revision(monkeypatch, tmp_path) -
def request(method, url, **kwargs):
calls.append((method, url, kwargs.get("json")))
assert kwargs["headers"]["X-Vibe-Device-Secret"] == "device-secret"
+ assert kwargs["allow_redirects"] is False
if url.endswith("/project-index"):
return _Response({"poll_after_seconds": 30, "projects": []})
if url.endswith("/project-access-intents"):
@@ -152,6 +154,27 @@ def test_sync_publishes_applies_and_acks_exact_revision(monkeypatch, tmp_path) -
assert policy["last_applied_control_plane_revision"] == 2
+def test_project_sync_rejects_redirects_without_forwarding_device_secret(monkeypatch) -> None:
+ def request(method, url, **kwargs):
+ assert method == "POST"
+ assert url == "https://control.example/project-index"
+ assert kwargs["headers"]["X-Vibe-Device-Secret"] == "device-secret"
+ assert kwargs["allow_redirects"] is False
+ return _Response({}, status_code=307)
+
+ monkeypatch.setattr(project_access_sync.requests, "request", request)
+
+ with pytest.raises(
+ project_access_sync.ProjectAccessSyncError,
+ match="project_access_sync_redirect_blocked",
+ ):
+ project_access_sync._request_json(
+ "POST",
+ "https://control.example/project-index",
+ device_secret="device-secret",
+ )
+
+
def test_lost_ack_retries_without_reapplying_policy(monkeypatch, tmp_path) -> None:
engine, project = _create_project(tmp_path)
ack_attempts = 0
diff --git a/tests/test_service_logging_handlers.py b/tests/test_service_logging_handlers.py
index 062c27cf5..4f697725c 100644
--- a/tests/test_service_logging_handlers.py
+++ b/tests/test_service_logging_handlers.py
@@ -165,26 +165,3 @@ def test_shutdown_signal_logging_is_lightweight(monkeypatch, caplog):
main._log_shutdown_signal(logger, signal.SIGTERM)
assert "Received signal 15 pid=123 ppid=1 pgid=123 sid=123" in caplog.text
-
-
-def test_request_controller_loop_stop_schedules_cleanup_via_run_finally():
- callbacks = []
-
- class Loop:
- def is_closed(self):
- return False
-
- def is_running(self):
- return True
-
- def stop(self):
- callbacks.append("stop")
-
- def call_soon_threadsafe(self, callback):
- callbacks.append(callback)
-
- loop = Loop()
- controller = type("Controller", (), {"_loop": loop})()
-
- assert main._request_controller_loop_stop(controller) is True
- assert callbacks == [loop.stop]
diff --git a/tests/test_ui_remote_access_auth.py b/tests/test_ui_remote_access_auth.py
index 80e066997..adfdabce2 100644
--- a/tests/test_ui_remote_access_auth.py
+++ b/tests/test_ui_remote_access_auth.py
@@ -960,6 +960,95 @@ def test_remote_session_archive_is_blocked_before_store_access(
assert response.get_json()["code"] == "remote_execution_disabled"
+ ("path", "json_body", "call_target"),
+ [
+ ("/api/control", {"action": "restart"}, "vibe.runtime.read_status"),
+ ("/api/upgrade", {}, "vibe.api.do_upgrade"),
+ ("/api/agent/codex/install", {}, "vibe.api.start_agent_install_job"),
+ (
+ "/api/dependencies/askill/install",
+ {},
+ "vibe.api.start_dependency_install_job",
+ ),
+ ],
+)
+def test_remote_system_operations_are_blocked_before_runtime_calls(
+ monkeypatch,
+ tmp_path,
+ path,
+ json_body,
+ call_target,
+):
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ config = _save_config(tmp_path)
+ client = app.test_client()
+ client.set_cookie(
+ remote_access.SESSION_COOKIE_NAME,
+ remote_session_cookie(config, "[email protected]", "user-owner"),
+ domain="alex.avibe.bot",
+ )
+
+ def unexpected_runtime_call(*args, **kwargs):
+ raise AssertionError("remote system operation reached the local runtime")
+
+ monkeypatch.setattr(call_target, unexpected_runtime_call)
+ response = client.post(
+ path,
+ json=json_body,
+ headers=csrf_headers(client, "https://alex.avibe.bot"),
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ )
+
+ assert response.status_code == 403
+ assert response.get_json()["code"] == "remote_execution_disabled"
+
+
+ ("method", "path", "json_body", "api_method"),
+ [
+ ("POST", "/api/agents", {"name": "remote"}, "create_vibe_agent"),
+ ("POST", "/api/agents/import", {}, "import_vibe_agents"),
+ ("POST", "/api/agents/default", {"name": "remote"}, "set_default_vibe_agent"),
+ ("PATCH", "/api/agents/remote", {"enabled": False}, "update_vibe_agent"),
+ ("DELETE", "/api/agents/remote", None, "remove_vibe_agent"),
+ ],
+)
+def test_remote_agent_definition_mutations_are_blocked_before_api_calls(
+ monkeypatch,
+ tmp_path,
+ method,
+ path,
+ json_body,
+ api_method,
+):
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ config = _save_config(tmp_path)
+ client = app.test_client()
+ client.set_cookie(
+ remote_access.SESSION_COOKIE_NAME,
+ remote_session_cookie(config, "[email protected]", "user-owner"),
+ domain="alex.avibe.bot",
+ )
+
+ def unexpected_agent_call(*args, **kwargs):
+ raise AssertionError("remote Agent mutation reached the local Agent API")
+
+ monkeypatch.setattr(api, api_method, unexpected_agent_call)
+ response = client.request(
+ method,
+ path,
+ json=json_body,
+ headers=csrf_headers(client, "https://alex.avibe.bot"),
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ )
+
+ assert response.status_code == 403
+ assert response.get_json()["code"] == "remote_execution_disabled"
+
+
@pytest.mark.parametrize(
("method", "path", "json_body", "api_method"),
[
diff --git a/ui/src/features/organization/policy.test.ts b/ui/src/features/organization/policy.test.ts
index 9d7da54e4..e760a4094 100644
--- a/ui/src/features/organization/policy.test.ts
+++ b/ui/src/features/organization/policy.test.ts
@@ -97,12 +97,13 @@ describe('Organization policy helpers', () => {
expect(requiresProjectAccessNarrowingConfirmation('restricted', [viewer], 'inherit', [])).toBe(false);
});
- it('requires confirmation only when a Resource audience shrinks', () => {
+ it('requires confirmation for every Resource access narrowing', () => {
expect(requiresResourceAccessNarrowingConfirmation('public', [], 'scope', ['group-1'])).toBe(true);
expect(requiresResourceAccessNarrowingConfirmation('public', [], 'private', [])).toBe(true);
expect(requiresResourceAccessNarrowingConfirmation('scope', ['group-1'], 'private', [])).toBe(true);
expect(requiresResourceAccessNarrowingConfirmation('scope', ['group-1', 'group-2'], 'scope', ['group-1'])).toBe(true);
- expect(requiresResourceAccessNarrowingConfirmation('private', [], 'scope', ['group-1'])).toBe(false);
+ expect(requiresResourceAccessNarrowingConfirmation('private', [], 'scope', ['group-1'])).toBe(true);
+ expect(requiresResourceAccessNarrowingConfirmation('private', [], 'public', [])).toBe(false);
expect(requiresResourceAccessNarrowingConfirmation('scope', ['group-1'], 'public', [])).toBe(false);
expect(requiresResourceAccessNarrowingConfirmation('scope', ['group-1'], 'scope', ['group-1', 'group-2'])).toBe(false);
});
diff --git a/ui/src/features/organization/policy.ts b/ui/src/features/organization/policy.ts
index b078e1da8..f92c44364 100644
--- a/ui/src/features/organization/policy.ts
+++ b/ui/src/features/organization/policy.ts
@@ -79,6 +79,7 @@ export function requiresResourceAccessNarrowingConfirmation(
scope: 1,
public: 2,
};
+ if (currentLevel === 'private') return nextLevel === 'scope';
if (audienceBreadth[nextLevel] < audienceBreadth[currentLevel]) return true;
if (currentLevel !== 'scope' || nextLevel !== 'scope') return false;
diff --git a/vibe/project_access_sync.py b/vibe/project_access_sync.py
index 8c61dc775..642fc61b9 100644
--- a/vibe/project_access_sync.py
+++ b/vibe/project_access_sync.py
@@ -99,9 +99,12 @@ def _request_json(
"X-Vibe-Device-Secret": device_secret,
},
timeout=timeout,
+ allow_redirects=False,
)
except requests.RequestException as error:
raise ProjectAccessSyncError("project_access_sync_unreachable") from error
+ if 300 <= response.status_code < 400:
+ raise ProjectAccessSyncError("project_access_sync_redirect_blocked")
try:
body = response.json()
except ValueError as error:
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index 4297256b2..5e9227d4f 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -2248,11 +2248,26 @@ def _is_remote_local_execution_request(method: str, path: str) -> bool:
if normalized_method == "POST" and path == "/api/running-agents/end":
return True
if normalized_method == "POST" and path in {
+ "/api/agents",
+ "/api/agents/default",
+ "/api/agents/import",
+ "/api/control",
"/api/skills",
"/api/skills/update",
"/api/skills/upload",
+ "/api/upgrade",
}:
return True
+ if normalized_method == "POST" and re.fullmatch(
+ r"/api/(?:agent/[^/]+|dependencies/[^/]+)/install",
+ path,
+ ):
+ return True
+ if normalized_method in {"PATCH", "DELETE"} and re.fullmatch(
+ r"/api/agents/[^/]+",
+ path,
+ ):
+ return True
if normalized_method == "PUT" and (
path == "/api/global-prompts"
or re.fullmatch(r"/api/projects/[^/]+/agents-md", path)