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): fail closed local machine APIs

Max3d7aa276de4e
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 de05150e1..4c803a53c 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
@@ -35,15 +35,23 @@ 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,
- Agent-definition and instruction mutations, model/backend mutations and
- runtime operations, service control, local installers, terminal sockets,
+2. The central HTTP authorization policy defaults every unclassified remote API
+ route to trusted-local access. It explicitly permits approved remote reads and
+ management routes, and rejects remote message dispatch, Show-event Agent
+ dispatch, Agent-definition and instruction mutations, model/backend mutations
+ and runtime operations, service control, local installers, terminal sockets,
file operations including Show Page icon uploads, and Harness definition
- mutations before invoking their underlying services. The same boundary also
- rejects payloads that persist future execution choices: Session Agent/model
- overrides, Project creation/workdir/default Agent, channel/thread/
- user cwd or routing, and Agent/platform/runtime config sections. Metadata-only
- Session and Project edits and unrelated UI/config preferences remain available.
+ mutations before invoking their underlying services. Local logs and Doctor
+ reports/diagnostics are also trusted-local because they expose machine paths,
+ process state, prompts, command output, and potentially credentials. The same
+ policy payload-filters routes that persist future execution choices with
+ explicit safe-field allowlists: Session Agent/model overrides, Project
+ creation/workdir/default Agent, channel/thread/user cwd or routing, and
+ Agent/platform/runtime config sections. Unknown fields fail closed. Complete
+ config round-trips may preserve protected values but cannot change them, and
+ protected fields are stripped before persistence so a concurrent local update
+ cannot be overwritten by a stale remote round-trip. Explicit Session/Project
+ display fields and explicit UI/config preferences remain available.
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.
@@ -73,10 +81,15 @@ substitute for either dependency.
- Remote service control, installers, Agent-definition mutations, model/backend
mutations and probes, and Show Page icon writes fail before reaching their
local runtime or filesystem services.
+- Remote logs, Doctor reads/runs, UI reloads, and legacy OpenCode helpers fail
+ before any file read, diagnostic, process spawn, service exit, or config write.
+- An unknown owner-only API route is trusted-local by default; remote exposure
+ requires an exact method/path policy entry and regression evidence. A new path
+ under an already approved namespace does not inherit remote access.
- Remote execution-setting writes through Session, Project, channel, thread,
user, and config routes fail before any store save, runtime reconciliation, or
- restart scheduling; Session titles, Project display names, and unrelated UI
- preferences remain writable.
+ restart scheduling; unknown payload fields fail closed, while Session titles,
+ Project display names, and explicitly allowlisted UI preferences remain writable.
- Paired Project synchronization never forwards the device secret through an
HTTP redirect.
- Remote Task and Watch add/update calls produce no definition write.
diff --git a/tests/test_instance_authorization.py b/tests/test_instance_authorization.py
index 46b9d3110..0e2b3c137 100644
--- a/tests/test_instance_authorization.py
+++ b/tests/test_instance_authorization.py
@@ -3,8 +3,12 @@ import pytest
from vibe.authorization import (
AuthorizationContext,
InstanceAuthorizationError,
+ REMOTE_HTTP_ALLOWED,
+ REMOTE_HTTP_LOCAL_ONLY,
+ REMOTE_HTTP_PAYLOAD_FILTERED,
can_receive_workbench_event,
context_from_session_payload,
+ http_authorization_policy,
require_instance_role,
required_instance_role,
trusted_local_context,
@@ -116,6 +120,65 @@ def test_http_policy_defaults_unknown_api_to_owner() -> None:
assert required_instance_role("GET", "/assets/app.js") is None
+ ("method", "path"),
+ [
+ ("GET", "/api/doctor"),
+ ("POST", "/api/doctor"),
+ ("POST", "/api/logs"),
+ ("POST", "/api/ui/reload"),
+ ("POST", "/api/opencode/options"),
+ ("POST", "/api/opencode/setup-permission"),
+ ("GET", "/api/vault/future-capability"),
+ ("GET", "/api/dock/future-capability"),
+ ("GET", "/api/web-push/future-capability"),
+ ("GET", "/api/models/future-capability"),
+ ("GET", "/api/harness/future-capability"),
+ ("GET", "/api/users/future-capability"),
+ ("GET", "/api/bind-codes/future-capability"),
+ ("GET", "/api/future-owner-capability"),
+ ("POST", "/api/future-owner-capability"),
+ ],
+)
+def test_remote_http_policy_defaults_local_machine_and_unknown_routes_to_local_only(
+ method,
+ path,
+) -> None:
+ policy = http_authorization_policy(method, path)
+
+ assert policy.minimum_role == "owner"
+ assert policy.remote_access == REMOTE_HTTP_LOCAL_ONLY
+
+
+ ("method", "path", "expected"),
+ [
+ ("GET", "/api/projects", REMOTE_HTTP_ALLOWED),
+ ("PUT", "/api/workbench/prefs", REMOTE_HTTP_ALLOWED),
+ ("PUT", "/api/resource-policies/agent/agent-1", REMOTE_HTTP_ALLOWED),
+ ("GET", "/api/models/runtime/status", REMOTE_HTTP_ALLOWED),
+ ("GET", "/api/models/agents/codex/chain", REMOTE_HTTP_ALLOWED),
+ ("GET", "/api/backend/codex/runtime", REMOTE_HTTP_ALLOWED),
+ ("GET", "/api/opencode/permission-status", REMOTE_HTTP_ALLOWED),
+ ("GET", "/api/vault/audit", REMOTE_HTTP_ALLOWED),
+ ("POST", "/api/dock/pins", REMOTE_HTTP_ALLOWED),
+ ("POST", "/api/web-push/subscriptions", REMOTE_HTTP_ALLOWED),
+ ("GET", "/api/harness/runs/run-1", REMOTE_HTTP_ALLOWED),
+ ("POST", "/api/users/user-1/admin", REMOTE_HTTP_ALLOWED),
+ ("DELETE", "/api/bind-codes/code-1", REMOTE_HTTP_ALLOWED),
+ ("POST", "/api/config", REMOTE_HTTP_PAYLOAD_FILTERED),
+ ("PATCH", "/api/projects/proj-1", REMOTE_HTTP_PAYLOAD_FILTERED),
+ ("PATCH", "/api/sessions/ses-1", REMOTE_HTTP_PAYLOAD_FILTERED),
+ ],
+)
+def test_remote_http_policy_keeps_approved_management_and_read_surfaces(
+ method,
+ path,
+ expected,
+) -> None:
+ assert http_authorization_policy(method, path).remote_access == expected
+
+
def test_workbench_event_policy_filters_privileged_and_unknown_events() -> None:
viewer = _remote_context("viewer")
editor = _remote_context("editor")
diff --git a/tests/test_ui_remote_access_auth.py b/tests/test_ui_remote_access_auth.py
index 5dcd5cb74..c46351f1a 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
import ipaddress
+import json
import logging
import socket
import asyncio
@@ -1094,6 +1095,11 @@ def test_remote_thread_scope_settings_are_blocked_before_store_access(monkeypatc
[
{"agents": {"codex": {"cli_path": "/tmp/remote-codex"}}},
{"platforms": {"enabled": ["telegram"], "primary": "telegram"}},
+ {"remote_access": {"provider": "none"}},
+ {"ui": {"setup_host": "0.0.0.0"}},
+ {"update": {"auto_update": False}},
+ {"show_pages_prompt": "follow remote instructions"},
+ {"future_runtime": {"enabled": True}},
],
)
def test_remote_execution_config_changes_are_blocked_before_runtime_reconcile(
@@ -1138,6 +1144,109 @@ def test_remote_session_and_project_metadata_predicates_remain_allowed():
)
+ ("method", "path", "payload"),
+ [
+ ("POST", "/api/sessions", None),
+ ("POST", "/api/sessions", {"project_id": "proj-1", "future_route": "codex"}),
+ ("PATCH", "/api/sessions/ses-1", {"title": "renamed", "future_route": "codex"}),
+ ("POST", "/api/projects", {"display_name": "Project", "future_workdir": "/tmp"}),
+ ("PATCH", "/api/projects/proj-1", {"display_name": "Project", "future_route": "codex"}),
+ (
+ "POST",
+ "/api/settings",
+ {"platform": "slack", "channels": {"C1": {"enabled": True, "future_route": "codex"}}},
+ ),
+ (
+ "POST",
+ "/api/settings/thread",
+ {
+ "platform": "telegram",
+ "channel_id": "C1",
+ "thread_id": "T1",
+ "settings": {"enabled": True, "future_route": "codex"},
+ },
+ ),
+ (
+ "POST",
+ "/api/users",
+ {"platform": "slack", "users": {"U1": {"enabled": True, "future_route": "codex"}}},
+ ),
+ ],
+)
+def test_remote_payload_filtered_routes_reject_unknown_fields(method, path, payload):
+ assert ui_server._is_remote_local_execution_request(method, path, payload)
+
+
+def test_remote_config_allows_only_explicit_preferences_and_unchanged_round_trip(
+ monkeypatch,
+ tmp_path,
+):
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ config = _save_config(tmp_path)
+
+ assert not ui_server._is_remote_local_execution_request(
+ "POST",
+ "/api/config",
+ {"language": "zh", "ui": {"instance_name": "Remote label"}},
+ )
+ assert not ui_server._is_remote_local_execution_request(
+ "POST",
+ "/api/config",
+ json.loads(json.dumps(api.config_to_payload(config))),
+ )
+ assert ui_server._is_remote_local_execution_request(
+ "POST",
+ "/api/config",
+ {"ui": {"future_setting": True}},
+ )
+
+
+def test_remote_config_strips_protected_round_trip_fields_before_persistence(
+ monkeypatch,
+ tmp_path,
+):
+ 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",
+ )
+ payload = json.loads(json.dumps(api.config_to_payload(config)))
+ payload["language"] = "zh"
+ observed = []
+
+ def save_config(remote_payload):
+ observed.append(remote_payload)
+ return config, False, False, []
+
+ monkeypatch.setattr(ui_server, "_save_config_and_runtime_decisions", save_config)
+ monkeypatch.setattr(ui_server, "_ensure_remote_access_monitoring", lambda _config: None)
+ response = client.post(
+ "/api/config",
+ json=payload,
+ headers=csrf_headers(client, "https://alex.avibe.bot"),
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ )
+
+ assert response.status_code == 200
+ assert len(observed) == 1
+ assert observed[0]["language"] == "zh"
+ assert observed[0]["ui"] == {
+ field: payload["ui"][field]
+ for field in ui_server._REMOTE_UI_CONFIG_MUTABLE_FIELDS
+ }
+ assert set(observed[0]).issubset(
+ ui_server._REMOTE_CONFIG_MUTABLE_FIELDS | {"ui"}
+ )
+ assert "runtime" not in observed[0]
+ assert "agents" not in observed[0]
+ assert "remote_access" not in observed[0]
+
+
def test_remote_session_archive_is_blocked_before_store_access(
monkeypatch,
tmp_path,
@@ -1214,6 +1323,51 @@ def test_remote_system_operations_are_blocked_before_runtime_calls(
assert response.get_json()["code"] == "remote_execution_disabled"
+ ("method", "path", "json_body", "call_target"),
+ [
+ ("GET", "/api/doctor", None, "vibe.ui_server.paths.get_runtime_doctor_path"),
+ ("POST", "/api/doctor", {}, "vibe.cli._doctor"),
+ ("POST", "/api/logs", {}, "vibe.ui_server._resolve_log_sources"),
+ ("POST", "/api/ui/reload", {"host": "127.0.0.1", "port": 5123}, "vibe.runtime.read_status"),
+ ("POST", "/api/opencode/options", {"cwd": "/tmp/remote"}, "vibe.api.opencode_options_async"),
+ ("POST", "/api/opencode/setup-permission", {}, "vibe.api.setup_opencode_permission"),
+ ],
+)
+def test_remote_diagnostics_and_legacy_system_helpers_are_blocked_before_local_access(
+ monkeypatch,
+ tmp_path,
+ method,
+ 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_local_access(*args, **kwargs):
+ raise AssertionError(f"remote request reached local capability: {path}")
+
+ monkeypatch.setattr(call_target, unexpected_local_access)
+ request_kwargs = {
+ "headers": csrf_headers(client, "https://alex.avibe.bot"),
+ "base_url": "https://alex.avibe.bot",
+ "environ_base": _remote_peer(),
+ }
+ if json_body is not None:
+ request_kwargs["json"] = json_body
+ response = client.request(method, path, **request_kwargs)
+
+ assert response.status_code == 403
+ assert response.get_json()["code"] == "remote_execution_disabled"
+
+
@pytest.mark.parametrize(
("path", "call_target"),
[
diff --git a/vibe/authorization.py b/vibe/authorization.py
index 8acee191d..655590db1 100644
--- a/vibe/authorization.py
+++ b/vibe/authorization.py
@@ -36,6 +36,16 @@ _VIEWER_WORKBENCH_EVENTS = frozenset(
)
_EDITOR_WORKBENCH_EVENTS = frozenset({"queue.updated", "show.event"})
+REMOTE_HTTP_ALLOWED = "allowed"
+REMOTE_HTTP_LOCAL_ONLY = "local_only"
+REMOTE_HTTP_PAYLOAD_FILTERED = "payload_filtered"
+
+
+@dataclass(frozen=True)
+class HttpAuthorizationPolicy:
+ minimum_role: str | None
+ remote_access: str = REMOTE_HTTP_ALLOWED
+
@dataclass(frozen=True)
class AuthorizationContext:
@@ -324,30 +334,187 @@ _EDITOR_HTTP_RULES = tuple(
)
)
+_REMOTE_LOCAL_ONLY_HTTP_RULES = tuple(
+ (method, re.compile(pattern))
+ for method, pattern in (
+ ("DELETE", r"^/api/sessions/[^/]+(?:/queue/[^/]+)?$"),
+ (
+ "POST",
+ r"^/api/sessions/[^/]+/(?:messages|attachments|cancel|queue/[^/]+/send-now)$",
+ ),
+ ("POST", r"^/api/asr/transcribe$"),
+ ("POST", r"^/api/show/sessions/[^/]+/(?:events|prewarm)$"),
+ )
+)
-def required_instance_role(method: str, path: str) -> str | None:
- """Return the minimum role for a remote HTTP request.
+_REMOTE_PAYLOAD_FILTERED_HTTP_RULES = tuple(
+ (method, re.compile(pattern))
+ for method, pattern in (
+ (
+ "POST",
+ r"^/api/(?:config|projects|sessions|settings|settings/thread|users)$",
+ ),
+ ("PATCH", r"^/api/(?:projects|sessions)/[^/]+$"),
+ )
+)
- Non-API page/static reads are handled by the authenticated shell. Unknown
- API routes deliberately default to owner so a newly added management route
- cannot accidentally become available to editors or viewers.
+_REMOTE_OWNER_ALLOWED_HTTP_RULES = tuple(
+ (methods, re.compile(pattern))
+ for methods, pattern in (
+ (frozenset({"GET", "HEAD", "POST"}), r"^/api/agent-onboarding$"),
+ (
+ frozenset({"GET", "HEAD"}),
+ r"^/api/(?:agents/[^/]+|agents-graph|running-agents|settings)$",
+ ),
+ (
+ frozenset({"GET", "HEAD"}),
+ r"^/api/vault/(?:pubkey|agent/pubkey|sandbox/root-metadata|settings|vmk|requests|requests/[^/]+|provision-requests/[^/]+|provision-requests/by-id/[^/]+|grants|audit)$",
+ ),
+ (
+ frozenset({"POST"}),
+ r"^/api/vault/(?:agent-bindings:batch|agent-binding|authz/factors/webauthn/options|authz/factors/webauthn|signing-addresses|secrets|secrets/[^/]+/reveal-context|requests/[^/]+/deny|requests/[^/]+/fulfill-access|grants|sign|pubkey-pin)$",
+ ),
+ (
+ frozenset({"PATCH"}),
+ r"^/api/vault/(?:settings|secrets/[^/]+)$",
+ ),
+ (
+ frozenset({"DELETE"}),
+ r"^/api/vault/(?:secrets/[^/]+|grants/[^/]+)$",
+ ),
+ (
+ frozenset({"POST"}),
+ r"^/api/show-pages/[^/]+/(?:ensure|rotate-share|share-id|visibility)$",
+ ),
+ (frozenset({"GET", "HEAD"}), r"^/api/dock$"),
+ (frozenset({"POST"}), r"^/api/dock/pins$"),
+ (frozenset({"DELETE"}), r"^/api/dock/pins/[^/]+$"),
+ (frozenset({"PUT"}), r"^/api/dock/order$"),
+ (frozenset({"PUT"}), r"^/api/workbench/prefs$"),
+ (
+ frozenset({"GET", "HEAD"}),
+ r"^/api/web-push/(?:status|vapid-public-key)$",
+ ),
+ (
+ frozenset({"POST"}),
+ r"^/api/web-push/(?:status|subscriptions|test)$",
+ ),
+ (frozenset({"DELETE"}), r"^/api/web-push/subscriptions$"),
+ (
+ frozenset({"PUT"}),
+ r"^/api/resource-policies/[^/]+/[^/]+$",
+ ),
+ (frozenset({"DELETE"}), r"^/api/projects/[^/]+$"),
+ (
+ frozenset({"GET", "HEAD"}),
+ r"^/api/(?:projects/[^/]+/agents-md|global-prompts)$",
+ ),
+ (frozenset({"POST"}), r"^/api/skills/preview$"),
+ (frozenset({"GET", "HEAD"}), r"^/api/skills/(?:check|find)$"),
+ (
+ frozenset({"GET", "HEAD"}),
+ r"^/api/models/(?:sources|agents|events|runtime/status)$",
+ ),
+ (
+ frozenset({"GET", "HEAD"}),
+ r"^/api/models/agents/[^/]+/(?:sources|chain)$",
+ ),
+ (
+ frozenset({"GET", "HEAD"}),
+ r"^/api/models/(?:turns/[^/]+/provenance|oauth/status/[^/]+)$",
+ ),
+ (
+ frozenset({"GET", "HEAD"}),
+ r"^/api/backend/(?:[^/]+/runtime|(?:claude|codex)/auth|[^/]+/auth/oauth/status/[^/]+)$",
+ ),
+ (
+ frozenset({"GET", "HEAD"}),
+ r"^/api/(?:opencode/permission-status|remote-access/status)$",
+ ),
+ (
+ frozenset({"GET", "HEAD"}),
+ r"^/api/harness/(?:counts|tasks|watches|runs|bootstrap|runs/[^/]+)$",
+ ),
+ (frozenset({"GET", "HEAD"}), r"^/api/users$"),
+ (frozenset({"POST"}), r"^/api/users/[^/]+/admin$"),
+ (frozenset({"DELETE"}), r"^/api/users/[^/]+$"),
+ (frozenset({"GET", "HEAD", "POST"}), r"^/api/bind-codes$"),
+ (frozenset({"DELETE"}), r"^/api/bind-codes/[^/]+$"),
+ )
+)
+
+
+def _http_rule_matches(
+ method: str,
+ path: str,
+ rules: tuple[tuple[str, re.Pattern[str]], ...],
+) -> bool:
+ return any(rule_method == method and pattern.fullmatch(path) for rule_method, pattern in rules)
+
+
+def _owner_http_rule_matches(method: str, path: str) -> bool:
+ return any(
+ method in methods and pattern.fullmatch(path)
+ for methods, pattern in _REMOTE_OWNER_ALLOWED_HTTP_RULES
+ )
+
+
+def http_authorization_policy(method: str, path: str) -> HttpAuthorizationPolicy:
+ """Return role and remote-exposure policy for one HTTP request.
+
+ Explicit viewer/editor and owner-management routes keep their approved remote
+ behavior. Unknown API routes fail closed to trusted-local callers so adding a
+ new owner-only endpoint cannot silently expose local machine capabilities.
"""
normalized_method = method.upper()
- # Organization management establishes and evaluates a separate Cloud user
- # identity. Any authenticated Instance viewer may enter that identity gate;
- # the Cloud service then re-evaluates Organization role and object ownership
- # for every read and mutation.
+ # Organization management is an explicit Cloud proxy namespace. Cloud user
+ # identity and object authorization are re-evaluated by that boundary.
if path.startswith("/api/cloud-management/"):
- return "viewer"
+ return HttpAuthorizationPolicy("viewer")
if path.startswith("/show/"):
- return "viewer" if normalized_method in {"GET", "HEAD", "OPTIONS"} else "editor"
+ minimum_role = (
+ "viewer" if normalized_method in {"GET", "HEAD", "OPTIONS"} else "editor"
+ )
+ return HttpAuthorizationPolicy(minimum_role)
if not path.startswith("/api/"):
- return None
+ return HttpAuthorizationPolicy(None)
+
+ minimum_role = "owner"
for rule_method, pattern in _EDITOR_HTTP_RULES:
if normalized_method == rule_method and pattern.fullmatch(path):
- return "editor"
- if normalized_method in {"GET", "HEAD", "OPTIONS"}:
- if any(pattern.fullmatch(path) for pattern in _VIEWER_HTTP_RULES):
- return "viewer"
- return "owner"
+ minimum_role = "editor"
+ break
+ else:
+ if normalized_method in {"GET", "HEAD", "OPTIONS"} and any(
+ pattern.fullmatch(path) for pattern in _VIEWER_HTTP_RULES
+ ):
+ minimum_role = "viewer"
+
+ if _http_rule_matches(normalized_method, path, _REMOTE_LOCAL_ONLY_HTTP_RULES):
+ remote_access = REMOTE_HTTP_LOCAL_ONLY
+ elif _http_rule_matches(
+ normalized_method,
+ path,
+ _REMOTE_PAYLOAD_FILTERED_HTTP_RULES,
+ ):
+ remote_access = REMOTE_HTTP_PAYLOAD_FILTERED
+ elif minimum_role in {"viewer", "editor"} or _owner_http_rule_matches(
+ normalized_method,
+ path,
+ ):
+ remote_access = REMOTE_HTTP_ALLOWED
+ else:
+ remote_access = REMOTE_HTTP_LOCAL_ONLY
+ return HttpAuthorizationPolicy(minimum_role, remote_access)
+
+
+def required_instance_role(method: str, path: str) -> str | None:
+ """Return the minimum role for a remote HTTP request.
+
+ Non-API page/static reads are handled by the authenticated shell. Unknown
+ API routes deliberately default to owner so a newly added management route
+ cannot accidentally become available to editors or viewers.
+ """
+
+ return http_authorization_policy(method, path).minimum_role
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index bd6418492..7eef278c9 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -2216,9 +2216,11 @@ def enforce_remote_access_cookie():
def enforce_instance_role_capabilities():
if _remote_auth_exempt_path():
return None
- from vibe.authorization import required_instance_role
+ from vibe.authorization import http_authorization_policy
- minimum_role = required_instance_role(request.method, request.path)
+ policy = http_authorization_policy(request.method, request.path)
+ g.http_authorization_policy = policy
+ minimum_role = policy.minimum_role
if minimum_role is None:
return None
context = getattr(g, "authorization_context", None)
@@ -2233,50 +2235,55 @@ def enforce_instance_role_capabilities():
return None
-_SESSION_EXECUTION_SETTING_FIELDS = frozenset(
+_REMOTE_CONFIG_MUTABLE_FIELDS = frozenset(
{
- "agent_backend",
- "agent_id",
- "agent_name",
- "agent_variant",
- "model",
- "reasoning_effort",
- "scope_id",
+ "ack_mode",
+ "agent_progress_style",
+ "agent_status_heartbeat_ms",
+ "agent_status_no_output_ms",
+ "include_time_info",
+ "include_user_info",
+ "language",
+ "reply_enhancements",
+ "show_duration",
}
)
-_PROJECT_EXECUTION_SETTING_FIELDS = frozenset(
+_REMOTE_UI_CONFIG_MUTABLE_FIELDS = frozenset(
{
- "agent_backend",
- "agent_id",
- "agent_name",
- "agent_variant",
- "expected_agent_id",
- "folder_path",
- "model",
- "reasoning_effort",
+ "chat_message_font_size",
+ "instance_name",
+ "show_agent_activity",
+ "show_tool_calls",
}
)
-_SCOPE_EXECUTION_SETTING_FIELDS = frozenset(
- {"custom_cwd", "expected_agent_name", "routing"}
+_REMOTE_CHANNEL_SETTING_FIELDS = frozenset(
+ {"enabled", "require_bind", "require_mention", "show_message_types"}
)
-_CONFIG_EXECUTION_SETTING_FIELDS = frozenset(
+_REMOTE_SETTINGS_FIELDS = frozenset(
{
- "agents",
- "audio_asr",
- "gateway",
- "memory",
- "model_hub",
+ "channels",
+ "guild_allowlist",
+ "guild_default_enabled",
+ "guilds",
"platform",
- "platforms",
- "runtime",
- "show_pages_prompt",
- "update",
+ }
+)
+_REMOTE_THREAD_SETTINGS_FIELDS = frozenset(
+ {"channel_id", "platform", "settings", "thread_id"}
+)
+_REMOTE_USER_SETTING_FIELDS = frozenset(
+ {
+ "bound_at",
+ "display_name",
+ "enabled",
+ "is_admin",
+ "show_message_types",
}
)
-def _payload_has_any_field(payload: Any, fields: frozenset[str] | set[str]) -> bool:
- return isinstance(payload, dict) and not fields.isdisjoint(payload)
+def _payload_has_only_fields(payload: Any, fields: frozenset[str] | set[str]) -> bool:
+ return isinstance(payload, dict) and set(payload).issubset(fields)
def _payload_changes_values(payload: Any, current: Any) -> bool:
@@ -2284,7 +2291,7 @@ def _payload_changes_values(payload: Any, current: Any) -> bool:
Config saves accept both complete UI round-trips and partial updates. Comparing
only supplied leaves lets an unchanged complete payload pass while still
- rejecting a remote caller that changes any execution-sensitive value.
+ rejecting a remote caller that changes any protected value.
"""
if isinstance(payload, dict):
@@ -2297,146 +2304,167 @@ def _payload_changes_values(payload: Any, current: Any) -> bool:
return payload != current
-def _config_execution_setting_fields() -> set[str]:
- from config.platform_registry import im_platform_descriptors
+def _remote_config_payload_is_allowed(payload: Any) -> bool:
+ """Allow explicit UI/message preferences and unchanged config round-trips.
+
+ Every other current or future config field is protected. A full payload from
+ GET /api/config remains valid only while all protected values are unchanged.
+ """
+
+ if not isinstance(payload, dict):
+ return False
+ from vibe import api
- return set(_CONFIG_EXECUTION_SETTING_FIELDS) | {
- descriptor.config_key for descriptor in im_platform_descriptors()
+ current = _load_remote_access_config()
+ if current is None:
+ return False
+ # Compare the request with the same JSON representation the browser received;
+ # catalog tuples become arrays on the wire and must not look like mutations.
+ current_payload = json.loads(json.dumps(api.config_to_payload(current)))
+ for field, value in payload.items():
+ if field in _REMOTE_CONFIG_MUTABLE_FIELDS:
+ continue
+ if field == "ui":
+ if not isinstance(value, dict):
+ return False
+ current_ui = current_payload.get("ui")
+ if not isinstance(current_ui, dict):
+ return False
+ if any(
+ ui_field not in _REMOTE_UI_CONFIG_MUTABLE_FIELDS
+ and (
+ ui_field not in current_ui
+ or _payload_changes_values(ui_value, current_ui[ui_field])
+ )
+ for ui_field, ui_value in value.items()
+ ):
+ return False
+ continue
+ if field not in current_payload or _payload_changes_values(
+ value,
+ current_payload[field],
+ ):
+ return False
+ return True
+
+
+def _remote_mutable_config_payload(payload: dict[str, Any]) -> dict[str, Any]:
+ """Strip unchanged protected config fields before the persistence boundary."""
+
+ mutable = {
+ field: value
+ for field, value in payload.items()
+ if field in _REMOTE_CONFIG_MUTABLE_FIELDS
}
+ ui = payload.get("ui")
+ if isinstance(ui, dict):
+ mutable_ui = {
+ field: value
+ for field, value in ui.items()
+ if field in _REMOTE_UI_CONFIG_MUTABLE_FIELDS
+ }
+ if mutable_ui:
+ mutable["ui"] = mutable_ui
+ return mutable
-def _remote_execution_payload_route(method: str, path: str) -> bool:
- normalized_method = method.upper()
- if normalized_method == "POST" and path in {
- "/api/config",
- "/api/projects",
- "/api/sessions",
- "/api/settings",
- "/api/settings/thread",
- "/api/users",
- }:
- return True
- return normalized_method == "PATCH" and bool(
- re.fullmatch(r"/api/(?:projects|sessions)/[^/]+", path)
+def _remote_scope_collection_is_allowed(
+ payload: Any,
+ *,
+ item_fields: frozenset[str],
+) -> bool:
+ return isinstance(payload, dict) and all(
+ _payload_has_only_fields(item, item_fields) for item in payload.values()
)
-def _payload_selects_remote_local_execution(method: str, path: str, payload: Any) -> bool:
+def _remote_settings_payload_is_allowed(payload: Any) -> bool:
+ if not _payload_has_only_fields(payload, _REMOTE_SETTINGS_FIELDS):
+ return False
+ if "channels" in payload and not _remote_scope_collection_is_allowed(
+ payload.get("channels"),
+ item_fields=_REMOTE_CHANNEL_SETTING_FIELDS,
+ ):
+ return False
+ if "guilds" in payload and not _remote_scope_collection_is_allowed(
+ payload.get("guilds"),
+ item_fields=frozenset({"enabled"}),
+ ):
+ return False
+ return True
+
+
+def _remote_payload_is_allowed(method: str, path: str, payload: Any) -> bool:
normalized_method = method.upper()
if normalized_method == "POST" and path == "/api/config":
- if not isinstance(payload, dict):
- return False
- sensitive_fields = _config_execution_setting_fields()
- supplied_sensitive = sensitive_fields.intersection(payload)
- if not supplied_sensitive:
- return False
- from vibe import api
-
- current = _load_remote_access_config()
- if current is None:
- return True
- current_payload = api.config_to_payload(current)
- return any(
- _payload_changes_values(payload[field], current_payload.get(field))
- for field in supplied_sensitive
- )
+ return _remote_config_payload_is_allowed(payload)
if normalized_method == "POST" and path == "/api/sessions":
- return _payload_has_any_field(payload, _SESSION_EXECUTION_SETTING_FIELDS)
+ return _payload_has_only_fields(payload, {"project_id", "title"})
if normalized_method == "PATCH" and re.fullmatch(r"/api/sessions/[^/]+", path):
- return _payload_has_any_field(payload, _SESSION_EXECUTION_SETTING_FIELDS)
+ return _payload_has_only_fields(payload, {"pinned", "title", "visibility"})
if normalized_method == "PATCH" and re.fullmatch(r"/api/projects/[^/]+", path):
- return _payload_has_any_field(payload, _PROJECT_EXECUTION_SETTING_FIELDS)
+ return _payload_has_only_fields(payload, {"display_name"})
if normalized_method == "POST" and path == "/api/settings":
- channels = payload.get("channels") if isinstance(payload, dict) else None
- return isinstance(channels, dict) and any(
- _payload_has_any_field(channel, _SCOPE_EXECUTION_SETTING_FIELDS)
- for channel in channels.values()
- if isinstance(channel, dict)
- )
+ return _remote_settings_payload_is_allowed(payload)
if normalized_method == "POST" and path == "/api/settings/thread":
- settings = payload.get("settings") if isinstance(payload, dict) else None
- return _payload_has_any_field(settings, _SCOPE_EXECUTION_SETTING_FIELDS)
+ if not _payload_has_only_fields(payload, _REMOTE_THREAD_SETTINGS_FIELDS):
+ return False
+ return _payload_has_only_fields(
+ payload.get("settings"),
+ _REMOTE_CHANNEL_SETTING_FIELDS,
+ )
if normalized_method == "POST" and path == "/api/users":
- users = payload.get("users") if isinstance(payload, dict) else None
- return isinstance(users, dict) and any(
- _payload_has_any_field(user, _SCOPE_EXECUTION_SETTING_FIELDS)
- for user in users.values()
- if isinstance(user, dict)
+ if not _payload_has_only_fields(payload, {"platform", "users"}):
+ return False
+ return _remote_scope_collection_is_allowed(
+ payload.get("users"),
+ item_fields=_REMOTE_USER_SETTING_FIELDS,
)
if normalized_method == "POST" and path == "/api/projects":
- return _payload_has_any_field(payload, {"folder_path"})
+ return _payload_has_only_fields(payload, {"display_name"})
return False
def _is_remote_local_execution_request(method: str, path: str, payload: Any = None) -> bool:
- normalized_method = method.upper()
- is_mutation = normalized_method not in {"GET", "HEAD", "OPTIONS"}
- if path.startswith(("/api/files/", "/api/browse")):
- return True
- if path.startswith("/api/terminal/"):
- return True
- if is_mutation and path.startswith(("/api/harness/", "/api/models/", "/api/backend/")):
- return True
- if normalized_method == "POST" and re.fullmatch(r"/api/show-pages/[^/]+/icon", path):
- return True
- 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)
- ):
- return True
- if normalized_method == "DELETE" and (
- re.fullmatch(r"/api/skills/[^/]+", path)
- or re.fullmatch(r"/api/sessions/[^/]+(?:/queue/[^/]+)?", path)
- or path == "/api/settings/thread"
- ):
- return True
- if normalized_method == "POST" and bool(
- re.fullmatch(
- r"/api/sessions/[^/]+/(?:messages|attachments|cancel|queue/[^/]+/send-now)",
- path,
- )
- ):
+ from vibe.authorization import (
+ REMOTE_HTTP_LOCAL_ONLY,
+ REMOTE_HTTP_PAYLOAD_FILTERED,
+ http_authorization_policy,
+ )
+
+ remote_access = http_authorization_policy(method, path).remote_access
+ if remote_access == REMOTE_HTTP_LOCAL_ONLY:
return True
- return _payload_selects_remote_local_execution(method, path, payload)
+ if remote_access != REMOTE_HTTP_PAYLOAD_FILTERED:
+ return False
+ return not _remote_payload_is_allowed(method, path, payload)
@app.before_request
async def enforce_remote_local_execution_boundary():
- """Keep shell-capable Workbench surfaces on the trusted-local origin."""
+ """Keep unapproved local-machine capabilities on the trusted-local origin."""
context = getattr(g, "authorization_context", None)
if context is None or not context.is_remote:
return None
- if _is_remote_local_execution_request(request.method, request.path):
+ from vibe.authorization import (
+ REMOTE_HTTP_LOCAL_ONLY,
+ REMOTE_HTTP_PAYLOAD_FILTERED,
+ http_authorization_policy,
+ )
+
+ policy = getattr(g, "http_authorization_policy", None)
+ if policy is None:
+ policy = http_authorization_policy(request.method, request.path)
+ if policy.remote_access == REMOTE_HTTP_LOCAL_ONLY:
return _remote_execution_disabled_response()
- if not _remote_execution_payload_route(request.method, request.path):
+ if policy.remote_access != REMOTE_HTTP_PAYLOAD_FILTERED:
return None
payload = await request.load_json()
if _is_remote_local_execution_request(request.method, request.path, payload):
return _remote_execution_disabled_response()
+ if request.method == "POST" and request.path == "/api/config":
+ g.remote_mutable_config_payload = _remote_mutable_config_payload(payload)
return None
@@ -5370,7 +5398,12 @@ async def config_post():
from vibe import internal_client
from vibe import remote_access
- payload = request.json or {}
+ remote_mutable_payload = getattr(g, "remote_mutable_config_payload", None)
+ payload = (
+ remote_mutable_payload
+ if remote_mutable_payload is not None
+ else request.json or {}
+ )
remote_access_runtime = None
try:
(