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.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(ui): defer compat json parsing until after guards
cyh1ca238c32915
diff --git a/tests/test_ui_server_mutation_protection.py b/tests/test_ui_server_mutation_protection.pyindex 49a0f8bc8..c70f265f4 100644--- a/tests/test_ui_server_mutation_protection.py+++ b/tests/test_ui_server_mutation_protection.py@@ -71,6 +71,52 @@ def test_config_post_rejects_malformed_json(monkeypatch, tmp_path):assert response.status_code == 400+def test_config_post_rejects_host_mismatch_before_parsing_malformed_json(monkeypatch, tmp_path):+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))+ V2Config(+ mode="self_host",+ version="v2",+ slack=SlackConfig(bot_token=""),+ runtime=RuntimeConfig(default_cwd="."),+ agents=AgentsConfig(),+ ).save()+ client = app.test_client()+ headers = csrf_headers(client, "http://127.0.0.1:15131")++ response = client.post(+ "/config",+ content="{",+ headers={**headers, "Content-Type": "application/json"},+ base_url="https://old-alex.avibe.bot",+ )++ assert response.status_code == 503+ assert response.get_json()["error"] == "remote_access_host_mismatch"+++def test_config_post_accepts_vendor_json_content_type(monkeypatch, tmp_path):+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))+ V2Config(+ mode="self_host",+ version="v2",+ slack=SlackConfig(bot_token=""),+ runtime=RuntimeConfig(default_cwd="."),+ agents=AgentsConfig(),+ ).save()+ client = app.test_client()+ headers = csrf_headers(client, "http://127.0.0.1:15131")++ response = client.post(+ "/config",+ content='{"mode":"self_host"}',+ headers={**headers, "Content-Type": "application/vnd.api+json"},+ base_url="http://127.0.0.1:15131",+ )++ assert response.status_code == 200+ assert response.get_json()["mode"] == "self_host"++def test_config_post_allows_forwarded_origin(monkeypatch, tmp_path):monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))V2Config(diff --git a/vibe/ui_compat.py b/vibe/ui_compat.pyindex 541c901e0..ebadbf963 100644--- a/vibe/ui_compat.py+++ b/vibe/ui_compat.py@@ -423,11 +423,10 @@ class CompatApp(FastAPI):route_regex: re.Pattern[str],defaults: dict[str, Any],) -> Response:- json_payload = await _read_json_payload(starlette_request)remote_addr = _test_remote_addr_from_scope(starlette_request.scope)if remote_addr:starlette_request.scope["vibe_remote_addr"] = remote_addr- compat_request = CompatRequest(starlette_request, json_payload=json_payload)+ compat_request = CompatRequest(starlette_request)token_request = _request_var.set(compat_request)token_g = _g_var.set(type("CompatG", (), {})())try:@@ -439,6 +438,7 @@ class CompatApp(FastAPI):response = normalize_response(result)breakif response is None:+ compat_request._json_payload = await _read_json_payload(starlette_request)route_args = defaults | _extract_path_args(route_regex, compat_request.path)response = normalize_response(await run_maybe_async(func, **route_args))except Exception as exc:@@ -478,7 +478,7 @@ def _test_remote_addr_from_scope(scope: Any) -> str | None:async def _read_json_payload(request: FastAPIRequest) -> Any:content_type = request.headers.get("content-type", "")- if "application/json" not in content_type.lower():+ if not _is_json_content_type(content_type):return Nonebody = await request.body()if not body:@@ -489,6 +489,13 @@ async def _read_json_payload(request: FastAPIRequest) -> Any:raise HTTPException(status_code=400, detail="Malformed JSON")+def _is_json_content_type(content_type: str) -> bool:+ media_type = content_type.split(";", 1)[0].strip().lower()+ return media_type == "application/json" or (+ media_type.startswith("application/") and media_type.endswith("+json")+ )++def _build_scope(method: str, url: str, headers: dict[str, str]) -> dict[str, Any]:parsed = urlsplit(url)raw_headers = [(key.lower().encode("latin-1"), value.encode("latin-1")) for key, value in headers.items()]