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.

merge(org): sync integration auth hardening

Max264418dd8bec
diff --cc tests/scenarios/auth_setup/test_auth_setup_scenarios.py
index 8261509a0,c27fb0b42..784411c99
--- a/tests/scenarios/auth_setup/test_auth_setup_scenarios.py
+++ b/tests/scenarios/auth_setup/test_auth_setup_scenarios.py
@@@ -42,49 -47,10 +48,51 @@@ from vibe.claude_config import
materialize_claude_subprocess_env,
read_claude_settings_env,
)
+ from vibe import remote_access, ui_server
+ from vibe.ui_server import app
+class ShowPageEmailAccessScenarioTests(unittest.TestCase):
+ def setUp(self):
+ self.harness = ShowPageEmailAccessScenarioHarness()
+ self.addCleanup(self.harness.close)
+
+ def test_exact_email_login_is_confined_to_its_signed_show_page(self):
+ """Scenario: AUTH-SETUP-401"""
+ handshake = self.harness.begin_login("session-one")
+ self.assertEqual(handshake["show_page_id"], "session-one")
+
+ callback = self.harness.complete_login(handshake)
+ self.assertEqual(callback.status_code, 302)
+ self.assertEqual(callback.headers["Location"], handshake["next_path"])
+
+ exact = self.harness.get(handshake["next_path"])
+ other = self.harness.get("/show/session-two/__show/me")
+ api = self.harness.get("/api/show-pages")
+ self.assertEqual(exact.status_code, 200)
+ self.assertEqual(exact.get_json(), {"authenticated": False, "canAnnotate": False})
+ self.assertEqual(other.status_code, 403)
+ self.assertEqual(other.get_json()["error"], "show_page_access_forbidden")
+ self.assertEqual(api.status_code, 403)
+
+ self.harness.seed_broader_session()
+ existing_session_handshake = self.harness.begin_login("session-one")
+ existing_session_callback = self.harness.complete_login(
+ existing_session_handshake,
+ instance_role="editor",
+ access_source="email",
+ )
+ self.assertEqual(existing_session_callback.status_code, 302)
+ self.assertEqual(
+ existing_session_callback.headers["Location"],
+ existing_session_handshake["next_path"],
+ )
+ self.assertEqual(
+ self.harness.get(existing_session_handshake["next_path"]).status_code,
+ 200,
+ )
+
+
class _FakeNextTurnRuntime:
def __init__(self):
self.refreshed = False
diff --cc tests/test_instance_authorization.py
index b0d81397f,1dc16fa1d..2b63f37f7
--- a/tests/test_instance_authorization.py
+++ b/tests/test_instance_authorization.py
@@@ -179,6 -129,21 +180,20 @@@ def test_http_policy_defaults_unknown_a
@pytest.mark.parametrize(
("method", "path"),
[
- ("POST", "/api/show-pages/ses-1/visibility"),
+ ("GET", "/api/backend/codex/runtime"),
+ ("GET", "/api/backend/claude/auth"),
+ ("GET", "/api/backend/codex/auth"),
+ ("GET", "/api/opencode/permission-status"),
+ ("GET", "/api/harness/tasks"),
+ ("GET", "/api/harness/watches"),
+ ("GET", "/api/global-prompts"),
+ ("GET", "/api/harness/runs"),
+ ("GET", "/api/harness/runs/run-1"),
+ ("GET", "/api/harness/bootstrap"),
+ ("GET", "/api/vault/pubkey"),
+ ("GET", "/api/vault/agent/pubkey"),
+ ("GET", "/api/vault/sandbox/root-metadata"),
+ ("GET", "/api/vault/vmk"),
("GET", "/api/doctor"),
("POST", "/api/doctor"),
("POST", "/api/logs"),
@@@ -231,8 -197,27 +248,28 @@@ def test_remote_http_policy_defaults_lo
("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),
- ("GET", "/api/users", REMOTE_HTTP_ALLOWED),
+ ("GET", "/api/harness/runs/run-1", REMOTE_HTTP_LOCAL_ONLY),
+ ("GET", "/api/users", REMOTE_HTTP_LOCAL_ONLY),
+ ("HEAD", "/api/users", REMOTE_HTTP_LOCAL_ONLY),
+ ("GET", "/api/skills/check", REMOTE_HTTP_LOCAL_ONLY),
+ ("HEAD", "/api/skills/find", REMOTE_HTTP_LOCAL_ONLY),
+ ("POST", "/api/vault/requests/access", REMOTE_HTTP_LOCAL_ONLY),
+ ("POST", "/api/vault/requests/sign", REMOTE_HTTP_LOCAL_ONLY),
- ("POST", "/api/show-pages/ses-1/rotate-share", REMOTE_HTTP_LOCAL_ONLY),
- ("POST", "/api/show-pages/ses-1/share-id", REMOTE_HTTP_LOCAL_ONLY),
++ ("POST", "/api/show-pages/ses-1/visibility", REMOTE_HTTP_ALLOWED),
++ ("POST", "/api/show-pages/ses-1/rotate-share", REMOTE_HTTP_ALLOWED),
++ ("POST", "/api/show-pages/ses-1/share-id", REMOTE_HTTP_ALLOWED),
+ ("GET", "/api/sessions/ses-1/draft", REMOTE_HTTP_LOCAL_ONLY),
+ ("PUT", "/api/sessions/ses-1/draft", REMOTE_HTTP_LOCAL_ONLY),
+ ("POST", "/api/sessions/ses-1/mark-read", REMOTE_HTTP_LOCAL_ONLY),
+ ("GET", "/status", REMOTE_HTTP_LOCAL_ONLY),
+ ("HEAD", "/status", REMOTE_HTTP_LOCAL_ONLY),
+ ("POST", "/api/show-pages/ses-1/ensure", REMOTE_HTTP_ALLOWED),
+ ("GET", "/api/memory/settings", REMOTE_HTTP_ALLOWED),
+ ("HEAD", "/api/memory/log/entry", REMOTE_HTTP_ALLOWED),
+ ("PATCH", "/api/memory/settings", REMOTE_HTTP_ALLOWED),
+ ("POST", "/api/memory/search", REMOTE_HTTP_ALLOWED),
+ ("POST", "/api/memory/runtime/restart", REMOTE_HTTP_ALLOWED),
+ ("POST", "/api/memory/clear", REMOTE_HTTP_ALLOWED),
("GET", "/show/ses-1/", REMOTE_HTTP_ALLOWED),
("POST", "/show/ses-1/__show/events", REMOTE_HTTP_ALLOWED),
("POST", "/api/config", REMOTE_HTTP_PAYLOAD_FILTERED),
diff --cc tests/test_resource_acl_show_pages.py
index b3f1e9ab7,49a395e3a..6dcbb48c2
--- a/tests/test_resource_acl_show_pages.py
+++ b/tests/test_resource_acl_show_pages.py
@@@ -222,18 -152,10 +222,19 @@@ def test_remote_show_page_list_and_dire
assert catalog.status_code == 200
assert {item["session_id"] for item in catalog.get_json()["pages"]} == {"ses-public", "ses-scope"}
+ assert all("path" not in item for item in catalog.get_json()["pages"])
assert mutation.status_code == 403
- assert mutation.get_json()["code"] == "remote_execution_disabled"
- assert page.status_code == 403
+ assert mutation.get_json()["code"] == "resource_access_forbidden"
+ assert page.status_code == 302
+ assert "show_page_id=ses-private" in page.headers["Location"]
+
+ reauth_result = client.get(
+ "/show/ses-private/?__vibe_show_page_reauth=1",
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ follow_redirects=False,
+ )
+ assert reauth_result.status_code == 403
def test_remote_show_page_creation_defaults_private_and_org_public_does_not_share(monkeypatch, tmp_path) -> None:
diff --cc tests/test_ui_remote_access_auth.py
index db86513c6,13f1c7c5e..f2e2668a2
--- a/tests/test_ui_remote_access_auth.py
+++ b/tests/test_ui_remote_access_auth.py
@@@ -139,181 -166,44 +166,240 @@@ def test_remote_login_endpoint_redirect
assert state_payload["retry"] is False
+def test_private_show_page_login_freezes_target_in_authorize_and_handshake(
+ monkeypatch, tmp_path
+):
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ config = _save_config(tmp_path)
++ client = app.test_client()
+
- response = app.test_client().get(
- "/show/session-one/asset.js",
++ navigation = client.get(
++ "/show/session-one/",
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
++ headers={"Accept": "text/html"},
+ follow_redirects=False,
+ )
+
- assert response.status_code == 302
- authorize_params = httpx.URL(response.headers["Location"]).params
++ assert navigation.status_code == 302
++ assert navigation.headers["Location"] == "/auth/login?next=%2Fshow%2Fsession-one%2F"
++
++ login = client.get(
++ navigation.headers["Location"],
++ base_url="https://alex.avibe.bot",
++ environ_base=_remote_peer(),
++ follow_redirects=False,
++ )
++
++ assert login.status_code == 302
++ authorize_params = httpx.URL(login.headers["Location"]).params
+ assert authorize_params["show_page_id"] == "session-one"
+ state_payload = ui_server._read_oauth_state(
+ config.remote_access.vibe_cloud.session_secret,
+ authorize_params["state"],
+ )
+ assert state_payload is not None
+ stored = remote_access._oauth_handshakes[state_payload["r"]]
+ assert stored["show_page_id"] == "session-one"
+
++ asset = client.get(
++ "/show/session-one/asset.js",
++ base_url="https://alex.avibe.bot",
++ environ_base=_remote_peer(),
++ follow_redirects=False,
++ )
++ assert asset.status_code == 401
++ assert asset.get_json()["error"] == "remote_access_login_required"
++
+
+def test_existing_broader_session_reauthorization_stops_when_grant_is_missing(
+ monkeypatch,
+ tmp_path,
+):
+ from core.show_pages import ShowPageStore
+
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ config = _save_config(tmp_path)
+ store = ShowPageStore()
+ try:
+ store.ensure("session-one")
+ finally:
+ store.close()
+ client = app.test_client()
+ client.set_cookie(
+ remote_access.SESSION_COOKIE_NAME,
+ remote_session_cookie(
+ config,
+ "guest-1",
+ role="editor",
+ access_source="email",
+ ),
+ domain="alex.avibe.bot",
+ )
+
+ start = client.get(
+ "/show/session-one/__show/me",
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ follow_redirects=False,
+ )
+ authorize_params = httpx.URL(start.headers["Location"]).params
+ state = authorize_params["state"]
+ state_payload = ui_server._read_oauth_state(
+ config.remote_access.vibe_cloud.session_secret,
+ state,
+ )
+ assert state_payload is not None
+ nonce = remote_access._oauth_handshakes[state_payload["r"]]["nonce"]
+ monkeypatch.setattr(
+ remote_access,
+ "exchange_oauth_code",
+ lambda *args, **kwargs: {
+ "claims": {
+ "email": "[email protected]",
+ "sub": "guest-1",
+ "nonce": nonce,
+ },
+ "session_claims": {
+ "vibe_instance_id": "inst_123",
+ "vibe_instance_role": "editor",
+ "vibe_instance_access_source": "email",
+ },
+ },
+ )
+
+ callback = client.get(
+ f"/auth/callback?code=test-code&state={state}",
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ follow_redirects=False,
+ )
+ assert callback.status_code == 302
+ assert ui_server.REMOTE_SHOW_PAGE_REAUTH_PARAM in callback.headers["Location"]
+
+ denied = client.get(
+ callback.headers["Location"],
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ follow_redirects=False,
+ )
+ assert denied.status_code == 404
+ assert "Location" not in denied.headers
+
+
+def test_show_page_email_session_is_confined_to_its_signed_route(monkeypatch, tmp_path):
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ config = _save_config(tmp_path)
+ cookie = remote_access.make_session_cookie(
+ config,
+ "guest-1",
+ session_claims={
+ "vibe_instance_id": "inst_123",
+ "vibe_instance_role": "viewer",
+ "vibe_instance_access_source": "show_page_email",
+ "vibe_show_page_id": "session-one",
+ },
+ )
+ client = app.test_client()
+ client.set_cookie(
+ remote_access.SESSION_COOKIE_NAME,
+ cookie,
+ domain="alex.avibe.bot",
+ )
+
+ exact = client.get(
+ "/show/session-one/missing.js",
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ )
+ other = client.get(
+ "/show/session-two/",
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ )
+ workbench = client.get(
+ "/api/show-pages",
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ )
+ session_api = client.get(
+ "/api/session",
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ )
+
+ assert exact.status_code != 403
+ assert other.status_code == 403
+ assert other.get_json()["error"] == "show_page_access_forbidden"
+ assert workbench.status_code == 403
+ assert session_api.status_code == 403
+
+
+def test_show_page_oidc_claim_shape_fails_closed(monkeypatch, tmp_path):
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ config = _save_config(tmp_path)
+ base = {
+ "vibe_instance_id": "inst_123",
+ "vibe_instance_role": "viewer",
+ "vibe_instance_access_source": "show_page_email",
+ }
+
+ with pytest.raises(remote_access.OAuthCodeExchangeError, match="invalid_show_page_id"):
+ remote_access.session_claims_from_oidc(config, base)
+ broader = remote_access.session_claims_from_oidc(
+ config,
+ {
+ **base,
+ "vibe_instance_role": "editor",
+ "vibe_instance_access_source": "email",
+ "vibe_show_page_id": "session-one",
+ },
+ )
+ assert broader["vibe_instance_access_source"] == "email"
+ assert broader["vibe_instance_role"] == "editor"
+ assert broader["vibe_show_page_id"] == "session-one"
+
+
+ def test_remote_login_endpoint_sanitizes_external_next_target(monkeypatch, tmp_path):
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ config = _save_config(tmp_path)
+
+ response = app.test_client().get(
+ "/auth/login?next=https://evil.example/path",
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ follow_redirects=False,
+ )
+
+ state = httpx.URL(response.headers["Location"]).params["state"]
+ state_payload = ui_server._read_oauth_state(config.remote_access.vibe_cloud.session_secret, state)
+ assert state_payload is not None
+ assert state_payload["next"] == "/"
+
+
+ def test_remote_login_endpoint_returns_authenticated_session_to_target(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-1"),
+ domain="alex.avibe.bot",
+ )
+
+ response = client.get(
+ "/auth/login?next=/chat/session-1",
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ follow_redirects=False,
+ )
+
+ assert response.status_code == 302
+ assert response.headers["Location"] == "/chat/session-1"
+
+
def test_custom_hostname_uses_remote_auth_until_heartbeat_removes_it(monkeypatch, tmp_path):
monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
config = _save_config(tmp_path)
@@@ -1754,16 -1706,60 +1902,70 @@@ def test_remote_show_page_icon_upload_i
@pytest.mark.parametrize(
- "path",
- ("path", "json_body", "api_method"),
++ ("path", "json_body", "api_method", "expected_args"),
[
- "/api/models/runtime/status",
- "/api/models/agents",
- "/api/backend/codex/runtime",
- "/api/backend/codex/auth",
- ("/api/show-pages/ses-local/rotate-share", {}, "rotate_show_page_share"),
++ (
++ "/api/show-pages/ses-local/rotate-share",
++ {},
++ "rotate_show_page_share",
++ ("ses-local",),
++ ),
+ (
+ "/api/show-pages/ses-local/share-id",
+ {"share_id": "remote-link"},
+ "set_show_page_share_id",
++ ("ses-local", "remote-link"),
+ ),
],
)
- def test_remote_model_and_backend_reads_remain_available(path):
- assert not ui_server._is_remote_local_execution_request("GET", path)
-def test_remote_show_page_public_link_mutations_are_blocked_before_store_access(
++def test_remote_show_page_public_link_mutations_reach_resource_authorization(
+ monkeypatch,
+ tmp_path,
+ path,
+ json_body,
+ api_method,
++ expected_args,
+ ):
+ 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_show_page_write(*args, **kwargs):
- raise AssertionError("remote public-link mutation reached the Show Page store")
++ calls = []
+
- monkeypatch.setattr(api, api_method, unexpected_show_page_write)
++ def authorized_show_page_write(*args, **kwargs):
++ calls.append((args, kwargs))
++ return {"session_id": "ses-local", "share_id": "remote-link"}
++
++ monkeypatch.setattr(api, api_method, authorized_show_page_write)
+ response = client.post(
+ path,
+ json=json_body,
+ headers=csrf_headers(client, "https://alex.avibe.bot"),
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ )
+
- assert response.status_code == 403
- assert response.get_json()["code"] == "remote_execution_disabled"
++ assert response.status_code == 200
++ assert calls == [(expected_args, {})]
+
+
+ @pytest.mark.parametrize(
+ ("path", "local_only"),
+ [
+ ("/api/models/runtime/status", False),
+ ("/api/models/agents", False),
+ ("/api/models/sources", True),
+ ("/api/backend/codex/runtime", True),
+ ("/api/backend/codex/auth", True),
+ ],
+ )
+ def test_remote_model_and_backend_reads_follow_execution_safety_policy(path, local_only):
+ assert ui_server._is_remote_local_execution_request("GET", path) is local_only
@pytest.mark.parametrize(
diff --cc tests/test_ui_show_pages.py
index 34443e2d9,b43eb20bc..dc753d633
--- a/tests/test_ui_show_pages.py
+++ b/tests/test_ui_show_pages.py
@@@ -90,8 -90,8 +90,11 @@@ class _FakeShowRuntimeManager
@pytest.fixture(autouse=True)
--def _show_runtime_node_version(monkeypatch):
++def _hermetic_show_runtime(monkeypatch):
monkeypatch.setattr("core.show_runtime._node_version", lambda node: (22, 16, 0))
++ set_show_runtime_manager_for_tests(_FakeShowRuntimeManager(fail=True))
++ yield
++ set_show_runtime_manager_for_tests(None)
def test_set_show_runtime_manager_stops_previous_manager():
diff --cc ui/src/components/ShowPagesPage.tsx
index 22834ff56,da8fd6d29..938c56358
--- a/ui/src/components/ShowPagesPage.tsx
+++ b/ui/src/components/ShowPagesPage.tsx
@@@ -23,8 -23,8 +23,9 @@@ import clsx from 'clsx'
import { useDock } from '../context/DockContext';
import { useWindowManager } from '../context/WindowManagerContext';
import { copyTextToClipboard } from '../lib/utils';
+ import { internalPwaLinkTarget, openLinkInNewContext } from '../lib/pwaNavigation';
-import { copyHref, displayLink, type ShowPageLinkInfo } from '../lib/showPageLinks';
+import { copyHref, displayLink } from '../lib/showPageLinks';
+import type { ShowPageVisibilityResult } from '../lib/showPageAccess';
import { type ShowPage, type ShowPagesController, type Visibility } from './useShowPages';
import { appTabHref, isAppleContextClick, tabModifierLabel, type LaunchModifiers } from '../apps/appLaunch';
import { filterShowPages, type ShowPageFilter } from '../apps/appLibrary';
diff --cc ui/src/components/workbench/ChatPage.tsx
index 9a054c333,f85657ba1..dd9215550
--- a/ui/src/components/workbench/ChatPage.tsx
+++ b/ui/src/components/workbench/ChatPage.tsx
@@@ -21,14 -21,15 +21,21 @@@ import { isTerminalAgentMessage, isTran
import { chatRowKind, drawsEmptyBodyPlaceholder, isAgentAuthored } from '../../lib/chatRowKind';
import { useIosKeyboardInset } from '../../lib/useIosKeyboardInset';
import { isProxyMediaUrl } from '../../lib/mediaProxy';
- import { isVaultApprovalRequest, placeVaultProvisionRequests } from '../../lib/vaultRequestPlacement';
+ import {
+ isVaultApprovalRequest,
+ placeVaultProvisionRequests,
+ vaultRequestSourceMessageId,
+ vaultRequestSourcePlatform,
+ vaultRequestSourceRunId,
+ vaultRequestSourceTurnId,
+ } from '../../lib/vaultRequestPlacement';
import { localPath, type ShowPageLinkInfo } from '../../lib/showPageLinks';
+import {
+ showPageHeaderAccess,
+ showPageRestoreAccessDecision,
+ type ShowPageAccess,
+ type ShowPageAccessProbe,
+} from '../../lib/showPageAccess';
import { showPageEmbeddedPath } from '../../apps/showPageAvatar';
import { downloadFile, fileMeta } from '../../lib/filesApi';
import { isEditableFile, isEditableMeta, previewOverlayKind } from '../../lib/filePreview';
@@@ -199,27 -209,26 +215,46 @@@ export const ChatPage: React.FC = () =
const { capabilities } = useInstanceAuthorization();
const [sessionCanChat, setSessionCanChat] = useState(false);
const canChat = capabilities.can_chat && sessionCanChat;
- const canManageShowPage = capabilities.can_manage_instance && capabilities.can_use_system;
++ const canManageShowPageAsInstance = capabilities.can_manage_instance && capabilities.can_use_system;
+ const [showPageAccessResult, setShowPageAccessResult] = useState<{
+ sessionId: string;
+ probe: ShowPageAccessProbe;
+ } | null>(null);
+ const showPageAccessProbeGenerationRef = useRef(0);
+ const currentShowPageAccessProbe = capabilities.can_use_show_pages
+ && showPageAccessResult?.sessionId === sessionId
+ ? showPageAccessResult?.probe ?? null
+ : null;
+ const showPageAccess = currentShowPageAccessProbe?.status === 'granted'
+ ? currentShowPageAccessProbe.access
+ : null;
+ const showPageRestoreAccess = showPageRestoreAccessDecision(
- capabilities.can_manage_instance,
++ canManageShowPageAsInstance,
+ currentShowPageAccessProbe,
+ );
+ const { canOpen: canOpenShowPage, canManage: canManageShowPage } = showPageHeaderAccess(
- capabilities.can_manage_instance,
++ canManageShowPageAsInstance,
+ showPageAccess,
+ );
const { unreadBySession, markRead: markInboxRead } = useWorkbenchInbox();
+ const { focusedId: foregroundAppWindowId, focusCanvas } = useWindowManager();
+ const isDesktop = useIsDesktop();
+ const [pageActive, setPageActive] = useState(() => readPageActivity());
+ useEffect(() => {
+ const syncPageActivity = () => setPageActive(readPageActivity());
+ document.addEventListener('visibilitychange', syncPageActivity);
+ window.addEventListener('focus', syncPageActivity);
+ window.addEventListener('blur', syncPageActivity);
+ window.addEventListener('pageshow', syncPageActivity);
+ window.addEventListener('pagehide', syncPageActivity);
+ return () => {
+ document.removeEventListener('visibilitychange', syncPageActivity);
+ window.removeEventListener('focus', syncPageActivity);
+ window.removeEventListener('blur', syncPageActivity);
+ window.removeEventListener('pageshow', syncPageActivity);
+ window.removeEventListener('pagehide', syncPageActivity);
+ };
+ }, []);
// The mobile chat surface is a fixed full-screen flex column; this keeps the
// composer glued to the iOS keyboard (settle-then-correct; see the hook).
const chatSurfaceRef = useRef<HTMLDivElement>(null);
@@@ -293,8 -305,8 +331,9 @@@
// Derived rather than an effect on purpose: the fallback lands in the SAME
// render that flips ``readOnly``. An effect would first commit one frame with
// the chat surface still hidden and the iframe already gone — a blank chat.
- const showPageActive = isShowPageActive(readOnly, showPageMode);
+ const showPageAccessDenied = showPageRestoreAccess === 'deny';
+ const showPageActive = isShowPageActive(readOnly, showPageMode, showPageAccessDenied);
+ const showPageActiveRef = useLatestRef(showPageActive);
// True while the share popover is open. The popover floats over the Show Page
// iframe; making the iframe inert lets an outside tap there reach the parent
// document so the (non-modal) popover dismisses, without modal-blocking the
@@@ -1318,14 -1642,11 +1700,14 @@@
void reconcile();
void refreshQueue();
void syncTurnState({ quiet: true });
- void refreshSessionRowUntilNativeBound();
+ void refreshSessionRow();
},
- onAuthorizationChanged: () => {
+ onAuthorizationChanged: (data) => {
const currentSessionId = sessionIdRef.current;
if (!currentSessionId) return;
+ if (data.resource_kinds?.includes('show_page')) {
+ void probeShowPageAccess(currentSessionId);
+ }
setSessionCanChat(false);
void api.getSession(currentSessionId, { cache: false })
.then((nextSession) => {
@@@ -1345,7 -1666,7 +1727,7 @@@
},
});
return disconnect;
- }, [api, sessionId, appendMessage, reconcile, refresh, refreshQueue, syncTurnState, refreshSessionRowUntilNativeBound, markWorking, goBack, ingestActivityRow, scheduleActivityRefresh, dispatchLive, probeShowPageAccess]);
- }, [api, sessionId, appendMessage, reconcile, refresh, refreshQueue, syncTurnState, refreshSessionRow, markWorking, goBack, ingestActivityRow, scheduleActivityRefresh, dispatchLive]);
++ }, [api, sessionId, appendMessage, reconcile, refresh, refreshQueue, syncTurnState, refreshSessionRow, markWorking, goBack, ingestActivityRow, scheduleActivityRefresh, dispatchLive, probeShowPageAccess]);
// Mobile tabs (the common case for IM users) get backgrounded mid-turn; the
// SSE feed can be suspended without a clean reconnect, dropping the reply.
@@@ -1656,23 -1981,22 +2042,30 @@@
useEffect(() => {
const sid = sessionId;
if (!sid || session?.id !== sid || showPageRestoreAttemptRef.current === sid) return;
- showPageRestoreAttemptRef.current = sid;
if (readOnly) {
+ showPageRestoreAttemptRef.current = sid;
writeChatViewMode(sid, 'chat');
+ setShowPageViewResolved(true);
return;
}
if (showChatSignal || deepLinkMessageId || readChatViewMode(sid) !== 'show-page') {
+ showPageRestoreAttemptRef.current = sid;
++ setShowPageViewResolved(true);
+ return;
+ }
+ if (showPageRestoreAccess === 'wait') return;
+ showPageRestoreAttemptRef.current = sid;
+ if (showPageRestoreAccess === 'deny') {
+ writeChatViewMode(sid, 'chat');
+ setShowPageViewResolved(true);
return;
}
- void openShowPage(sid);
+ void openShowPage(sid).finally(() => {
+ if (sessionIdRef.current === sid && showPageRestoreAttemptRef.current === sid) {
+ setShowPageViewResolved(true);
+ }
+ });
- }, [deepLinkMessageId, openShowPage, readOnly, session?.id, sessionId, showChatSignal]);
+ }, [deepLinkMessageId, openShowPage, readOnly, session?.id, sessionId, showChatSignal, showPageRestoreAccess]);
// When the share control resolves the page (open) or flips its visibility, the
// serving route changes (private → /show/, public → /p/). Re-point the iframe
diff --cc vibe/authorization.py
index f0255d6d3,6bab27e82..db3534fca
--- a/vibe/authorization.py
+++ b/vibe/authorization.py
@@@ -377,9 -345,12 +377,12 @@@ _REMOTE_LOCAL_ONLY_HTTP_RULES = tuple
for method, pattern in (
("DELETE", r"^/api/sessions/[^/]+(?:/queue/[^/]+)?$"),
("POST", r"^/api/sessions/[^/]+/fork$"),
+ ("GET", r"^/api/sessions/[^/]+/draft$"),
+ ("PUT", r"^/api/sessions/[^/]+/draft$"),
+ ("POST", r"^/api/sessions/[^/]+/mark-read$"),
(
"POST",
- r"^/api/sessions/[^/]+/(?:messages|attachments|cancel|queue/[^/]+/send-now)$",
+ r"^/api/sessions/[^/]+/(?:attachments|cancel|queue/[^/]+/send-now)$",
),
("POST", r"^/api/asr/transcribe$"),
("POST", r"^/api/show/sessions/[^/]+/(?:events|prewarm)$"),
@@@ -390,6 -361,22 +393,20 @@@
("DELETE", r"^/api/settings/thread$"),
("GET", r"^/api/bind-codes$"),
("DELETE", r"^/api/projects/[^/]+$"),
+ ("GET", r"^/api/harness/(?:runs|bootstrap|runs/[^/]+)$"),
+ ("GET", r"^/api/vault/(?:pubkey|agent/pubkey|sandbox/root-metadata|vmk)$"),
+ ("GET", r"^/api/global-prompts$"),
+ # Model Hub source listing returns credential metadata
+ # (credential_ref, masked_credential, account_label, custom base_url,
+ # usage/billing) that must not cross the tunnel; the mutation surface
+ # is already fail-closed local-only, so the read stays local-only too.
+ ("GET", r"^/api/models/sources$"),
+ ("HEAD", r"^/api/models/sources$"),
- ("POST", r"^/api/show-pages/[^/]+/visibility$"),
- ("POST", r"^/api/show-pages/[^/]+/(?:rotate-share|share-id)$"),
+ ("GET", r"^/api/skills/(?:check|find)$"),
+ ("HEAD", r"^/api/skills/(?:check|find)$"),
+ ("POST", r"^/api/vault/requests/(?:access|sign)$"),
+ ("GET", r"^/api/users$"),
+ ("HEAD", r"^/api/users$"),
)
)
@@@ -421,12 -408,8 +438,12 @@@ _REMOTE_OWNER_ALLOWED_HTTP_RULES = tupl
),
(
frozenset({"POST"}),
- r"^/api/show-pages/[^/]+/(?:ensure|rotate-share|share-id|visibility)$",
+ r"^/api/show-pages/[^/]+/ensure$",
),
+ (
+ frozenset({"GET", "HEAD", "PUT"}),
+ r"^/api/show-pages/[^/]+/authorized-emails$",
+ ),
(frozenset({"GET", "HEAD"}), r"^/api/dock$"),
(frozenset({"POST"}), r"^/api/dock/pins$"),
(frozenset({"DELETE"}), r"^/api/dock/pins/[^/]+$"),
diff --cc vibe/ui_server.py
index 8aca05173,f44212c51..e4628822c
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@@ -1672,34 -1699,15 +1721,39 @@@ def _oauth_callback_arg(name: str) -> s
return request.args.get(name) or request.args.get(f"amp;{name}")
-def _redirect_to_vibe_cloud_login(config: V2Config, *, next_target: Any | None = None):
+def _show_page_id_from_private_route(path: str) -> str | None:
+ match = re.match(r"^/show/([^/]+)(?:/|$)", path or "")
+ if match is None:
+ return None
+ try:
+ from core.show_pages import validate_session_id
+
+ return validate_session_id(unquote(match.group(1)))
+ except Exception:
+ return None
+
+
+def _redirect_to_vibe_cloud_login(
+ config: V2Config,
+ *,
++ next_target: Any | None = None,
+ show_page_reauth: bool = False,
+):
from vibe import remote_access
cloud = config.remote_access.vibe_cloud
code_verifier = secrets.token_urlsafe(48)
digest = hashlib.sha256(code_verifier.encode("ascii")).digest()
code_challenge = base64.urlsafe_b64encode(digest).rstrip(b"=").decode("ascii")
- raw_next = request.full_path if request.query_string else request.path
- raw_next = next_target if next_target is not None else (request.full_path if request.query_string else request.path)
- next_target = _strip_oauth_retry_param(raw_next)
++ raw_next = (
++ next_target
++ if next_target is not None
++ else (request.full_path if request.query_string else request.path)
++ )
+ next_target = _strip_show_page_reauth_param(_strip_oauth_retry_param(raw_next))
+ if show_page_reauth:
+ next_target = _add_show_page_reauth_param(next_target)
- show_page_id = _show_page_id_from_private_route(request.path)
++ show_page_id = _show_page_id_from_private_route(urlsplit(next_target).path)
rid = secrets.token_urlsafe(18)
state = _make_oauth_state(
cloud.session_secret,