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(authorization): keep unrelated OAuth callbacks and remote project pickers from dead-ending

Max76ca13209686
diff --git a/tests/test_cloud_management.py b/tests/test_cloud_management.py
index e08ee8155..5ccaeb1fc 100644
--- a/tests/test_cloud_management.py
+++ b/tests/test_cloud_management.py
@@ -626,6 +626,77 @@ def test_callback_state_and_code_fail_with_distinct_errors(monkeypatch, tmp_path
assert invalid_code.value.code == "invalid_cloud_management_code"
+def _connected_callback_client(config: V2Config):
+ """A browser that already holds a live management grant."""
+
+ client = _remote_client(config)
+ client.set_cookie(cloud_management.HANDLE_COOKIE_NAME, "grant-1", domain="alex.avibe.bot")
+ client.set_cookie(cloud_management.BROWSER_COOKIE_NAME, "browser-1", domain="alex.avibe.bot")
+ cloud_management._grants["grant-1"] = _grant()
+ return client
+
+
+def _handle_cookie_cleared(response) -> bool:
+ return any(
+ value.startswith(f"{cloud_management.HANDLE_COOKIE_NAME}=") and "Max-Age=0" in value
+ for value in response.headers.getlist("set-cookie")
+ )
+
+
+ "query",
+ [
+ # Forged authorization response: no handshake matches this state.
+ "?code=code-1&state=forged-state",
+ # Forged upstream failure on the same unrelated state.
+ "?error=access_denied&state=forged-state",
+ # No state at all, as a bare cross-site link would send.
+ "",
+ ],
+)
+def test_unrelated_callback_never_revokes_an_active_grant(monkeypatch, tmp_path, query: str) -> None:
+ """The callback is unauthenticated and CSRF-exempt, so a cross-site link
+ reaches it with the `SameSite=Lax` management cookies attached. A failure
+ that cannot be tied to this browser's own handshake must leave the existing
+ grant intact instead of letting any site force a logout."""
+
+ config = _save_config(monkeypatch, tmp_path)
+ client = _connected_callback_client(config)
+
+ response = client.get(f"/auth/organization/callback{query}", base_url=REMOTE_ORIGIN)
+
+ assert response.status_code == 302
+ assert not _handle_cookie_cleared(response)
+ assert cloud_management.resolve_grant("grant-1", "browser-1", None)[0] is not None
+
+
+def test_own_flow_callback_failure_still_revokes_the_grant(monkeypatch, tmp_path) -> None:
+ """A failure on a handshake this browser actually started is a real
+ reauthorization signal, so the stale grant is still torn down."""
+
+ config = _save_config(monkeypatch, tmp_path)
+ client = _connected_callback_client(config)
+ monkeypatch.setattr(
+ cloud_management,
+ "_validated_backend",
+ lambda _config: SimpleNamespace(base_url="https://avibe.bot"),
+ )
+ _, state = cloud_management.begin_authorization(
+ config,
+ browser_id="browser-1",
+ remote_subject=None,
+ callback_origin=REMOTE_ORIGIN,
+ next_path="/admin/organization/overview",
+ silent=False,
+ )
+
+ response = client.get(f"/auth/organization/callback?state={state}", base_url=REMOTE_ORIGIN)
+
+ assert response.status_code == 302
+ assert _handle_cookie_cleared(response)
+ assert cloud_management.resolve_grant("grant-1", "browser-1", None)[0] is None
+
+
def test_management_token_is_verified_with_real_rsa_jwks(monkeypatch, tmp_path) -> None:
config = _save_config(monkeypatch, tmp_path)
private_key = rsa.generate_private_key(public_exponent=65537, key_size=2048)
diff --git a/ui/src/components/workbench/ProjectSettingsDialog.tsx b/ui/src/components/workbench/ProjectSettingsDialog.tsx
index dffe54f56..5a0fedc3f 100644
--- a/ui/src/components/workbench/ProjectSettingsDialog.tsx
+++ b/ui/src/components/workbench/ProjectSettingsDialog.tsx
@@ -13,7 +13,7 @@ import { InfoHint } from '../ui/info-hint';
import { AgentRoutePicker } from './AgentRoutePicker';
import type { AgentRoutePatch } from './AgentRoutePicker';
import { ProjectAgentsMdDialog } from './ProjectAgentsMdDialog';
-import { canEditProjectInstructions } from '../../lib/remoteAuth';
+import { canEditProjectDefaultAgent, canEditProjectInstructions } from '../../lib/remoteAuth';
// Per-project settings. Three sections:
// 1. Working directory (read-only) — where the Agent runs.
@@ -35,6 +35,10 @@ export const ProjectSettingsDialog: React.FC<{
// Reading and saving AGENTS.md are both local-only, so the shortcut is only
// offered where the editor can actually load the file.
const canEditAgentsMd = capabilities.can_manage_projects && canEditProjectInstructions({ remote });
+ // The remote project PATCH filter keeps only `display_name`, so every pick the
+ // route picker persists would dead-end in `remote_execution_disabled`; the
+ // section is offered only where it can actually save.
+ const canEditDefaultAgent = capabilities.can_manage_projects && canEditProjectDefaultAgent({ remote });
const [agents, setAgents] = useState<VibeAgentBrief[]>([]);
const [agentsMdOpen, setAgentsMdOpen] = useState(false);
@@ -100,6 +104,7 @@ export const ProjectSettingsDialog: React.FC<{
</section>
{/* 2. Default Agent (backend + model + effort). */}
+ {canEditDefaultAgent ? (
<section className="flex flex-col gap-1.5">
<div className="flex items-center gap-1.5">
<span className="text-[12px] font-semibold text-foreground">
@@ -121,6 +126,7 @@ export const ProjectSettingsDialog: React.FC<{
onNavigateAway={onClose}
/>
</section>
+ ) : null}
{/* 3. Project guidance prompt → the existing AGENTS.md editor. */}
{canEditAgentsMd ? (
diff --git a/ui/src/lib/remoteAuth.test.ts b/ui/src/lib/remoteAuth.test.ts
index 5ec3b7788..3f37ff037 100644
--- a/ui/src/lib/remoteAuth.test.ts
+++ b/ui/src/lib/remoteAuth.test.ts
@@ -11,6 +11,7 @@ import {
canAdministerMemory,
canArchiveProjects,
canEditAgentDefinitions,
+ canEditProjectDefaultAgent,
canEditProjectInstructions,
canManageSkills,
canManageVaultSecrets,
@@ -45,6 +46,7 @@ describe('local-only workbench controls', () => {
canUseHarness,
canArchiveProjects,
canEditProjectInstructions,
+ canEditProjectDefaultAgent,
canAdministerMemory,
};
diff --git a/ui/src/lib/remoteAuth.ts b/ui/src/lib/remoteAuth.ts
index e5f85548b..7b52d6d52 100644
--- a/ui/src/lib/remoteAuth.ts
+++ b/ui/src/lib/remoteAuth.ts
@@ -107,6 +107,17 @@ export function canEditProjectInstructions(context: RemoteContext): boolean {
return isTrustedLocal(context);
}
+/**
+ * A Project's default Agent is local-only. `PATCH /api/projects/{id}` is
+ * payload-filtered remotely down to `display_name`, so the rename this dialog
+ * shares stays permitted while every default-Agent field the picker persists
+ * (`agent_id`, `agent_name`, `agent_variant`, `model`, `reasoning_effort`)
+ * dead-ends in `remote_execution_disabled`.
+ */
+export function canEditProjectDefaultAgent(context: RemoteContext): boolean {
+ return isTrustedLocal(context);
+}
+
/**
* Memory administration is local-only: the admin log enumerates memcells for
* every principal, a settings save repoints the shared provider endpoints, and
diff --git a/vibe/cloud_management.py b/vibe/cloud_management.py
index 079c525f2..e76c2a0e8 100644
--- a/vibe/cloud_management.py
+++ b/vibe/cloud_management.py
@@ -267,6 +267,25 @@ def fail_handshake(state: str | None) -> str:
return handshake.next_path if handshake is not None else "/admin/organization/overview"
+def callback_owns_flow(state: str | None, browser_id: str | None) -> bool:
+ """Whether a callback proves it belongs to *browser_id*'s own handshake.
+
+ The OAuth callback is intentionally unauthenticated and CSRF-exempt, and the
+ management cookies are ``SameSite=Lax``, so any site can drive a top-level
+ navigation to it with attacker-chosen ``state`` / ``code`` / ``error`` and
+ have the victim's cookies attached. A failure on such a callback says
+ nothing about the browser's existing grant, so only a live handshake bound
+ to this exact browser authorizes tearing that grant down. This peeks
+ without consuming, so an unrelated callback also cannot pop a genuine
+ pending handshake out from under a real login.
+ """
+
+ if not state or not browser_id:
+ return False
+ handshake = handshake_for_handoff(state)
+ return handshake is not None and secrets.compare_digest(handshake.browser_id, browser_id)
+
+
def complete_authorization(
config: V2Config,
*,
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index 6c5d51930..8763f86bf 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -5869,13 +5869,21 @@ def cloud_management_auth_callback():
return _auth_rate_limit_response()
state = str(request.args.get("state") or "")
upstream_error = str(request.args.get("error") or "")
+ browser_id = request.cookies.get(cloud_management.BROWSER_COOKIE_NAME) or ""
+ # This route is unauthenticated and CSRF-exempt, so a cross-site top-level
+ # link reaches it with the `SameSite=Lax` management cookies attached. Only
+ # a callback that resolves to this browser's own live handshake may tear
+ # down its existing grant; an unrelated or forged one leaves the current
+ # session exactly as it was instead of forcing a logout.
+ owns_flow = cloud_management.callback_owns_flow(state, browser_id)
if upstream_error:
+ if not owns_flow:
+ return _cloud_management_redirect("/admin/organization/overview", upstream_error)
next_path = cloud_management.fail_handshake(state)
response = _cloud_management_redirect(next_path, upstream_error)
_delete_cloud_management_cookie(response, cloud_management.HANDLE_COOKIE_NAME)
_mark_cloud_management_manual(response)
return response
- browser_id = request.cookies.get(cloud_management.BROWSER_COOKIE_NAME) or ""
try:
grant, next_path = cloud_management.complete_authorization(
config,
@@ -5894,6 +5902,8 @@ def cloud_management_auth_callback():
"/admin/organization/overview",
code,
)
+ if not owns_flow:
+ return response
cloud_management.invalidate_grant(
request.cookies.get(cloud_management.HANDLE_COOKIE_NAME)
)