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): confine web push registration and show annotation media

Max9f2a8c7ba582
diff --git a/tests/test_instance_authorization.py b/tests/test_instance_authorization.py
index bcd3d510c..1fe92e43b 100644
--- a/tests/test_instance_authorization.py
+++ b/tests/test_instance_authorization.py
@@ -206,7 +206,17 @@ def test_remote_http_policy_defaults_local_machine_and_unknown_routes_to_local_o
("GET", "/api/dock", REMOTE_HTTP_ALLOWED),
("POST", "/api/dock/pins", REMOTE_HTTP_LOCAL_ONLY),
("PUT", "/api/dock/order", REMOTE_HTTP_LOCAL_ONLY),
- ("POST", "/api/web-push/subscriptions", REMOTE_HTTP_ALLOWED),
+ # A push endpoint is caller-supplied and `send_web_push()` fetches it
+ # from this host, so registering or testing one from across the tunnel
+ # would let a remote caller aim an outbound request at loopback, a
+ # private LAN host or a rebinding name. Status reads stay remote: they
+ # report the caller's own subscription and reach no endpoint.
+ ("GET", "/api/web-push/status", REMOTE_HTTP_ALLOWED),
+ ("POST", "/api/web-push/status", REMOTE_HTTP_ALLOWED),
+ ("GET", "/api/web-push/vapid-public-key", REMOTE_HTTP_ALLOWED),
+ ("POST", "/api/web-push/subscriptions", REMOTE_HTTP_LOCAL_ONLY),
+ ("DELETE", "/api/web-push/subscriptions", REMOTE_HTTP_LOCAL_ONLY),
+ ("POST", "/api/web-push/test", REMOTE_HTTP_LOCAL_ONLY),
("GET", "/api/harness/runs/run-1", REMOTE_HTTP_LOCAL_ONLY),
("GET", "/api/users", REMOTE_HTTP_LOCAL_ONLY),
("HEAD", "/api/users", REMOTE_HTTP_LOCAL_ONLY),
@@ -342,6 +352,23 @@ def test_remote_http_policy_keeps_approved_management_and_read_surfaces(
),
("dockAndWorkbenchPrefs", "PUT", "/api/dock/order", REMOTE_HTTP_LOCAL_ONLY),
("dockAndWorkbenchPrefs", "PUT", "/api/workbench/prefs", REMOTE_HTTP_LOCAL_ONLY),
+ # canRegisterWebPush: status reads stay remote, but registering or
+ # testing an endpoint this host will call does not.
+ ("canRegisterWebPush", "GET", "/api/web-push/status", REMOTE_HTTP_ALLOWED),
+ ("canRegisterWebPush", "POST", "/api/web-push/status", REMOTE_HTTP_ALLOWED),
+ (
+ "canRegisterWebPush",
+ "POST",
+ "/api/web-push/subscriptions",
+ REMOTE_HTTP_LOCAL_ONLY,
+ ),
+ (
+ "canRegisterWebPush",
+ "DELETE",
+ "/api/web-push/subscriptions",
+ REMOTE_HTTP_LOCAL_ONLY,
+ ),
+ ("canRegisterWebPush", "POST", "/api/web-push/test", REMOTE_HTTP_LOCAL_ONLY),
],
)
def test_local_only_workbench_gates_match_the_remote_http_policy(
diff --git a/tests/test_resource_acl_show_pages.py b/tests/test_resource_acl_show_pages.py
index a5799f203..f99ce2ee8 100644
--- a/tests/test_resource_acl_show_pages.py
+++ b/tests/test_resource_acl_show_pages.py
@@ -6,7 +6,7 @@ from sqlalchemy import select
from config import paths
from core.dock_store import BUILTIN_DOCK_IDS, DockError
from core.show_pages import ShowPageError, ShowPageStore, public_url
-from storage import projects_service, resource_access_service
+from storage import media_service, projects_service, resource_access_service
from storage import workbench_sessions_service as sessions_service
from storage.db import create_sqlite_engine
from storage.importer import ensure_sqlite_state
@@ -402,3 +402,106 @@ def test_remote_member_cannot_archive_session_with_another_owners_page(monkeypat
).scalar_one() == "private"
finally:
engine.dispose()
+
+
+def test_remote_show_annotation_media_follows_the_page_acl(monkeypatch, tmp_path) -> None:
+ """A screenshot token does not outlive access to the page it was drawn on.
+
+ `/api/media/<token>` authorizes Project/session role and short-circuits for
+ the Instance owner, so without a page check a caller who once saw a private
+ Show Page keeps its annotation screenshot readable after the page policy
+ stops naming them - and a remote Instance owner reads one they were never
+ allowed to open. The caller below is exactly that: Instance owner, but not
+ the subject the private page's policy names.
+ """
+
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ config = _save_config(tmp_path)
+ project_dir = tmp_path / "project"
+ project_dir.mkdir()
+ ensure_sqlite_state()
+ engine = create_sqlite_engine(paths.get_sqlite_state_path())
+ try:
+ with engine.begin() as connection:
+ project = projects_service.create_project(connection, str(project_dir))
+ sessions = {
+ access_level: sessions_service.create_session(
+ connection,
+ scope_id=project["scope_id"],
+ agent_backend="claude",
+ )["id"]
+ for access_level in ("private", "public")
+ }
+
+ store = ShowPageStore()
+ try:
+ for access_level, session_id in sessions.items():
+ store.ensure(session_id)
+ with store.engine.begin() as connection:
+ resource_access_service.ensure_resource_policy(
+ connection,
+ resource_kind="show_page",
+ resource_id=session_id,
+ organization_id="org-1",
+ owner_user_id="owner-1",
+ access_level=access_level,
+ )
+ finally:
+ store.close()
+
+ def _screenshot(name: str) -> str:
+ path = tmp_path / f"{name}.png"
+ path.write_bytes(b"\x89PNG\r\n\x1a\n" + name.encode("ascii"))
+ return str(path.resolve())
+
+ with engine.begin() as connection:
+ tokens = {
+ f"{source}:{access_level}": media_service.register(
+ connection,
+ scope_id=project["scope_id"],
+ session_id=session_id,
+ kind="image",
+ source=source,
+ local_path=_screenshot(f"{source}-{access_level}"),
+ )
+ for source in ("show_annotation", "agent_reply")
+ for access_level, session_id in sessions.items()
+ }
+ orphan_token = media_service.register(
+ connection,
+ scope_id=None,
+ session_id=None,
+ kind="image",
+ source="show_annotation",
+ local_path=_screenshot("orphan"),
+ )
+
+ client = app.test_client()
+ client.set_cookie(
+ remote_access.SESSION_COOKIE_NAME,
+ _organization_cookie(
+ config,
+ subject="member-1",
+ groups=["group-engineering"],
+ instance_role="owner",
+ ),
+ domain="alex.avibe.bot",
+ )
+
+ def _media(token: str):
+ return client.get(
+ f"/api/media/{token}",
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ )
+
+ # The page ACL decides, not the Instance-owner shortcut.
+ assert _media(tokens["show_annotation:private"]).status_code == 404
+ assert _media(tokens["show_annotation:public"]).status_code == 200
+ # An annotation with no page to check against cannot be authorized.
+ assert _media(orphan_token).status_code == 404
+ # Only Show annotations gained the page check; other media keeps the
+ # Project/session authorization it already had as its only gate.
+ assert _media(tokens["agent_reply:private"]).status_code == 200
+ finally:
+ engine.dispose()
diff --git a/tests/test_ui_remote_access_auth.py b/tests/test_ui_remote_access_auth.py
index 69ffdc59a..f8c26c6a6 100644
--- a/tests/test_ui_remote_access_auth.py
+++ b/tests/test_ui_remote_access_auth.py
@@ -2303,6 +2303,79 @@ def test_remote_owner_instruction_reads_stay_local_while_queue_reads_do_not(
assert ui_server._is_remote_local_execution_request("POST", "/api/skills/preview")
+def test_remote_owner_cannot_register_or_test_a_web_push_endpoint(
+ monkeypatch,
+ tmp_path,
+):
+ """Push registration is the SSRF surface; the status read is not.
+
+ A subscription endpoint is caller-supplied and ``send_web_push()`` fetches
+ it from this host, and nothing between the payload and that request keeps
+ it pointed at a real push service - an HTTPS URL naming loopback, a private
+ LAN host or a rebinding name is accepted. A remote caller could therefore
+ register one and use ``/test`` to have the Avibe host issue the request
+ from inside its own network, so both mutations stop at the boundary while
+ the principal-scoped status read still crosses it.
+ """
+
+ from storage.importer import ensure_sqlite_state
+
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ config = _save_config(tmp_path)
+ ensure_sqlite_state()
+ sent: list[dict] = []
+ monkeypatch.setattr(
+ "core.web_push.send_web_push",
+ lambda **kwargs: sent.append(kwargs),
+ )
+ client = app.test_client()
+ client.set_cookie(
+ remote_access.SESSION_COOKIE_NAME,
+ remote_session_cookie(config, "[email protected]", "user-owner"),
+ domain="alex.avibe.bot",
+ )
+ headers = csrf_headers(client, "https://alex.avibe.bot")
+
+ def _post(path: str, payload: dict):
+ return client.post(
+ path,
+ json=payload,
+ headers=headers,
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ )
+
+ internal_endpoint = "https://127.0.0.1:8443/push"
+ subscribe = _post(
+ "/api/web-push/subscriptions",
+ {
+ "endpoint": internal_endpoint,
+ "keys": {"p256dh": "public-key", "auth": "auth-secret"},
+ },
+ )
+ test_send = _post("/api/web-push/test", {"endpoint": internal_endpoint})
+ unsubscribe = client.delete(
+ "/api/web-push/subscriptions",
+ json={"endpoint": internal_endpoint},
+ headers=headers,
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ )
+ status = client.get(
+ "/api/web-push/status",
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ )
+
+ for response in (subscribe, test_send, unsubscribe):
+ assert response.status_code == 403
+ assert response.get_json()["code"] == "remote_execution_disabled"
+ assert sent == []
+ assert status.status_code == 200
+ # No endpoint was stored, so the status read reports nothing to send to.
+ assert status.get_json()["subscription_count"] == 0
+
+
def test_remote_show_dispatch_is_rejected_before_event_reservation(
monkeypatch,
tmp_path,
diff --git a/ui/src/components/workbench/WebPushControl.tsx b/ui/src/components/workbench/WebPushControl.tsx
index 518f1fe0a..49ab695ac 100644
--- a/ui/src/components/workbench/WebPushControl.tsx
+++ b/ui/src/components/workbench/WebPushControl.tsx
@@ -3,7 +3,9 @@ import { useTranslation } from 'react-i18next';
import { Bell, BellOff, Loader2, Smartphone } from 'lucide-react';
import { useApi } from '@/context/ApiContext';
+import { useInstanceAuthorization } from '@/context/InstanceAuthorizationContext';
import { useToast } from '@/context/ToastContext';
+import { canRegisterWebPush } from '@/lib/remoteAuth';
import { Button } from '../ui/button';
import { Badge } from '../ui/badge';
import {
@@ -22,11 +24,15 @@ type Status = 'checking' | 'unsupported' | 'needs_install' | 'disabled' | 'enabl
export const WebPushControl: React.FC = () => {
const { t } = useTranslation();
const api = useApi();
+ const { remote } = useInstanceAuthorization();
const { showToast } = useToast();
const [status, setStatus] = useState<Status>('checking');
const [busy, setBusy] = useState(false);
const [testing, setTesting] = useState(false);
const [support, setSupport] = useState<WebPushSupportState | null>(null);
+ // Subscribe / unsubscribe / test are local-only, so a remote instance can read
+ // its push status but cannot register an endpoint for this host to call.
+ const canRegister = canRegisterWebPush({ remote });
const refresh = async () => {
const nextSupport = getWebPushSupportState();
@@ -55,9 +61,10 @@ export const WebPushControl: React.FC = () => {
};
useEffect(() => {
+ if (!canRegister) return;
void refresh();
// eslint-disable-next-line react-hooks/exhaustive-deps
- }, []);
+ }, [canRegister]);
const onEnable = async () => {
setBusy(true);
@@ -111,6 +118,15 @@ export const WebPushControl: React.FC = () => {
}
};
+ if (!canRegister) {
+ return (
+ <Badge variant="secondary" className="h-8 rounded-lg px-3">
+ <BellOff className="size-3" />
+ {t('workbench.inbox.notifications.localOnly')}
+ </Badge>
+ );
+ }
+
if (status === 'checking') {
return (
<Badge variant="secondary" className="h-8 rounded-lg px-3">
diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json
index c2adcb6a1..76a3e03be 100644
--- a/ui/src/i18n/en.json
+++ b/ui/src/i18n/en.json
@@ -1722,6 +1722,7 @@
"notifications": {
"checking": "Checking notifications",
"unsupported": "Notifications unavailable",
+ "localOnly": "Enable notifications on this device locally",
"installFirst": "Add to Home Screen first",
"enable": "Enable notifications",
"enabled": "Notifications on",
diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.json
index 7a19e02a4..56f7a6a9e 100644
--- a/ui/src/i18n/zh.json
+++ b/ui/src/i18n/zh.json
@@ -1722,6 +1722,7 @@
"notifications": {
"checking": "正在检查通知",
"unsupported": "当前不支持通知",
+ "localOnly": "请在本机开启通知",
"installFirst": "先添加到主屏幕",
"enable": "开启通知",
"enabled": "通知已开启",
diff --git a/ui/src/lib/remoteAuth.test.ts b/ui/src/lib/remoteAuth.test.ts
index 9752c7946..5ec3b7788 100644
--- a/ui/src/lib/remoteAuth.test.ts
+++ b/ui/src/lib/remoteAuth.test.ts
@@ -14,6 +14,7 @@ import {
canEditProjectInstructions,
canManageSkills,
canManageVaultSecrets,
+ canRegisterWebPush,
canUseHarness,
checkRemoteAuthForPath,
deferRemoteAuthRedirect,
@@ -40,6 +41,7 @@ describe('local-only workbench controls', () => {
const predicates = {
canManageSkills,
canManageVaultSecrets,
+ canRegisterWebPush,
canUseHarness,
canArchiveProjects,
canEditProjectInstructions,
diff --git a/ui/src/lib/remoteAuth.ts b/ui/src/lib/remoteAuth.ts
index 16745bbce..e5f85548b 100644
--- a/ui/src/lib/remoteAuth.ts
+++ b/ui/src/lib/remoteAuth.ts
@@ -117,6 +117,17 @@ export function canAdministerMemory(context: RemoteContext): boolean {
return isTrustedLocal(context);
}
+/**
+ * Registering and testing a Web Push subscription is local-only: the endpoint is
+ * caller-supplied and this host later fetches it, so a remote subscription would
+ * be an outbound request to an address the caller picked. Reading push status
+ * stays remote-permitted, which is why this gates the enable / disable / test
+ * controls rather than the surface that shows them.
+ */
+export function canRegisterWebPush(context: RemoteContext): boolean {
+ return isTrustedLocal(context);
+}
+
export async function checkRemoteAuthForPath<Session extends RemoteSession>(
path: string,
diff --git a/vibe/authorization.py b/vibe/authorization.py
index b6c1ff2a5..c5df856df 100644
--- a/vibe/authorization.py
+++ b/vibe/authorization.py
@@ -416,15 +416,25 @@ _REMOTE_OWNER_ALLOWED_HTTP_RULES = tuple(
# remote write would reorder and re-pin everyone else's Dock and flip
# another principal's banner preference, so the mutations stay local.
(frozenset({"GET", "HEAD"}), r"^/api/dock$"),
+ # Reading push status stays remote, and so does the `POST` form of it:
+ # it reports this principal's own subscription count and can only
+ # re-attach a device id to an endpoint that is already stored and
+ # enabled for that same principal, so it can neither introduce an
+ # endpoint nor send to one.
+ #
+ # Registering and testing a subscription are different: the endpoint is
+ # caller-supplied data that `send_web_push()` later fetches from the
+ # Avibe host, and nothing between the payload and the request restricts
+ # it to a real push service. A remote caller could register an HTTPS
+ # endpoint aimed at loopback, a private LAN host or a rebinding name and
+ # then have this host issue the request from inside the network, so the
+ # write and the test stay local until the endpoint is checked against
+ # its resolved addresses.
(
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({"POST"}), r"^/api/web-push/status$"),
(
frozenset({"PUT"}),
r"^/api/resource-policies/[^/]+/[^/]+$",
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index e1e9cfa62..adfce243c 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -9519,10 +9519,37 @@ def media_get(token: str):
return _registered_media_response(token)
+def _media_row_show_page_access_allowed(context: Any, row: dict[str, Any]) -> bool:
+ """Whether *context* may still read a Show annotation's screenshot bytes.
+
+ A `show_annotation` screenshot is part of the page it was drawn on, so it
+ inherits that page's resource ACL rather than only the Project/session role
+ the rest of the media proxy checks. Without this the media token outlives
+ the access that produced it: a caller who saw a private page once keeps its
+ screenshot readable after the page policy stops naming them, and being the
+ Instance owner does not override the page ACL either -- a direct read of a
+ page owned by another subject is denied, so its screenshot must be too.
+
+ Media from any other source is unaffected and keeps the Project/session
+ authorization below as its only gate.
+ """
+
+ if (row.get("source") or "") != "show_annotation":
+ return True
+ session_id = row.get("session_id")
+ if not isinstance(session_id, str) or not session_id:
+ # Fail closed: an annotation screenshot with no page to check against
+ # cannot be authorized, and serving it would be the exact bypass above.
+ return False
+ return _show_page_resource_access_allowed(context, session_id)
+
+
def _request_can_read_media_row(conn, token: str, row: dict[str, Any]) -> bool:
from storage import media_service, project_access_service
context = getattr(g, "authorization_context", None)
+ if not _media_row_show_page_access_allowed(context, row):
+ return False
if context is None or context.is_instance_owner:
return True
session_ids = media_service.referenced_session_ids(conn, token)