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(vault): delegate WebAuthn to the sandbox iframe via a self allowlist (#841)

Call Whiteb9f09bcaa82d
diff --git a/tests/test_vault_rest.py b/tests/test_vault_rest.py
index bb34b5e67..149675c12 100644
--- a/tests/test_vault_rest.py
+++ b/tests/test_vault_rest.py
@@ -182,21 +182,24 @@ def test_rest_agent_pubkey_route(monkeypatch):
assert response.get_json() == {"ok": True, "public_key": "pk", "fingerprint": "fp"}
-def test_rest_security_headers_delegate_webauthn_to_sandbox_only():
+def test_rest_security_headers_delegate_webauthn_to_self_and_sandbox():
client = app.test_client()
response = client.get("/api/csrf-token")
permissions = response.headers["Permissions-Policy"]
- assert 'publickey-credentials-get=("https://sandbox.avibe.bot")' in permissions
- assert 'publickey-credentials-create=("https://sandbox.avibe.bot")' in permissions
+ # Chrome only honors WebAuthn delegation to the cross-origin sandbox iframe when the
+ # allowlist includes `self` (an origin-only allowlist does not reach the child) — see
+ # VAULT_SANDBOX_PERMISSIONS_POLICY. Still narrowly scoped to self + the sandbox origin.
+ assert 'publickey-credentials-get=(self "https://sandbox.avibe.bot")' in permissions
+ assert 'publickey-credentials-create=(self "https://sandbox.avibe.bot")' in permissions
assert 'clipboard-write=(self "https://sandbox.avibe.bot")' in permissions
- assert "publickey-credentials-get=(self" not in permissions
- assert "publickey-credentials-create=(self" not in permissions
+ assert "publickey-credentials-get=*" not in permissions
+ assert "publickey-credentials-create=*" not in permissions
assert "frame-src 'self' https://sandbox.avibe.bot" in response.headers["Content-Security-Policy"]
-def test_spa_document_security_headers_delegate_webauthn_to_sandbox_only():
+def test_spa_document_security_headers_delegate_webauthn_to_self_and_sandbox():
client = app.test_client()
response = client.request("HEAD", "/vaults", base_url="http://127.0.0.1:5123")
@@ -204,11 +207,12 @@ def test_spa_document_security_headers_delegate_webauthn_to_sandbox_only():
assert response.status_code == 200
assert "text/html" in response.headers["content-type"]
permissions = response.headers["Permissions-Policy"]
- assert 'publickey-credentials-get=("https://sandbox.avibe.bot")' in permissions
- assert 'publickey-credentials-create=("https://sandbox.avibe.bot")' in permissions
+ # See the companion REST test: `self` is required for the cross-origin iframe delegation.
+ assert 'publickey-credentials-get=(self "https://sandbox.avibe.bot")' in permissions
+ assert 'publickey-credentials-create=(self "https://sandbox.avibe.bot")' in permissions
assert 'clipboard-write=(self "https://sandbox.avibe.bot")' in permissions
- assert "publickey-credentials-get=(self" not in permissions
- assert "publickey-credentials-create=(self" not in permissions
+ assert "publickey-credentials-get=*" not in permissions
+ assert "publickey-credentials-create=*" not in permissions
assert "frame-src 'self' https://sandbox.avibe.bot" in response.headers["Content-Security-Policy"]
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index 41c9dbeca..79531b0a6 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -125,9 +125,21 @@ TRACEBACK_EXCEPTION_PATTERN = re.compile(
CSRF_COOKIE_NAME = "vibe_csrf_token"
CSRF_HEADER_NAME = "X-Vibe-CSRF-Token"
VAULT_SANDBOX_ORIGIN = "https://sandbox.avibe.bot"
+# WebAuthn is delegated to the cross-origin sandbox iframe via Permissions-Policy. Chrome only
+# honors the delegation when the allowlist includes `self`: an origin-only allowlist
+# (`("origin")`, no self) does NOT reach the cross-origin child — verified empirically against
+# the sandbox iframe's DevTools "Allowed Features". So get + create both include self.
+#
+# Accepted trade-off (product decision): with `self`, the parent origin can also invoke the
+# get/create ceremonies, so a parent-app XSS could — via a user-approved passkey prompt — derive
+# the VMK. We intentionally do NOT defend against that. The sandbox's purpose is that the VMK /
+# PRF output / private keys / plaintext are only ever handled *inside* the sandbox origin, and the
+# agent (a backend process, never in the browser) can never reach them — those guarantees hold
+# regardless of self. Forcing a top-level popup on every unlock to close a
+# browser-XSS-social-engineering gap would wreck UX for a strictly secondary threat.
VAULT_SANDBOX_PERMISSIONS_POLICY = (
- f'publickey-credentials-get=("{VAULT_SANDBOX_ORIGIN}"), '
- f'publickey-credentials-create=("{VAULT_SANDBOX_ORIGIN}"), '
+ f'publickey-credentials-get=(self "{VAULT_SANDBOX_ORIGIN}"), '
+ f'publickey-credentials-create=(self "{VAULT_SANDBOX_ORIGIN}"), '
f'clipboard-write=(self "{VAULT_SANDBOX_ORIGIN}")'
)
REMOTE_OAUTH_COOKIE_NAME = "__Host-vibe_remote_oauth"